Skip to content

Commit 481c308

Browse files
committed
[Build] Products should use c99name for -module-name
<rdar://problem/44929423> Error when compiling products with dashes(`-`) in the name
1 parent 4a88f2c commit 481c308

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public final class ProductBuildDescription {
498498
}
499499
args += ["-L", buildParameters.buildPath.asString]
500500
args += ["-o", binary.asString]
501-
args += ["-module-name", product.name]
501+
args += ["-module-name", product.name.mangledToC99ExtendedIdentifier()]
502502
args += dylibs.map({ "-l" + $0.product.name })
503503

504504
// Add arguements needed for code coverage if it is enabled.

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ final class BuildPlanTests: XCTestCase {
615615
path: "/Bar",
616616
url: "/Bar",
617617
products: [
618-
ProductDescription(name: "Bar", type: .library(.dynamic), targets: ["Bar"]),
618+
ProductDescription(name: "Bar-Baz", type: .library(.dynamic), targets: ["Bar"]),
619619
],
620620
targets: [
621621
TargetDescription(name: "Bar", dependencies: []),
@@ -628,7 +628,7 @@ final class BuildPlanTests: XCTestCase {
628628
PackageDependencyDescription(url: "/Bar", requirement: .upToNextMajor(from: "1.0.0")),
629629
],
630630
targets: [
631-
TargetDescription(name: "Foo", dependencies: ["Bar"]),
631+
TargetDescription(name: "Foo", dependencies: ["Bar-Baz"]),
632632
]),
633633
]
634634
)
@@ -639,35 +639,35 @@ final class BuildPlanTests: XCTestCase {
639639
result.checkTargetsCount(2)
640640

641641
let fooLinkArgs = try result.buildProduct(for: "Foo").linkArguments()
642-
let barLinkArgs = try result.buildProduct(for: "Bar").linkArguments()
642+
let barLinkArgs = try result.buildProduct(for: "Bar-Baz").linkArguments()
643643

644644
#if os(macOS)
645645
XCTAssertEqual(fooLinkArgs, [
646646
"/fake/path/to/swiftc", "-g", "-L", "/path/to/build/debug",
647-
"-o", "/path/to/build/debug/Foo", "-module-name", "Foo", "-lBar", "-emit-executable",
647+
"-o", "/path/to/build/debug/Foo", "-module-name", "Foo", "-lBar-Baz", "-emit-executable",
648648
"@/path/to/build/debug/Foo.product/Objects.LinkFileList",
649649
])
650650

651651
XCTAssertEqual(barLinkArgs, [
652652
"/fake/path/to/swiftc", "-g", "-L", "/path/to/build/debug", "-o",
653-
"/path/to/build/debug/libBar.dylib",
654-
"-module-name", "Bar", "-emit-library",
655-
"@/path/to/build/debug/Bar.product/Objects.LinkFileList",
653+
"/path/to/build/debug/libBar-Baz.dylib",
654+
"-module-name", "Bar_Baz", "-emit-library",
655+
"@/path/to/build/debug/Bar-Baz.product/Objects.LinkFileList",
656656
])
657657
#else
658658
XCTAssertEqual(fooLinkArgs, [
659659
"/fake/path/to/swiftc", "-g", "-L", "/path/to/build/debug",
660-
"-o", "/path/to/build/debug/Foo", "-module-name", "Foo", "-lBar", "-emit-executable",
660+
"-o", "/path/to/build/debug/Foo", "-module-name", "Foo", "-lBar-Baz", "-emit-executable",
661661
"-Xlinker", "-rpath=$ORIGIN",
662662
"@/path/to/build/debug/Foo.product/Objects.LinkFileList",
663663
])
664664

665665
XCTAssertEqual(barLinkArgs, [
666666
"/fake/path/to/swiftc", "-g", "-L", "/path/to/build/debug", "-o",
667-
"/path/to/build/debug/libBar.so",
668-
"-module-name", "Bar", "-emit-library",
667+
"/path/to/build/debug/libBar-Baz.so",
668+
"-module-name", "Bar_Baz", "-emit-library",
669669
"-Xlinker", "-rpath=$ORIGIN",
670-
"@/path/to/build/debug/Bar.product/Objects.LinkFileList",
670+
"@/path/to/build/debug/Bar-Baz.product/Objects.LinkFileList",
671671
])
672672
#endif
673673

0 commit comments

Comments
 (0)