Skip to content

Commit 452c88c

Browse files
Replace --target-arch/--host-arch <arch> with --target/--host <triple> (#73)
* Replace `--target-cpu/--host-cpu <arch>` with `--target/--host <triple>` This allows users to specify other triple fields like os and vendor. * Update Sources/GeneratorCLI/GeneratorCLI.swift Co-authored-by: Max Desiatov <[email protected]> * Keep backward compatibility for `--target-arch/--host-arch` * Fix typo in deprecation help message --------- Co-authored-by: Max Desiatov <[email protected]>
1 parent d18cdb4 commit 452c88c

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

Sources/GeneratorCLI/GeneratorCLI.swift

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,33 @@ extension GeneratorCLI {
100100

101101
@Option(
102102
help: """
103-
CPU architecture of the host triple of the bundle. Defaults to a triple of the machine this generator is \
104-
running on if unspecified. Available options: \(
105-
Triple.Arch.allCases.map { "`\($0.rawValue)`" }.joined(separator: ", ")
106-
).
103+
The host triple of the bundle. Defaults to a triple of the machine this generator is \
104+
running on if unspecified.
107105
"""
108106
)
109-
var hostArch: Triple.Arch? = nil
107+
var host: Triple? = nil
110108

111109
@Option(
112110
help: """
113-
CPU architecture of the target triple of the bundle. Same as the host triple CPU architecture if unspecified. \
114-
Available options: \(Triple.Arch.allCases.map { "`\($0.rawValue)`" }.joined(separator: ", ")).
111+
The target triple of the bundle. The default depends on a recipe used for SDK generation. Pass `--help` to a specific recipe subcommand for more details.
115112
"""
116113
)
114+
var target: Triple? = nil
115+
116+
@Option(help: "Deprecated. Use `--host` instead")
117+
var hostArch: Triple.Arch? = nil
118+
@Option(help: "Deprecated. Use `--target` instead")
117119
var targetArch: Triple.Arch? = nil
118120

119121
func deriveHostTriple() throws -> Triple {
122+
if let host {
123+
return host
124+
}
120125
let current = try SwiftSDKGenerator.getCurrentTriple(isVerbose: verbose)
121-
if let explicitArch = hostArch {
122-
return Triple(arch: explicitArch, vendor: current.vendor, os: current.os!)
126+
if let arch = hostArch {
127+
let target = Triple(arch: arch, vendor: current.vendor!, os: current.os!)
128+
print("deprecated: Please use `--host \(target.triple)` instead of `--host-arch \(arch)`")
129+
return target
123130
}
124131
return current
125132
}
@@ -128,7 +135,10 @@ extension GeneratorCLI {
128135
struct MakeLinuxSDK: AsyncParsableCommand {
129136
static let configuration = CommandConfiguration(
130137
commandName: "make-linux-sdk",
131-
abstract: "Generate a Swift SDK bundle for Linux."
138+
abstract: "Generate a Swift SDK bundle for Linux.",
139+
discussion: """
140+
The default `--target` triple is Linux with the same CPU architecture with host triple
141+
"""
132142
)
133143

134144
@OptionGroup
@@ -161,7 +171,14 @@ extension GeneratorCLI {
161171
var linuxDistributionVersion: String?
162172

163173
func deriveTargetTriple(hostTriple: Triple) -> Triple {
164-
Triple(arch: self.generatorOptions.targetArch ?? hostTriple.arch!, vendor: nil, os: .linux, environment: .gnu)
174+
if let target = generatorOptions.target {
175+
return target
176+
}
177+
if let arch = generatorOptions.targetArch {
178+
let target = Triple(arch: arch, vendor: nil, os: .linux, environment: .gnu)
179+
print("deprecated: Please use `--target \(target.triple)` instead of `--target-arch \(arch)`")
180+
}
181+
return Triple(arch: hostTriple.arch!, vendor: nil, os: .linux, environment: .gnu)
165182
}
166183

167184
func run() async throws {

0 commit comments

Comments
 (0)