Skip to content

Commit

Permalink
generator/linux: Use --ldpath linker flag for 5.9 (#151)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
euanh authored Nov 18, 2024
1 parent 3e7755c commit f6da543
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,20 @@ public struct LinuxRecipe: SwiftSDKRecipe {
}

public func applyPlatformOptions(toolset: inout Toolset, targetTriple: Triple) {
toolset.swiftCompiler = Toolset.ToolProperties(extraCLIOptions: [
"-use-ld=lld",
"-Xlinker",
"-R/usr/lib/swift/linux/",
])
var swiftCompilerOptions = ["-Xlinker", "-R/usr/lib/swift/linux/"]

// Swift 5.9 does not handle the `-use-ld` option properly:
// https://github.com/swiftlang/swift-package-manager/issues/7222
if self.versionsConfiguration.swiftVersion.hasPrefix("5.9") {
swiftCompilerOptions += ["-Xclang-linker", "--ld-path=ld.lld"]
} else {
swiftCompilerOptions.append("-use-ld=lld")
toolset.linker = Toolset.ToolProperties(path: "ld.lld")
}

toolset.swiftCompiler = Toolset.ToolProperties(extraCLIOptions: swiftCompilerOptions)

toolset.cxxCompiler = Toolset.ToolProperties(extraCLIOptions: ["-lstdc++"])
toolset.linker = Toolset.ToolProperties(path: "ld.lld")
toolset.librarian = Toolset.ToolProperties(path: "llvm-ar")
}

Expand Down

0 comments on commit f6da543

Please sign in to comment.