Skip to content

Generate the compatibility header for libraries on all platforms #8695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ public final class SwiftModuleBuildDescription {

/// Returns true if ObjC compatibility header should be emitted.
private var shouldEmitObjCCompatibilityHeader: Bool {
self.buildParameters.triple.isDarwin() && self.target.type == .library
self.target.type == .library
}

func writeOutputFileMap(to path: AbsolutePath) throws {
Expand Down
87 changes: 12 additions & 75 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5475,40 +5475,26 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
let buildPath = result.plan.productsBuildPath

let fooTarget = try result.moduleBuildDescription(for: "Foo").swift().compileArguments()
#if os(macOS)
XCTAssertMatch(
fooTarget,
[
.anySequence,
"-emit-objc-header",
"-emit-objc-header-path", "/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/Foo-Swift.h",
.anySequence,
]
)
#else
XCTAssertNoMatch(
fooTarget,
[
.anySequence,
"-emit-objc-header",
"-emit-objc-header-path", "/path/to/build/\(result.plan.destinationBuildParameters.triple)/Foo.build/Foo-Swift.h",
"-emit-objc-header-path",
"\(buildPath.appending(components: "Foo.build", "Foo-Swift.h"))",
.anySequence,
]
)
#endif

let barTarget = try result.moduleBuildDescription(for: "Bar").clang().basicArguments(isCXX: false)
#if os(macOS)
XCTAssertMatch(
barTarget,
[.anySequence, "-fmodule-map-file=/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/module.modulemap", .anySequence]
)
#else
XCTAssertNoMatch(
barTarget,
[.anySequence, "-fmodule-map-file=/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/module.modulemap", .anySequence]
[
.anySequence,
"-fmodule-map-file=\(buildPath.appending(components: "Foo.build", "module.modulemap"))",
.anySequence,
]
)
#endif

let yaml = try fs.tempDirectory.appending(components: UUID().uuidString, "debug.yaml")
try fs.createDirectory(yaml.parentDirectory, recursive: true)
Expand Down Expand Up @@ -5574,50 +5560,26 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
let buildPath = result.plan.productsBuildPath

let fooTarget = try result.moduleBuildDescription(for: "Foo").swift().compileArguments()
#if os(macOS)
XCTAssertMatch(
fooTarget,
[
.anySequence,
"-emit-objc-header",
"-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/Foo-Swift.h",
.anySequence,
]
)
#else
XCTAssertNoMatch(
fooTarget,
[
.anySequence,
"-emit-objc-header",
"-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/Foo-Swift.h",
"\(buildPath.appending(components: "Foo.build", "Foo-Swift.h"))",
.anySequence,
]
)
#endif

let barTarget = try result.moduleBuildDescription(for: "Bar").clang().basicArguments(isCXX: false)
#if os(macOS)
XCTAssertMatch(
barTarget,
[
.anySequence,
"-fmodule-map-file=/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/module.modulemap",
"-fmodule-map-file=\(buildPath.appending(components: "Foo.build", "module.modulemap"))",
.anySequence,
]
)
#else
XCTAssertNoMatch(
barTarget,
[
.anySequence,
"-fmodule-map-file=/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/module.modulemap",
.anySequence,
]
)
#endif

let yaml = try fs.tempDirectory.appending(components: UUID().uuidString, "debug.yaml")
try fs.createDirectory(yaml.parentDirectory, recursive: true)
Expand Down Expand Up @@ -5685,54 +5647,29 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
let dynamicLibraryPrefix = "lib"
#endif
let result = try BuildPlanResult(plan: plan)
let buildPath = result.plan.productsBuildPath

let fooTarget = try result.moduleBuildDescription(for: "Foo").swift().compileArguments()
#if os(macOS)
XCTAssertMatch(
fooTarget,
[
.anySequence,
"-emit-objc-header",
"-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/Foo-Swift.h",
"\(buildPath.appending(components: "Foo.build", "Foo-Swift.h"))",
.anySequence,
]
)
#else
XCTAssertNoMatch(
fooTarget,
[
.anySequence,
"-emit-objc-header",
"-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/Foo-Swift.h",
.anySequence,
]
)
#endif

let barTarget = try result.moduleBuildDescription(for: "Bar").clang().basicArguments(isCXX: false)
#if os(macOS)
XCTAssertMatch(
barTarget,
[
.anySequence,
"-fmodule-map-file=/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/module.modulemap",
"-fmodule-map-file=\(buildPath.appending(components: "Foo.build", "module.modulemap"))",
.anySequence,
]
)
#else
XCTAssertNoMatch(
barTarget,
[
.anySequence,
"-fmodule-map-file=/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/module.modulemap",
.anySequence,
]
)
#endif

let buildPath = result.plan.productsBuildPath

let yaml = try fs.tempDirectory.appending(components: UUID().uuidString, "debug.yaml")
try fs.createDirectory(yaml.parentDirectory, recursive: true)
Expand Down
49 changes: 13 additions & 36 deletions Tests/BuildTests/ModuleAliasingBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -732,39 +732,26 @@ final class ModuleAliasingBuildTests: XCTestCase {
let fooLoggingArgs = try result.moduleBuildDescription(for: "FooLogging").swift().compileArguments()
let barLoggingArgs = try result.moduleBuildDescription(for: "BarLogging").swift().compileArguments()
let loggingArgs = try result.moduleBuildDescription(for: "Logging").swift().compileArguments()
#if os(macOS)
let buildPath = result.plan.productsBuildPath

XCTAssertMatch(
fooLoggingArgs,
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/FooLogging.build/FooLogging-Swift.h", .anySequence]
"\(buildPath.appending(components: "FooLogging.build", "FooLogging-Swift.h"))",
.anySequence]
)
XCTAssertMatch(
barLoggingArgs,
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/BarLogging.build/BarLogging-Swift.h", .anySequence]
"\(buildPath.appending(components: "BarLogging.build", "BarLogging-Swift.h"))",
.anySequence]
)
XCTAssertMatch(
loggingArgs,
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Logging.build/Logging-Swift.h", .anySequence]
)
#else
XCTAssertNoMatch(
fooLoggingArgs,
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/FooLogging.build/FooLogging-Swift.h", .anySequence]
)
XCTAssertNoMatch(
barLoggingArgs,
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/BarLogging.build/BarLogging-Swift.h", .anySequence]
)
XCTAssertNoMatch(
loggingArgs,
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Logging.build/Logging-Swift.h", .anySequence]
"\(buildPath.appending(components: "Logging.build", "Logging-Swift.h"))",
.anySequence]
)
#endif
}

