Skip to content

Commit 7837bd7

Browse files
rauhulMaxDesiatov
authored andcommitted
Enable armv7em CPU and none OS triples (#6438)
Adds preliminary knowledge of `armv7em` CPU and `none` OS environments to SwiftPM. Future diffs will be required to fully support these triples. This change allows a `armv7em-apple-none-macho` build via a destination v3 bundle to make it further through SwiftPM. (cherry picked from commit da7d339) # Conflicts: # Sources/SPMBuildCore/BuildParameters.swift
1 parent f9c5565 commit 7837bd7

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

Sources/Basics/Triple.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public struct Triple: Encodable, Equatable, Sendable {
4848
case aarch64
4949
case amd64
5050
case armv7
51+
case armv7em
5152
case armv6
5253
case armv5
5354
case arm
@@ -73,6 +74,8 @@ public struct Triple: Encodable, Equatable, Sendable {
7374
case windows
7475
case wasi
7576
case openbsd
77+
// 'OS' suffix purely to avoid name clash with Optional.none
78+
case noneOS = "none"
7679
}
7780

7881
public enum ABI: Encodable, Equatable, RawRepresentable, Sendable {
@@ -265,6 +268,8 @@ extension Triple {
265268
return ".dll"
266269
case .wasi:
267270
return ".wasm"
271+
case .noneOS:
272+
fatalError("Cannot create dynamic libraries for os \"none\".")
268273
}
269274
}
270275

@@ -278,6 +283,8 @@ extension Triple {
278283
return ".wasm"
279284
case .windows:
280285
return ".exe"
286+
case .noneOS:
287+
return ""
281288
}
282289
}
283290

Sources/SPMBuildCore/BinaryTarget+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extension Triple.OS {
9797
/// Returns a representation of the receiver that can be compared with platform strings declared in an XCFramework.
9898
fileprivate var asXCFrameworkPlatformString: String? {
9999
switch self {
100-
case .darwin, .linux, .wasi, .windows, .openbsd:
100+
case .darwin, .linux, .wasi, .windows, .openbsd, .noneOS:
101101
return nil // XCFrameworks do not support any of these platforms today.
102102
case .macOS:
103103
return "macos"

Sources/SPMBuildCore/BuildParameters.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,18 +391,22 @@ public struct BuildParameters: Encodable {
391391
return buildPath.appending(binaryRelativePath(for: product))
392392
}
393393

394+
/// Returns the path to the dynamic library of a product for the current build parameters.
395+
func potentialDynamicLibraryPath(for product: ResolvedProduct) throws -> RelativePath {
396+
try RelativePath(validating: "\(triple.dynamicLibraryPrefix)\(product.name)\(triple.dynamicLibraryExtension)")
397+
}
398+
394399
/// Returns the path to the binary of a product for the current build parameters, relative to the build directory.
395-
public func binaryRelativePath(for product: ResolvedProduct) -> RelativePath {
396-
let potentialExecutablePath = RelativePath("\(product.name)\(triple.executableExtension)")
397-
let potentialLibraryPath = RelativePath("\(triple.dynamicLibraryPrefix)\(product.name)\(triple.dynamicLibraryExtension)")
400+
public func binaryRelativePath(for product: ResolvedProduct) throws -> RelativePath {
401+
let potentialExecutablePath = try RelativePath(validating: "\(product.name)\(triple.executableExtension)")
398402

399403
switch product.type {
400404
case .executable, .snippet:
401405
return potentialExecutablePath
402406
case .library(.static):
403407
return RelativePath("lib\(product.name)\(triple.staticLibraryExtension)")
404408
case .library(.dynamic):
405-
return potentialLibraryPath
409+
return try potentialDynamicLibraryPath(for: product)
406410
case .library(.automatic), .plugin:
407411
fatalError()
408412
case .test:
@@ -418,7 +422,7 @@ public struct BuildParameters: Encodable {
418422
}
419423
case .macro:
420424
#if BUILD_MACROS_AS_DYLIBS
421-
return potentialLibraryPath
425+
return try potentialDynamicLibraryPath(for: product)
422426
#else
423427
return potentialExecutablePath
424428
#endif

0 commit comments

Comments
 (0)