Skip to content

Commit aca3ee0

Browse files
Merge remote-tracking branch 'origin/main' into swiftlang#65-support-for-armhf
2 parents 9368d99 + f63f812 commit aca3ee0

File tree

7 files changed

+247
-44
lines changed

7 files changed

+247
-44
lines changed

Sources/GeneratorCLI/GeneratorCLI.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,14 @@ extension GeneratorCLI {
109109
var hostSwiftPackagePath: String? = nil
110110

111111
@Flag(
112-
help: "Don't include host toolchain in generated SDK, making it similar to the Static SDKs for Linux."
112+
inversion: .prefixedNo,
113+
help: """
114+
Whether or not to include the host toolchain in the Swift SDK.
115+
If the host toolchain is not included, this makes the Swift SDK compatible with any host, \
116+
but requires exactly the same version of the swift.org toolchain to be installed for it to work.
117+
"""
113118
)
114-
var noHostToolchain: Bool = false
119+
var hostToolchain: Bool = true
115120

116121
@Option(
117122
help: """
@@ -232,7 +237,7 @@ extension GeneratorCLI {
232237
fromContainerImage: self.fromContainerImage,
233238
hostSwiftPackagePath: self.generatorOptions.hostSwiftPackagePath,
234239
targetSwiftPackagePath: self.generatorOptions.targetSwiftPackagePath,
235-
noHostToolchain: self.generatorOptions.noHostToolchain
240+
includeHostToolchain: self.generatorOptions.hostToolchain
236241
)
237242
try await GeneratorCLI.run(recipe: recipe, targetTriple: targetTriple, options: self.generatorOptions)
238243
}

Sources/Helpers/Vendor/Triple.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
///
3333
/// This is a port of https://github.com/apple/swift-llvm/blob/stable/include/llvm/ADT/Triple.h
3434
@dynamicMemberLookup
35-
public struct Triple: Sendable {
35+
public struct Triple: Sendable, Equatable {
3636
/// `Triple` proxies predicates from `Triple.OS`, returning `false` for an unknown OS.
3737
public subscript(dynamicMember predicate: KeyPath<OS, Bool>) -> Bool {
3838
os?[keyPath: predicate] ?? false

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Download.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ extension SwiftSDKGenerator {
109109
}
110110

111111
print("Downloading \(urls.count) Ubuntu packages...")
112-
let pathsConfiguration = self.pathsConfiguration
113-
114112
try await inTemporaryDirectory { fs, tmpDir in
115113
let downloadedFiles = try await self.downloadFiles(from: urls, to: tmpDir, client, engine)
116114
report(downloadedFiles: downloadedFiles)
@@ -119,10 +117,6 @@ extension SwiftSDKGenerator {
119117
try await fs.unpack(file: tmpDir.appending(fileName), into: sdkDirPath)
120118
}
121119
}
122-
123-
if self.includeHostToolchain {
124-
try createDirectoryIfNeeded(at: pathsConfiguration.toolchainBinDirPath)
125-
}
126120
}
127121

128122
func downloadFiles(

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Unpack.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ extension SwiftSDKGenerator {
4646
logGenerationStep("Unpacking and copying Swift binaries for the host triple...")
4747
let pathsConfiguration = self.pathsConfiguration
4848

49+
try self.createDirectoryIfNeeded(at: pathsConfiguration.toolchainDirPath)
50+
4951
let excludes =
5052
unusedDarwinPlatforms.map { "--exclude usr/lib/swift/\($0)" } +
5153
unusedDarwinPlatforms.map { "--exclude usr/lib/swift_static/\($0)" } +

Sources/SwiftSDKGenerator/Serialization/Toolset.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct Toolset: Encodable {
2626

2727
/// Root path of the toolset, if present. When filling in ``Toolset.ToolProperties/path``, if a raw path string in
2828
/// ``DecodedToolset`` is inferred to be relative, it's resolved as absolute path relatively to `rootPath`.
29-
let rootPath: String?
29+
var rootPath: String?
3030

3131
// MARK: Tools currently known and used by SwiftPM.
3232

Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
2424
public enum HostSwiftSource: Sendable, Equatable {
2525
case localPackage(FilePath)
2626
case remoteTarball
27-
case skip
27+
case preinstalled
2828
}
2929

3030
let mainTargetTriple: Triple
@@ -52,7 +52,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
5252
fromContainerImage: String?,
5353
hostSwiftPackagePath: String?,
5454
targetSwiftPackagePath: String?,
55-
noHostToolchain: Bool = false
55+
includeHostToolchain: Bool = false
5656
) throws {
5757
let versionsConfiguration = try VersionsConfiguration(
5858
swiftVersion: swiftVersion,
@@ -74,8 +74,8 @@ public struct LinuxRecipe: SwiftSDKRecipe {
7474
}
7575
}
7676
let hostSwiftSource: HostSwiftSource
77-
if noHostToolchain {
78-
hostSwiftSource = .skip
77+
if includeHostToolchain == false {
78+
hostSwiftSource = .preinstalled
7979
} else if let hostSwiftPackagePath {
8080
hostSwiftSource = .localPackage(FilePath(hostSwiftPackagePath))
8181
} else {
@@ -109,6 +109,10 @@ public struct LinuxRecipe: SwiftSDKRecipe {
109109
}
110110

111111
public func applyPlatformOptions(toolset: inout Toolset, targetTriple: Triple) {
112+
if self.hostSwiftSource == .preinstalled {
113+
toolset.rootPath = nil
114+
}
115+
112116
var swiftCompilerOptions = ["-Xlinker", "-R/usr/lib/swift/linux/"]
113117

114118
// Swift 5.9 does not handle the `-use-ld` option properly:
@@ -118,7 +122,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
118122
} else {
119123
swiftCompilerOptions.append("-use-ld=lld")
120124

121-
if self.hostSwiftSource != .skip {
125+
if self.hostSwiftSource != .preinstalled {
122126
toolset.linker = Toolset.ToolProperties(path: "ld.lld")
123127
}
124128
}
@@ -158,6 +162,48 @@ public struct LinuxRecipe: SwiftSDKRecipe {
158162
.appending("\(self.linuxDistribution.name.rawValue)-\(self.linuxDistribution.release).sdk")
159163
}
160164

165+
func itemsToDownload(from artifacts: DownloadableArtifacts) -> [DownloadableArtifacts.Item] {
166+
var items: [DownloadableArtifacts.Item] = []
167+
if self.hostSwiftSource != .preinstalled && !self.versionsConfiguration.swiftVersion.hasPrefix("6.0") {
168+
items.append(artifacts.hostLLVM)
169+
}
170+
171+
switch self.targetSwiftSource {
172+
case .remoteTarball:
173+
items.append(artifacts.targetSwift)
174+
case .docker, .localPackage: break
175+
}
176+
177+
switch self.hostSwiftSource {
178+
case .remoteTarball:
179+
items.append(artifacts.hostSwift)
180+
case .localPackage: break
181+
case .preinstalled: break
182+
}
183+
return items
184+
}
185+
186+
var hostTriples: [Triple]? {
187+
if self.hostSwiftSource == .preinstalled {
188+
// Swift 5.9 and 5.10 require `supportedTriples` to be set in info.json.
189+
// FIXME: This can be removed once the SDK generator does not support 5.9/5.10 any more.
190+
if self.versionsConfiguration.swiftVersion.hasPrefix("5.9")
191+
|| self.versionsConfiguration.swiftVersion.hasPrefix("5.10") {
192+
return [
193+
Triple("x86_64-unknown-linux-gnu"),
194+
Triple("aarch64-unknown-linux-gnu"),
195+
Triple("x86_64-apple-macos"),
196+
Triple("arm64-apple-macos"),
197+
]
198+
}
199+
200+
// Swift 6.0 and later can set `supportedTriples` to nil
201+
return nil
202+
}
203+
204+
return [self.mainHostTriple]
205+
}
206+
161207
public func makeSwiftSDK(
162208
generator: SwiftSDKGenerator,
163209
engine: QueryEngine,
@@ -180,27 +226,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
180226
client,
181227
engine,
182228
downloadableArtifacts: &downloadableArtifacts,
183-
itemsToDownload: { artifacts in
184-
var items: [DownloadableArtifacts.Item] = []
185-
186-
if self.hostSwiftSource != .skip && !self.versionsConfiguration.swiftVersion.hasPrefix("6.0") {
187-
items.append(artifacts.hostLLVM)
188-
}
189-
190-
switch self.targetSwiftSource {
191-
case .remoteTarball:
192-
items.append(artifacts.targetSwift)
193-
case .docker, .localPackage: break
194-
}
195-
196-
switch self.hostSwiftSource {
197-
case .remoteTarball:
198-
items.append(artifacts.hostSwift)
199-
case .localPackage: break
200-
case .skip: break
201-
}
202-
return items
203-
}
229+
itemsToDownload: { artifacts in itemsToDownload(from: artifacts) }
204230
)
205231

206232
if !self.shouldUseDocker {
@@ -227,7 +253,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
227253
try await generator.unpackHostSwift(
228254
hostSwiftPackagePath: downloadableArtifacts.hostSwift.localPath
229255
)
230-
case .skip:
256+
case .preinstalled:
231257
break
232258
}
233259

@@ -252,8 +278,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
252278

253279
try await generator.fixAbsoluteSymlinks(sdkDirPath: sdkDirPath)
254280

255-
var hostTriples: [Triple]? = [self.mainHostTriple]
256-
if self.hostSwiftSource != .skip {
281+
if self.hostSwiftSource != .preinstalled {
257282
if !self.versionsConfiguration.swiftVersion.hasPrefix("6.0") {
258283
try await generator.prepareLLDLinker(engine, llvmArtifact: downloadableArtifacts.hostLLVM)
259284
}
@@ -269,11 +294,8 @@ public struct LinuxRecipe: SwiftSDKRecipe {
269294
logGenerationStep("Fixing `swift-autolink-extract` symlink...")
270295
try await generator.createSymlink(at: autolinkExtractPath, pointingTo: "swift")
271296
}
272-
} else if self.versionsConfiguration.swiftVersion.hasPrefix("6.0") {
273-
// We can exclude the host triples starting in Swift 6.0
274-
hostTriples = nil
275297
}
276298

277-
return SwiftSDKProduct(sdkDirPath: sdkDirPath, hostTriples: hostTriples)
299+
return SwiftSDKProduct(sdkDirPath: sdkDirPath, hostTriples: self.hostTriples)
278300
}
279301
}

0 commit comments

Comments
 (0)