Skip to content

Commit 78a5a30

Browse files
committed
generator: The target toolchain is still needed to build a package-based SDK
PR swiftlang#177 was intended to skip unnecessary toolchain downloads, making it possible to build a container-based SDK offline if all its requirements had already been dowloaded. The change was too broad and also broke building package-based SDKs. PR swiftlang#177 skips calling generator.downloadArtifacts() when building an SDK without an embedded host toolchain (the default). In addition to downloading the host toolchain (and LLVM, if needed), generator.downloadArtifacts() is also responsible for downloading the target toolchain. This is not needed when building a container-based SDK but is required when building a package-based SDK, which combines an SDK from swift.org with supporting libraries extracted from Debian packages. In fact, generator.downloadArtifacts() already avoids downloading toolchains when building a container-based SDK without an embedded toolchain. The only network call which caused offline builds to fail was an unconditional check for a suitable LLVM binary from GitHub. This PR restores the call to generator.downloadArtifacts() and only makes the LLVM check if LLVM is in the list of required downloads. This allows the EndToEnd tests to pass again (with PR swiftlang#170 temporarily reverted because of issue swiftlang#181).
1 parent 80b0a28 commit 78a5a30

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Download.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ extension SwiftSDKGenerator {
3939
logger.info("Downloading required toolchain packages...")
4040
let hostLLVMURL = downloadableArtifacts.hostLLVM.remoteURL
4141
// Workaround an issue with github.com returning 400 instead of 404 status to HEAD requests from AHC.
42-
let isLLVMBinaryArtifactAvailable = try await type(of: client).with(http1Only: true) {
43-
try await $0.head(
44-
url: hostLLVMURL.absoluteString,
45-
headers: ["Accept": "*/*", "User-Agent": "Swift SDK Generator"]
46-
)
47-
}
4842

49-
if !isLLVMBinaryArtifactAvailable {
50-
downloadableArtifacts.useLLVMSources()
43+
if itemsToDownload(downloadableArtifacts).contains(where: { $0.remoteURL == downloadableArtifacts.hostLLVM.remoteURL } ) {
44+
let isLLVMBinaryArtifactAvailable = try await type(of: client).with(http1Only: true) {
45+
try await $0.head(
46+
url: hostLLVMURL.absoluteString,
47+
headers: ["Accept": "*/*", "User-Agent": "Swift SDK Generator"]
48+
)
49+
}
50+
51+
if !isLLVMBinaryArtifactAvailable {
52+
downloadableArtifacts.useLLVMSources()
53+
}
5154
}
5255

5356
let results = try await withThrowingTaskGroup(of: FileCacheRecord.self) { group in

Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,12 @@ public struct LinuxRecipe: SwiftSDKRecipe {
236236
generator.pathsConfiguration
237237
)
238238

239-
if hostSwiftSource != .preinstalled {
240-
try await generator.downloadArtifacts(
241-
client,
242-
engine,
243-
downloadableArtifacts: &downloadableArtifacts,
244-
itemsToDownload: { artifacts in itemsToDownload(from: artifacts) }
245-
)
246-
}
239+
try await generator.downloadArtifacts(
240+
client,
241+
engine,
242+
downloadableArtifacts: &downloadableArtifacts,
243+
itemsToDownload: { artifacts in itemsToDownload(from: artifacts) }
244+
)
247245

248246
if !self.shouldUseDocker {
249247
guard case let .ubuntu(version) = linuxDistribution else {

0 commit comments

Comments
 (0)