Skip to content

Commit 02ef96f

Browse files
authored
generator/linux: Use the Swift 6.0 toolchain's lld (#159)
After Swift 6.0 the swift.org toolchain includes LLD, so it is not necessary to install it separately from an LLVM archive. The LLD provided by the swift.org toolchain is also a multiarch binary, so the SDK will run on both x86_64 and aarch64 macOS hosts. This change slightly reduces the size of a Swift 6.0 SDK because currently these SDKs include two copies of LLD - one from the SDK and one from LLVM. This is because LLD is typically installed as a single binary with multiple symlinks pointing to it representing different 'personalities' such as `ld.lld`, `wasm-ld` and so on. SDK generator copies the `lld` binary in as `ld.lld`, overwriting one of the symlinks: -rwxr-xr-x 1 euanh staff 108M 14 Nov 2023 ld.lld lrwxr-xr-x 1 euanh staff 3B 24 Oct 15:11 ld64.lld -> lld -rwxr-xr-x 1 euanh staff 265M 24 Oct 19:28 lld lrwxr-xr-x 1 euanh staff 3B 24 Oct 15:11 lld-link -> lld lrwxr-xr-x 1 euanh staff 3B 24 Oct 15:11 wasm-ld -> lld After this PR, we only have one copy of the `lld` binary: lrwxr-xr-x 1 euanh staff 3B 24 Oct 15:11 ld.lld -> lld lrwxr-xr-x 1 euanh staff 3B 24 Oct 15:11 ld64.lld -> lld -rwxr-xr-x 1 euanh staff 265M 24 Oct 19:28 lld lrwxr-xr-x 1 euanh staff 3B 24 Oct 15:11 lld-link -> lld lrwxr-xr-x 1 euanh staff 3B 24 Oct 15:11 wasm-ld -> lld This change does not significantly change the time to build a new SDK with a warm cache (PR #149), however the very first build with a cold cache improves considerably because the LLVM archive does not need to be downloaded and unpacked. For example, two tests run one after the other on an M3 MacBook Air with a fast network connection: rm -rf Artifacts Bundles swift run swift-sdk-generator make-linux-sdk --swift-version 6.0.2-RELEASE `main`: 1m21s, (2.9GB in `Artifacts` directory) this PR: 39s, (2.1GB in `Artifacts` directory)
1 parent 4339b89 commit 02ef96f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,18 @@ public struct LinuxRecipe: SwiftSDKRecipe {
174174
engine,
175175
downloadableArtifacts: &downloadableArtifacts,
176176
itemsToDownload: { artifacts in
177-
var items = [artifacts.hostLLVM]
177+
var items: [DownloadableArtifacts.Item] = []
178+
179+
if !self.versionsConfiguration.swiftVersion.hasPrefix("6.0") {
180+
items.append(artifacts.hostLLVM)
181+
}
182+
178183
switch self.targetSwiftSource {
179184
case .remoteTarball:
180185
items.append(artifacts.targetSwift)
181186
case .docker, .localPackage: break
182187
}
188+
183189
switch self.hostSwiftSource {
184190
case .remoteTarball:
185191
items.append(artifacts.hostSwift)
@@ -234,7 +240,9 @@ public struct LinuxRecipe: SwiftSDKRecipe {
234240
)
235241
}
236242

237-
try await generator.prepareLLDLinker(engine, llvmArtifact: downloadableArtifacts.hostLLVM)
243+
if !self.versionsConfiguration.swiftVersion.hasPrefix("6.0") {
244+
try await generator.prepareLLDLinker(engine, llvmArtifact: downloadableArtifacts.hostLLVM)
245+
}
238246

239247
try await generator.fixAbsoluteSymlinks(sdkDirPath: sdkDirPath)
240248

0 commit comments

Comments
 (0)