From 051e8037dd25adcb8a64cd2d973c18afc827a2c7 Mon Sep 17 00:00:00 2001 From: Egor Zhdan Date: Fri, 7 Nov 2025 12:01:34 -0800 Subject: [PATCH] [cxx-interop] Add driver support for `-emit-clang-header-min-access` This is a counterpart to https://github.com/swiftlang/swift/pull/84816. rdar://159211965 --- Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift | 4 ++++ Sources/SwiftOptions/Options.swift | 2 +- Tests/SwiftDriverTests/SwiftDriverTests.swift | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift index acb44c74d..1bac2b5da 100644 --- a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift +++ b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift @@ -385,6 +385,10 @@ extension Driver { try commandLine.appendLast(.clangBuildSessionFile, from: &parsedOptions) } + if isFrontendArgSupported(.emitClangHeaderMinAccess) { + try commandLine.appendLast(.emitClangHeaderMinAccess, from: &parsedOptions) + } + if isFrontendArgSupported(.enableBuiltinModule) { try commandLine.appendLast(.enableBuiltinModule, from: &parsedOptions) } diff --git a/Sources/SwiftOptions/Options.swift b/Sources/SwiftOptions/Options.swift index 317d3ed00..659d4c74b 100644 --- a/Sources/SwiftOptions/Options.swift +++ b/Sources/SwiftOptions/Options.swift @@ -349,7 +349,7 @@ extension Option { public static let emitAssembly: Option = Option("-emit-assembly", .flag, attributes: [.frontend, .noInteractive, .doesNotAffectIncrementalBuild], helpText: "Emit assembly file(s) (-S)", group: .modes) public static let emitAst: Option = Option("-emit-ast", .flag, alias: Option.dumpAst, attributes: [.frontend, .noInteractive, .doesNotAffectIncrementalBuild]) public static let emitBc: Option = Option("-emit-bc", .flag, attributes: [.frontend, .noInteractive, .doesNotAffectIncrementalBuild], helpText: "Emit LLVM BC file(s)", group: .modes) - public static let emitClangHeaderMinAccess: Option = Option("-emit-clang-header-min-access", .separate, attributes: [.frontend, .noInteractive, .argumentIsPath, .cacheInvariant], metaVar: "", helpText: "The minimum access level of declarations to include in the emitted header.>") + public static let emitClangHeaderMinAccess: Option = Option("-emit-clang-header-min-access", .separate, attributes: [.frontend, .noInteractive, .cacheInvariant], metaVar: "", helpText: "The minimum access level of declarations to include in the emitted header") public static let emitClangHeaderNonmodularIncludes: Option = Option("-emit-clang-header-nonmodular-includes", .flag, attributes: [.frontend, .noInteractive, .supplementaryOutput], helpText: "Augment emitted Objective-C header with textual imports for every included modular import") public static let emitClangHeaderPath: Option = Option("-emit-clang-header-path", .separate, alias: Option.emitObjcHeaderPath, attributes: [.frontend, .noInteractive, .argumentIsPath, .supplementaryOutput, .cacheInvariant], helpText: "Emit an Objective-C and C++ header file to ") public static let emitConstValuesPath: Option = Option("-emit-const-values-path", .separate, attributes: [.frontend, .noInteractive, .argumentIsPath, .supplementaryOutput, .cacheInvariant], metaVar: "", helpText: "Emit the extracted compile-time known values to ") diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index 57559f00d..756905fb7 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -7983,6 +7983,16 @@ final class SwiftDriverTests: XCTestCase { try XCTAssertJobInvocationMatches(jobs[0], .flag("-emit-objc-header-path"), toPathOption("path/to/header")) } + func testEmitClangHeaderMinAccess() throws { + VirtualPath.resetTemporaryFileStore() + var driver = try Driver(args: [ + "swiftc", "-emit-clang-header-path", "path/to/header", "-emit-clang-header-min-access", "public", "-typecheck", "test.swift" + ]) + let jobs = try driver.planBuild().removingAutolinkExtractJobs() + XCTAssertEqual(jobs.count, 2) + try XCTAssertJobInvocationMatches(jobs[0], .flag("-emit-clang-header-min-access"), .flag("public")) + } + func testGccToolchainFlags() throws { VirtualPath.resetTemporaryFileStore() var driver = try Driver(args: [