func testModuleAliasingDuplicateTargetNameInUpstream() async throws {
Expand Down Expand Up @@ -851,30 +838,20 @@ final class ModuleAliasingBuildTests: XCTestCase {

let otherLoggingArgs = try result.moduleBuildDescription(for: "OtherLogging").swift().compileArguments()
let loggingArgs = try result.moduleBuildDescription(for: "Logging").swift().compileArguments()
let buildPath = result.plan.productsBuildPath

#if os(macOS)
XCTAssertMatch(
otherLoggingArgs,
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/OtherLogging.build/OtherLogging-Swift.h", .anySequence]
"\(buildPath.appending(components: "OtherLogging.build", "OtherLogging-Swift.h"))",
.anySequence]
)
XCTAssertMatch(
loggingArgs,
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Logging.build/Logging-Swift.h", .anySequence]
)
#else
XCTAssertNoMatch(
otherLoggingArgs,
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/OtherLogging.build/OtherLogging-Swift.h", .anySequence]
)
XCTAssertNoMatch(
loggingArgs,
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Logging.build/Logging-Swift.h", .anySequence]
"\(buildPath.appending(components: "Logging.build", "Logging-Swift.h"))",
.anySequence]
)
#endif
}

func testModuleAliasingMultipleAliasesInProduct() async throws {
Expand Down