From ff7fa0c306cd5d2863ca951ca0eae87355a1abce Mon Sep 17 00:00:00 2001 From: CodingCarpincho Date: Sun, 7 Sep 2025 22:34:37 -0700 Subject: [PATCH 1/3] Always use `rawValue` when using OS enum as string Certain enum cases, such as `freeBSD`, contain capital letters. However, target triples must be entirely in lower case. The enum case's raw value reflects this, but our custom initializer for the Triple structure does not use it, resulting in an invalid target triple. This makes the generated SDK unusable if the user passed only the desired architecture instead of a complete triple. To address this problem, the initializer should always request the rawValue explicitly. --- Sources/SwiftSDKGenerator/PlatformModels/Triple.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/SwiftSDKGenerator/PlatformModels/Triple.swift b/Sources/SwiftSDKGenerator/PlatformModels/Triple.swift index 55dec55..28f6870 100644 --- a/Sources/SwiftSDKGenerator/PlatformModels/Triple.swift +++ b/Sources/SwiftSDKGenerator/PlatformModels/Triple.swift @@ -18,10 +18,12 @@ extension Triple: @unchecked Sendable {} extension Triple { public init(arch: Arch, vendor: Vendor?, os: OS, environment: Environment) { + let os = os.rawValue self.init("\(arch)-\(vendor?.rawValue ?? "unknown")-\(os)-\(environment)", normalizing: true) } public init(arch: Arch, vendor: Vendor?, os: OS) { + let os = os.rawValue self.init("\(arch)-\(vendor?.rawValue ?? "unknown")-\(os)", normalizing: true) } } From b0c10e1d26ded0613bd677c651eb21c43d60ed6c Mon Sep 17 00:00:00 2001 From: CodingCarpincho Date: Sun, 7 Sep 2025 22:38:07 -0700 Subject: [PATCH 2/3] Include FreeBSD version number in derived target triple Target triples for the FreeBSD platform must include the FreeBSD version number at the end of the triple. If we use a derived target triple, then the version number won't be included, resulting in the SDK not being usable. --- Sources/GeneratorCLI/GeneratorCLI.swift | 6 +++--- Sources/SwiftSDKGenerator/PlatformModels/Triple.swift | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/GeneratorCLI/GeneratorCLI.swift b/Sources/GeneratorCLI/GeneratorCLI.swift index 5394b10..3ae62f9 100644 --- a/Sources/GeneratorCLI/GeneratorCLI.swift +++ b/Sources/GeneratorCLI/GeneratorCLI.swift @@ -345,12 +345,12 @@ extension GeneratorCLI { ) var freeBSDVersion: String - func deriveTargetTriple(hostTriples: [Triple]) throws -> Triple { + func deriveTargetTriple(hostTriples: [Triple], freebsdVersion: String) throws -> Triple { if let target = generatorOptions.target, target.os == .freeBSD { return target } if let arch = generatorOptions.targetArch { - let target = Triple(arch: arch, vendor: nil, os: .freeBSD) + let target = Triple(arch: arch, vendor: nil, os: .freeBSD, version: freebsdVersion) appLogger.warning( """ Using `--target-arch \(arch)` defaults to `\(target.triple)`. \ @@ -375,7 +375,7 @@ extension GeneratorCLI { } let hostTriples = try self.generatorOptions.deriveHostTriples() - let targetTriple = try self.deriveTargetTriple(hostTriples: hostTriples) + let targetTriple = try self.deriveTargetTriple(hostTriples: hostTriples, freebsdVersion: self.freeBSDVersion) let sourceSwiftToolchain: FilePath? if let fromSwiftToolchain { diff --git a/Sources/SwiftSDKGenerator/PlatformModels/Triple.swift b/Sources/SwiftSDKGenerator/PlatformModels/Triple.swift index 28f6870..a88a09e 100644 --- a/Sources/SwiftSDKGenerator/PlatformModels/Triple.swift +++ b/Sources/SwiftSDKGenerator/PlatformModels/Triple.swift @@ -26,6 +26,11 @@ extension Triple { let os = os.rawValue self.init("\(arch)-\(vendor?.rawValue ?? "unknown")-\(os)", normalizing: true) } + + public init(arch: Arch, vendor: Vendor?, os: OS, version: String) { + let os = os.rawValue + self.init("\(arch)-\(vendor?.rawValue ?? "unknown")-\(os)\(version)", normalizing: true) + } } extension Triple.Arch { From 3cfd454da5e3b3e243ef0847393f30d2a580aa2f Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Mon, 8 Sep 2025 10:39:57 +0100 Subject: [PATCH 3/3] Fix capitalization in `GeneratorCLI.swift` --- Sources/GeneratorCLI/GeneratorCLI.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/GeneratorCLI/GeneratorCLI.swift b/Sources/GeneratorCLI/GeneratorCLI.swift index 3ae62f9..c4b4fd9 100644 --- a/Sources/GeneratorCLI/GeneratorCLI.swift +++ b/Sources/GeneratorCLI/GeneratorCLI.swift @@ -345,12 +345,12 @@ extension GeneratorCLI { ) var freeBSDVersion: String - func deriveTargetTriple(hostTriples: [Triple], freebsdVersion: String) throws -> Triple { + func deriveTargetTriple(hostTriples: [Triple], freeBSDVersion: String) throws -> Triple { if let target = generatorOptions.target, target.os == .freeBSD { return target } if let arch = generatorOptions.targetArch { - let target = Triple(arch: arch, vendor: nil, os: .freeBSD, version: freebsdVersion) + let target = Triple(arch: arch, vendor: nil, os: .freeBSD, version: freeBSDVersion) appLogger.warning( """ Using `--target-arch \(arch)` defaults to `\(target.triple)`. \ @@ -375,7 +375,7 @@ extension GeneratorCLI { } let hostTriples = try self.generatorOptions.deriveHostTriples() - let targetTriple = try self.deriveTargetTriple(hostTriples: hostTriples, freebsdVersion: self.freeBSDVersion) + let targetTriple = try self.deriveTargetTriple(hostTriples: hostTriples, freeBSDVersion: self.freeBSDVersion) let sourceSwiftToolchain: FilePath? if let fromSwiftToolchain {