Skip to content

Commit f6da543

Browse files
authored
generator/linux: Use --ldpath linker flag for 5.9 (#151)
Swift Package Manager's linker flag handling changed between 5.9 and 5.10. The flags which work for 5.9 cause linking failures 5.10 and later, and vice versa: swiftlang/swift-package-manager#7222 This commit generates workaround flags for 5.9 and new-style flags for all other versions. The EndToEnd tests currently cannot run in CI, so this change was tested locally. (Issue #145) * The basic 'hello world' example generated by `swift package init` built successfully with 5.9.2, 5.10.1 and 6.0.2 SDKs on x86_64 and aarch64. * A more complex example using Vapor built succesfully with 5.9.2, 5.10.1. 6.0.2 failed because of the CShims problem reported in Issue #138.
1 parent 3e7755c commit f6da543

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,20 @@ public struct LinuxRecipe: SwiftSDKRecipe {
105105
}
106106

107107
public func applyPlatformOptions(toolset: inout Toolset, targetTriple: Triple) {
108-
toolset.swiftCompiler = Toolset.ToolProperties(extraCLIOptions: [
109-
"-use-ld=lld",
110-
"-Xlinker",
111-
"-R/usr/lib/swift/linux/",
112-
])
108+
var swiftCompilerOptions = ["-Xlinker", "-R/usr/lib/swift/linux/"]
109+
110+
// Swift 5.9 does not handle the `-use-ld` option properly:
111+
// https://github.com/swiftlang/swift-package-manager/issues/7222
112+
if self.versionsConfiguration.swiftVersion.hasPrefix("5.9") {
113+
swiftCompilerOptions += ["-Xclang-linker", "--ld-path=ld.lld"]
114+
} else {
115+
swiftCompilerOptions.append("-use-ld=lld")
116+
toolset.linker = Toolset.ToolProperties(path: "ld.lld")
117+
}
118+
119+
toolset.swiftCompiler = Toolset.ToolProperties(extraCLIOptions: swiftCompilerOptions)
120+
113121
toolset.cxxCompiler = Toolset.ToolProperties(extraCLIOptions: ["-lstdc++"])
114-
toolset.linker = Toolset.ToolProperties(path: "ld.lld")
115122
toolset.librarian = Toolset.ToolProperties(path: "llvm-ar")
116123
}
117124

0 commit comments

Comments
 (0)