@@ -23,11 +23,14 @@ struct GeneratorCLI: AsyncParsableCommand {
23
23
defaultSubcommand: MakeLinuxSDK . self
24
24
)
25
25
26
- static func run< Recipe: SwiftSDKRecipe > ( recipe: Recipe , options: GeneratorOptions ) async throws {
26
+ static func run< Recipe: SwiftSDKRecipe > (
27
+ recipe: Recipe ,
28
+ hostTriple: Triple ,
29
+ targetTriple: Triple ,
30
+ options: GeneratorOptions
31
+ ) async throws {
27
32
let elapsed = try await ContinuousClock ( ) . measure {
28
33
let logger = Logger ( label: " org.swift.swift-sdk-generator " )
29
-
30
- let ( hostTriple, targetTriple) = try await options. deriveTriples ( )
31
34
let generator = try await SwiftSDKGenerator (
32
35
bundleVersion: options. bundleVersion,
33
36
hostTriple: hostTriple,
@@ -56,7 +59,12 @@ struct GeneratorCLI: AsyncParsableCommand {
56
59
}
57
60
}
58
61
59
- extension Triple . CPU : ExpressibleByArgument { }
62
+ extension Triple . Arch : ExpressibleByArgument { }
63
+ extension Triple : ExpressibleByArgument {
64
+ public init ? ( argument: String ) {
65
+ self . init ( argument, normalizing: true )
66
+ }
67
+ }
60
68
61
69
extension GeneratorCLI {
62
70
struct GeneratorOptions : ParsableArguments {
@@ -94,29 +102,26 @@ extension GeneratorCLI {
94
102
help: """
95
103
CPU architecture of the host triple of the bundle. Defaults to a triple of the machine this generator is \
96
104
running on if unspecified. Available options: \(
97
- Triple . CPU . allCases. map { " ` \( $0. rawValue) ` " } . joined ( separator: " , " )
105
+ Triple . Arch . allCases. map { " ` \( $0. rawValue) ` " } . joined ( separator: " , " )
98
106
) .
99
107
"""
100
108
)
101
- var hostArch : Triple . CPU ? = nil
109
+ var hostArch : Triple . Arch ? = nil
102
110
103
111
@Option (
104
112
help: """
105
113
CPU architecture of the target triple of the bundle. Same as the host triple CPU architecture if unspecified. \
106
- Available options: \( Triple . CPU . allCases. map { " ` \( $0. rawValue) ` " } . joined ( separator: " , " ) ) .
114
+ Available options: \( Triple . Arch . allCases. map { " ` \( $0. rawValue) ` " } . joined ( separator: " , " ) ) .
107
115
"""
108
116
)
109
- var targetArch : Triple . CPU ? = nil
110
-
111
- func deriveTriples( ) async throws -> ( hostTriple: Triple , targetTriple: Triple ) {
112
- let hostTriple = try await SwiftSDKGenerator . getHostTriple ( explicitArch: hostArch, isVerbose: verbose)
113
- let targetTriple = Triple (
114
- cpu: targetArch ?? hostTriple. cpu,
115
- vendor: . unknown,
116
- os: . linux,
117
- environment: . gnu
118
- )
119
- return ( hostTriple, targetTriple)
117
+ var targetArch : Triple . Arch ? = nil
118
+
119
+ func deriveHostTriple( ) throws -> Triple {
120
+ let current = try SwiftSDKGenerator . getCurrentTriple ( isVerbose: verbose)
121
+ if let explicitArch = hostArch {
122
+ return Triple ( arch: explicitArch, vendor: current. vendor, os: current. os!)
123
+ }
124
+ return current
120
125
}
121
126
}
122
127
@@ -155,6 +160,10 @@ extension GeneratorCLI {
155
160
)
156
161
var linuxDistributionVersion : String ?
157
162
163
+ func deriveTargetTriple( hostTriple: Triple ) -> Triple {
164
+ Triple ( arch: self . generatorOptions. targetArch ?? hostTriple. arch!, vendor: nil , os: . linux, environment: . gnu)
165
+ }
166
+
158
167
func run( ) async throws {
159
168
if isInvokedAsDefaultSubcommand ( ) {
160
169
print ( " deprecated: Please explicity specify the subcommand to run. For example: $ swift-sdk-generator make-linux-sdk " )
@@ -167,7 +176,8 @@ extension GeneratorCLI {
167
176
}
168
177
let linuxDistributionVersion = self . linuxDistributionVersion ?? linuxDistributionDefaultVersion
169
178
let linuxDistribution = try LinuxDistribution ( name: linuxDistributionName, version: linuxDistributionVersion)
170
- let ( _, targetTriple) = try await generatorOptions. deriveTriples ( )
179
+ let hostTriple = try self . generatorOptions. deriveHostTriple ( )
180
+ let targetTriple = self . deriveTargetTriple ( hostTriple: hostTriple)
171
181
172
182
let recipe = try LinuxRecipe (
173
183
targetTriple: targetTriple,
@@ -178,7 +188,7 @@ extension GeneratorCLI {
178
188
withDocker: withDocker,
179
189
fromContainerImage: fromContainerImage
180
190
)
181
- try await GeneratorCLI . run ( recipe: recipe, options: generatorOptions)
191
+ try await GeneratorCLI . run ( recipe: recipe, hostTriple : hostTriple , targetTriple : targetTriple , options: generatorOptions)
182
192
}
183
193
184
194
func isInvokedAsDefaultSubcommand( ) -> Bool {
0 commit comments