Skip to content

Commit f625710

Browse files
authored
Generate the compatibility header for libraries on all platforms (#8695)
Enable generating the compatibility header for library targets on all platforms by lifting the restriction to Darwin. As part of the work to formalize `@cdecl` we've been adding content to the compatibility header that is usable by C compilers without the need for Objective-C or modules. Lifting this restriction will allow Linux and Windows users to generate and import the compatibility header to call `@cdecl` functions in their package.
1 parent 4e45170 commit f625710

File tree

3 files changed

+26
-112
lines changed

3 files changed

+26
-112
lines changed

Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ public final class SwiftModuleBuildDescription {
801801

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

807807
func writeOutputFileMap(to path: AbsolutePath) throws {

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 12 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5603,40 +5603,26 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
56035603
let buildPath = result.plan.productsBuildPath
56045604

56055605
let fooTarget = try result.moduleBuildDescription(for: "Foo").swift().compileArguments()
5606-
#if os(macOS)
56075606
XCTAssertMatch(
56085607
fooTarget,
56095608
[
56105609
.anySequence,
56115610
"-emit-objc-header",
5612-
"-emit-objc-header-path", "/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/Foo-Swift.h",
5613-
.anySequence,
5614-
]
5615-
)
5616-
#else
5617-
XCTAssertNoMatch(
5618-
fooTarget,
5619-
[
5620-
.anySequence,
5621-
"-emit-objc-header",
5622-
"-emit-objc-header-path", "/path/to/build/\(result.plan.destinationBuildParameters.triple)/Foo.build/Foo-Swift.h",
5611+
"-emit-objc-header-path",
5612+
"\(buildPath.appending(components: "Foo.build", "Foo-Swift.h"))",
56235613
.anySequence,
56245614
]
56255615
)
5626-
#endif
56275616

56285617
let barTarget = try result.moduleBuildDescription(for: "Bar").clang().basicArguments(isCXX: false)
5629-
#if os(macOS)
56305618
XCTAssertMatch(
56315619
barTarget,
5632-
[.anySequence, "-fmodule-map-file=/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/module.modulemap", .anySequence]
5633-
)
5634-
#else
5635-
XCTAssertNoMatch(
5636-
barTarget,
5637-
[.anySequence, "-fmodule-map-file=/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/module.modulemap", .anySequence]
5620+
[
5621+
.anySequence,
5622+
"-fmodule-map-file=\(buildPath.appending(components: "Foo.build", "module.modulemap"))",
5623+
.anySequence,
5624+
]
56385625
)
5639-
#endif
56405626

56415627
let yaml = try fs.tempDirectory.appending(components: UUID().uuidString, "debug.yaml")
56425628
try fs.createDirectory(yaml.parentDirectory, recursive: true)
@@ -5702,50 +5688,26 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
57025688
let buildPath = result.plan.productsBuildPath
57035689

57045690
let fooTarget = try result.moduleBuildDescription(for: "Foo").swift().compileArguments()
5705-
#if os(macOS)
57065691
XCTAssertMatch(
57075692
fooTarget,
57085693
[
57095694
.anySequence,
57105695
"-emit-objc-header",
57115696
"-emit-objc-header-path",
5712-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/Foo-Swift.h",
5713-
.anySequence,
5714-
]
5715-
)
5716-
#else
5717-
XCTAssertNoMatch(
5718-
fooTarget,
5719-
[
5720-
.anySequence,
5721-
"-emit-objc-header",
5722-
"-emit-objc-header-path",
5723-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/Foo-Swift.h",
5697+
"\(buildPath.appending(components: "Foo.build", "Foo-Swift.h"))",
57245698
.anySequence,
57255699
]
57265700
)
5727-
#endif
57285701

57295702
let barTarget = try result.moduleBuildDescription(for: "Bar").clang().basicArguments(isCXX: false)
5730-
#if os(macOS)
57315703
XCTAssertMatch(
57325704
barTarget,
57335705
[
57345706
.anySequence,
5735-
"-fmodule-map-file=/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/module.modulemap",
5707+
"-fmodule-map-file=\(buildPath.appending(components: "Foo.build", "module.modulemap"))",
57365708
.anySequence,
57375709
]
57385710
)
5739-
#else
5740-
XCTAssertNoMatch(
5741-
barTarget,
5742-
[
5743-
.anySequence,
5744-
"-fmodule-map-file=/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/module.modulemap",
5745-
.anySequence,
5746-
]
5747-
)
5748-
#endif
57495711

57505712
let yaml = try fs.tempDirectory.appending(components: UUID().uuidString, "debug.yaml")
57515713
try fs.createDirectory(yaml.parentDirectory, recursive: true)
@@ -5813,54 +5775,29 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
58135775
let dynamicLibraryPrefix = "lib"
58145776
#endif
58155777
let result = try BuildPlanResult(plan: plan)
5778+
let buildPath = result.plan.productsBuildPath
58165779

58175780
let fooTarget = try result.moduleBuildDescription(for: "Foo").swift().compileArguments()
5818-
#if os(macOS)
58195781
XCTAssertMatch(
58205782
fooTarget,
58215783
[
58225784
.anySequence,
58235785
"-emit-objc-header",
58245786
"-emit-objc-header-path",
5825-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/Foo-Swift.h",
5787+
"\(buildPath.appending(components: "Foo.build", "Foo-Swift.h"))",
58265788
.anySequence,
58275789
]
58285790
)
5829-
#else
5830-
XCTAssertNoMatch(
5831-
fooTarget,
5832-
[
5833-
.anySequence,
5834-
"-emit-objc-header",
5835-
"-emit-objc-header-path",
5836-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/Foo-Swift.h",
5837-
.anySequence,
5838-
]
5839-
)
5840-
#endif
58415791

58425792
let barTarget = try result.moduleBuildDescription(for: "Bar").clang().basicArguments(isCXX: false)
5843-
#if os(macOS)
58445793
XCTAssertMatch(
58455794
barTarget,
58465795
[
58475796
.anySequence,
5848-
"-fmodule-map-file=/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/module.modulemap",
5797+
"-fmodule-map-file=\(buildPath.appending(components: "Foo.build", "module.modulemap"))",
58495798
.anySequence,
58505799
]
58515800
)
5852-
#else
5853-
XCTAssertNoMatch(
5854-
barTarget,
5855-
[
5856-
.anySequence,
5857-
"-fmodule-map-file=/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Foo.build/module.modulemap",
5858-
.anySequence,
5859-
]
5860-
)
5861-
#endif
5862-
5863-
let buildPath = result.plan.productsBuildPath
58645801

58655802
let yaml = try fs.tempDirectory.appending(components: UUID().uuidString, "debug.yaml")
58665803
try fs.createDirectory(yaml.parentDirectory, recursive: true)

Tests/BuildTests/ModuleAliasingBuildTests.swift

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -732,39 +732,26 @@ final class ModuleAliasingBuildTests: XCTestCase {
732732
let fooLoggingArgs = try result.moduleBuildDescription(for: "FooLogging").swift().compileArguments()
733733
let barLoggingArgs = try result.moduleBuildDescription(for: "BarLogging").swift().compileArguments()
734734
let loggingArgs = try result.moduleBuildDescription(for: "Logging").swift().compileArguments()
735-
#if os(macOS)
735+
let buildPath = result.plan.productsBuildPath
736+
736737
XCTAssertMatch(
737738
fooLoggingArgs,
738739
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
739-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/FooLogging.build/FooLogging-Swift.h", .anySequence]
740+
"\(buildPath.appending(components: "FooLogging.build", "FooLogging-Swift.h"))",
741+
.anySequence]
740742
)
741743
XCTAssertMatch(
742744
barLoggingArgs,
743745
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
744-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/BarLogging.build/BarLogging-Swift.h", .anySequence]
746+
"\(buildPath.appending(components: "BarLogging.build", "BarLogging-Swift.h"))",
747+
.anySequence]
745748
)
746749
XCTAssertMatch(
747750
loggingArgs,
748751
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
749-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Logging.build/Logging-Swift.h", .anySequence]
750-
)
751-
#else
752-
XCTAssertNoMatch(
753-
fooLoggingArgs,
754-
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
755-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/FooLogging.build/FooLogging-Swift.h", .anySequence]
756-
)
757-
XCTAssertNoMatch(
758-
barLoggingArgs,
759-
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
760-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/BarLogging.build/BarLogging-Swift.h", .anySequence]
761-
)
762-
XCTAssertNoMatch(
763-
loggingArgs,
764-
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
765-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Logging.build/Logging-Swift.h", .anySequence]
752+
"\(buildPath.appending(components: "Logging.build", "Logging-Swift.h"))",
753+
.anySequence]
766754
)
767-
#endif
768755
}
769756

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

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

855-
#if os(macOS)
856843
XCTAssertMatch(
857844
otherLoggingArgs,
858845
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
859-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/OtherLogging.build/OtherLogging-Swift.h", .anySequence]
846+
"\(buildPath.appending(components: "OtherLogging.build", "OtherLogging-Swift.h"))",
847+
.anySequence]
860848
)
861849
XCTAssertMatch(
862850
loggingArgs,
863851
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
864-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Logging.build/Logging-Swift.h", .anySequence]
865-
)
866-
#else
867-
XCTAssertNoMatch(
868-
otherLoggingArgs,
869-
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
870-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/OtherLogging.build/OtherLogging-Swift.h", .anySequence]
871-
)
872-
XCTAssertNoMatch(
873-
loggingArgs,
874-
[.anySequence, "-emit-objc-header", "-emit-objc-header-path",
875-
"/path/to/build/\(result.plan.destinationBuildParameters.triple)/debug/Logging.build/Logging-Swift.h", .anySequence]
852+
"\(buildPath.appending(components: "Logging.build", "Logging-Swift.h"))",
853+
.anySequence]
876854
)
877-
#endif
878855
}
879856

880857
func testModuleAliasingMultipleAliasesInProduct() async throws {

0 commit comments

Comments
 (0)