Skip to content

Commit dce4662

Browse files
committed
Make the package build on all Apple platforms
Although the functionality is not available on iOS-derived platforms, this can make cross platform development smoother.
1 parent c6dc97f commit dce4662

File tree

7 files changed

+18
-10
lines changed

7 files changed

+18
-10
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import PackageDescription
55

66
let availabilityMacro: SwiftSetting = .enableExperimentalFeature(
7-
"AvailabilityMacro=SubprocessSpan: macOS 9999",
7+
"AvailabilityMacro=SubprocessSpan: macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, visionOS 9999",
88
)
99

1010
var dep: [Package.Dependency] = [
@@ -31,7 +31,7 @@ defaultTraits.insert("SubprocessSpan")
3131

3232
let package = Package(
3333
name: "Subprocess",
34-
platforms: [.macOS(.v13)],
34+
platforms: [.macOS(.v13), .iOS(.v16)],
3535
products: [
3636
.library(
3737
name: "Subprocess",

[email protected]

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import PackageDescription
55

66
let availabilityMacro: SwiftSetting = .enableExperimentalFeature(
7-
"AvailabilityMacro=SubprocessSpan: macOS 9999"
7+
"AvailabilityMacro=SubprocessSpan: macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, visionOS 9999",
88
)
99

1010
let package = Package(
1111
name: "Subprocess",
12-
platforms: [.macOS(.v13)],
12+
platforms: [.macOS(.v13), .iOS(.v16)]],
1313
products: [
1414
.library(
1515
name: "Subprocess",

Sources/Subprocess/Atomic.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal struct AtomicBox: Sendable, ~Copyable {
3737

3838
internal init() {
3939
#if canImport(Synchronization)
40-
guard #available(macOS 15, *) else {
40+
guard #available(macOS 15, iOS 18, tvOS 18, watchOS 11, visionOS 2, *) else {
4141
fatalError("Unexpected configuration")
4242
}
4343
let box = Atomic(UInt8(0))
@@ -62,7 +62,7 @@ internal struct AtomicBox: Sendable, ~Copyable {
6262
}
6363

6464
#if canImport(Synchronization)
65-
@available(macOS 15, *)
65+
@available(macOS 15, iOS 18, tvOS 18, watchOS 11, visionOS 2, *)
6666
extension Atomic where Value == UInt8 {
6767
borrowing func _bitwiseXor(
6868
_ operand: OutputConsumptionState

Sources/Subprocess/Platforms/Subprocess+Darwin.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ extension Configuration {
166166
error: Error,
167167
errorPipe: CreatedPipe
168168
) throws -> Execution<Output, Error> {
169+
#if !os(macOS)
170+
throw SubprocessError(code: .init(.spawnFailed), underlyingError: .init(rawValue: ENOTSUP))
171+
#else
169172
// Instead of checking if every possible executable path
170173
// is valid, spawn each directly and catch ENOENT
171174
let possiblePaths = self.executable.possibleExecutablePaths(
@@ -377,6 +380,7 @@ extension Configuration {
377380
underlyingError: .init(rawValue: ENOENT)
378381
)
379382
}
383+
#endif
380384
}
381385
}
382386

Sources/_SubprocessCShims/process_shims.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ vm_size_t _subprocess_vm_size(void) {
8484
#endif
8585

8686
// MARK: - Darwin (posix_spawn)
87-
#if TARGET_OS_MAC
87+
#if TARGET_OS_OSX
8888
static int _subprocess_spawn_prefork(
8989
pid_t * _Nonnull pid,
9090
const char * _Nonnull exec_path,
@@ -247,7 +247,7 @@ int _subprocess_spawn(
247247
return posix_spawn(pid, exec_path, file_actions, spawn_attrs, args, env);
248248
}
249249

250-
#endif // TARGET_OS_MAC
250+
#endif // TARGET_OS_OSX
251251

252252
// MARK: - Linux (fork/exec + posix_spawn fallback)
253253
#if TARGET_OS_LINUX

Tests/SubprocessTests/SubprocessTests+Darwin.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ struct SubprocessDarwinTests {
3232
}
3333
var platformOptions = PlatformOptions()
3434
platformOptions.preSpawnProcessConfigurator = { spawnAttr, _ in
35+
#if os(macOS)
3536
// Set POSIX_SPAWN_SETSID flag, which implies calls
3637
// to setsid
3738
var flags: Int16 = 0
3839
posix_spawnattr_getflags(&spawnAttr, &flags)
3940
posix_spawnattr_setflags(&spawnAttr, flags | Int16(POSIX_SPAWN_SETSID))
41+
#endif
4042
}
4143
// Check the proces ID (pid), pross group ID (pgid), and
4244
// controling terminal's process group ID (tpgid)
@@ -56,10 +58,12 @@ struct SubprocessDarwinTests {
5658
let intendedWorkingDir = FileManager.default.temporaryDirectory.path()
5759
var platformOptions = PlatformOptions()
5860
platformOptions.preSpawnProcessConfigurator = { _, fileAttr in
61+
#if os(macOS)
5962
// Change the working directory
6063
intendedWorkingDir.withCString { path in
6164
_ = posix_spawn_file_actions_addchdir_np(&fileAttr, path)
6265
}
66+
#endif
6367
}
6468
let pwdResult = try await Subprocess.run(
6569
.path("/bin/pwd"),

Tests/SubprocessTests/SubprocessTests+Linting.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private func enableLintingTest() -> Bool {
2525
} catch {
2626
return false
2727
}
28-
#elseif os(Linux) || os(Windows)
28+
#else
2929
// Use swift-format directly
3030
do {
3131
_ = try Executable.name("swift-format")
@@ -66,7 +66,7 @@ struct SubprocessLintingTest {
6666
executable: .path("/usr/bin/xcrun"),
6767
arguments: ["swift-format", "lint", "-s", "--recursive", sourcePath]
6868
)
69-
#elseif os(Linux) || os(Windows)
69+
#else
7070
let configuration = Configuration(
7171
executable: .name("swift-format"),
7272
arguments: ["lint", "-s", "--recursive", sourcePath]

0 commit comments

Comments
 (0)