Skip to content

Commit 0cf84e2

Browse files
committed
Disambiguate apple and darwin triples
Fixes a bug where all triples with vendor apple are considered to be os variants of darwin. This change special cases "apple-none" to not match `Triple.isDarwin()`, but all other "apple-*" triples will still be considered to be darwin variant. Fixes some fallout of making the above change to check for the newly added `Triple.isApple()` instead of `Triple.isDarwin()` to allow the triple "apple-none" to opt into behaviors like dead stripping, using libtool, etc. As a result of these changes spm no longer appends a macOS version number to the "armv7em-apple-none-macho" triple (e.g. "armv7em-apple-none-macho10.13") removing the work around of passing "-target armv7em-apple-none-macho" via cli args or via a toolset.json. Additionally spm no longer passes unexpected -rpath args to the linker when building a static binary for "armv7em-apple-none-macho".
1 parent a5d1e8d commit 0cf84e2

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

Sources/Basics/Triple.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,23 @@ public struct Triple: Encodable, Equatable, Sendable {
159159
return nil
160160
}
161161

162+
public func isApple() -> Bool {
163+
vendor == .apple
164+
}
165+
162166
public func isAndroid() -> Bool {
163167
os == .linux && abi == .android
164168
}
165169

166170
public func isDarwin() -> Bool {
167-
vendor == .apple || os == .macOS || os == .darwin
171+
switch (vendor, os) {
172+
case (.apple, .noneOS):
173+
return false
174+
case (.apple, _), (_, .macOS), (_, .darwin):
175+
return true
176+
default:
177+
return false
178+
}
168179
}
169180

170181
public func isLinux() -> Bool {

Sources/Build/BuildDescription/ProductBuildDescription.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
113113
case .debug:
114114
return []
115115
case .release:
116-
if self.buildParameters.triple.isDarwin() {
116+
if self.buildParameters.triple.isApple() {
117117
return ["-Xlinker", "-dead_strip"]
118118
} else if self.buildParameters.triple.isWindows() {
119119
return ["-Xlinker", "/OPT:REF"]
@@ -139,7 +139,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
139139
if triple.isWindows(), librarian.hasSuffix("link") || librarian.hasSuffix("link.exe") {
140140
return try [librarian, "/LIB", "/OUT:\(binaryPath.pathString)", "@\(self.linkFileListPath.pathString)"]
141141
}
142-
if triple.isDarwin(), librarian.hasSuffix("libtool") {
142+
if triple.isApple(), librarian.hasSuffix("libtool") {
143143
return try [librarian, "-static", "-o", binaryPath.pathString, "@\(self.linkFileListPath.pathString)"]
144144
}
145145
return try [librarian, "crs", binaryPath.pathString, "@\(self.linkFileListPath.pathString)"]

Sources/Build/BuildPlan.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ extension BuildParameters {
138138
/// Computes the linker flags to use in order to rename a module-named main function to 'main' for the target platform, or nil if the linker doesn't support it for the platform.
139139
func linkerFlagsForRenamingMainFunction(of target: ResolvedTarget) -> [String]? {
140140
let args: [String]
141-
if self.triple.isDarwin() {
141+
if self.triple.isApple() {
142142
args = ["-alias", "_\(target.c99name)_main", "_main"]
143143
}
144144
else if self.triple.isLinux() {

Sources/PackageModel/UserToolchain.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ public final class UserToolchain: Toolchain {
135135
) throws
136136
-> AbsolutePath
137137
{
138-
let variable: String = triple.isDarwin() ? "LIBTOOL" : "AR"
138+
let variable: String = triple.isApple() ? "LIBTOOL" : "AR"
139139
let tool: String = {
140-
if triple.isDarwin() { return "libtool" }
140+
if triple.isApple() { return "libtool" }
141141
if triple.isWindows() {
142142
if let librarian: AbsolutePath =
143143
UserToolchain.lookup(

Sources/SPMBuildCore/BuildParameters.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ public struct BuildParameters: Encodable {
380380
return nil
381381
}
382382

383-
if triple.isDarwin() {
383+
if triple.isApple() {
384384
return .swiftAST
385385
}
386386
return .modulewrap

0 commit comments

Comments
 (0)