@@ -24,7 +24,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
24
24
public enum HostSwiftSource : Sendable , Equatable {
25
25
case localPackage( FilePath )
26
26
case remoteTarball
27
- case skip
27
+ case preinstalled
28
28
}
29
29
30
30
let mainTargetTriple : Triple
@@ -52,7 +52,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
52
52
fromContainerImage: String ? ,
53
53
hostSwiftPackagePath: String ? ,
54
54
targetSwiftPackagePath: String ? ,
55
- noHostToolchain : Bool = false
55
+ includeHostToolchain : Bool = false
56
56
) throws {
57
57
let versionsConfiguration = try VersionsConfiguration (
58
58
swiftVersion: swiftVersion,
@@ -74,8 +74,8 @@ public struct LinuxRecipe: SwiftSDKRecipe {
74
74
}
75
75
}
76
76
let hostSwiftSource : HostSwiftSource
77
- if noHostToolchain {
78
- hostSwiftSource = . skip
77
+ if includeHostToolchain == false {
78
+ hostSwiftSource = . preinstalled
79
79
} else if let hostSwiftPackagePath {
80
80
hostSwiftSource = . localPackage( FilePath ( hostSwiftPackagePath) )
81
81
} else {
@@ -109,6 +109,10 @@ public struct LinuxRecipe: SwiftSDKRecipe {
109
109
}
110
110
111
111
public func applyPlatformOptions( toolset: inout Toolset , targetTriple: Triple ) {
112
+ if self . hostSwiftSource == . preinstalled {
113
+ toolset. rootPath = nil
114
+ }
115
+
112
116
var swiftCompilerOptions = [ " -Xlinker " , " -R/usr/lib/swift/linux/ " ]
113
117
114
118
// Swift 5.9 does not handle the `-use-ld` option properly:
@@ -118,7 +122,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
118
122
} else {
119
123
swiftCompilerOptions. append ( " -use-ld=lld " )
120
124
121
- if self . hostSwiftSource != . skip {
125
+ if self . hostSwiftSource != . preinstalled {
122
126
toolset. linker = Toolset . ToolProperties ( path: " ld.lld " )
123
127
}
124
128
}
@@ -158,6 +162,48 @@ public struct LinuxRecipe: SwiftSDKRecipe {
158
162
. appending ( " \( self . linuxDistribution. name. rawValue) - \( self . linuxDistribution. release) .sdk " )
159
163
}
160
164
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
+
161
207
public func makeSwiftSDK(
162
208
generator: SwiftSDKGenerator ,
163
209
engine: QueryEngine ,
@@ -180,27 +226,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
180
226
client,
181
227
engine,
182
228
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) }
204
230
)
205
231
206
232
if !self . shouldUseDocker {
@@ -227,7 +253,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
227
253
try await generator. unpackHostSwift (
228
254
hostSwiftPackagePath: downloadableArtifacts. hostSwift. localPath
229
255
)
230
- case . skip :
256
+ case . preinstalled :
231
257
break
232
258
}
233
259
@@ -252,8 +278,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
252
278
253
279
try await generator. fixAbsoluteSymlinks ( sdkDirPath: sdkDirPath)
254
280
255
- var hostTriples : [ Triple ] ? = [ self . mainHostTriple]
256
- if self . hostSwiftSource != . skip {
281
+ if self . hostSwiftSource != . preinstalled {
257
282
if !self . versionsConfiguration. swiftVersion. hasPrefix ( " 6.0 " ) {
258
283
try await generator. prepareLLDLinker ( engine, llvmArtifact: downloadableArtifacts. hostLLVM)
259
284
}
@@ -269,11 +294,8 @@ public struct LinuxRecipe: SwiftSDKRecipe {
269
294
logGenerationStep ( " Fixing `swift-autolink-extract` symlink... " )
270
295
try await generator. createSymlink ( at: autolinkExtractPath, pointingTo: " swift " )
271
296
}
272
- } else if self . versionsConfiguration. swiftVersion. hasPrefix ( " 6.0 " ) {
273
- // We can exclude the host triples starting in Swift 6.0
274
- hostTriples = nil
275
297
}
276
298
277
- return SwiftSDKProduct ( sdkDirPath: sdkDirPath, hostTriples: hostTriples)
299
+ return SwiftSDKProduct ( sdkDirPath: sdkDirPath, hostTriples: self . hostTriples)
278
300
}
279
301
}
0 commit comments