Skip to content

Make the package build on all Apple platforms #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import PackageDescription

let availabilityMacro: SwiftSetting = .enableExperimentalFeature(
"AvailabilityMacro=SubprocessSpan: macOS 9999",
"AvailabilityMacro=SubprocessSpan: macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, visionOS 9999",
)

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

let package = Package(
name: "Subprocess",
platforms: [.macOS(.v13)],
platforms: [.macOS(.v13), .iOS(.v16)],
products: [
.library(
name: "Subprocess",
Expand Down
4 changes: 2 additions & 2 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import PackageDescription

let availabilityMacro: SwiftSetting = .enableExperimentalFeature(
"AvailabilityMacro=SubprocessSpan: macOS 9999"
"AvailabilityMacro=SubprocessSpan: macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, visionOS 9999",
)

let package = Package(
name: "Subprocess",
platforms: [.macOS(.v13)],
platforms: [.macOS(.v13), .iOS(.v16)]],
products: [
.library(
name: "Subprocess",
Expand Down
4 changes: 2 additions & 2 deletions Sources/Subprocess/Atomic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal struct AtomicBox: Sendable, ~Copyable {

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

#if canImport(Synchronization)
@available(macOS 15, *)
@available(macOS 15, iOS 18, tvOS 18, watchOS 11, visionOS 2, *)
extension Atomic where Value == UInt8 {
borrowing func _bitwiseXor(
_ operand: OutputConsumptionState
Expand Down
4 changes: 4 additions & 0 deletions Sources/Subprocess/Platforms/Subprocess+Darwin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ extension Configuration {
error: Error,
errorPipe: CreatedPipe
) throws -> Execution<Output, Error> {
#if !os(macOS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motivation of this change makes sense, but this runtime error inside this function is very non obvious to me.

throw SubprocessError(code: .init(.spawnFailed), underlyingError: .init(rawValue: ENOTSUP))
#else
// Instead of checking if every possible executable path
// is valid, spawn each directly and catch ENOENT
let possiblePaths = self.executable.possibleExecutablePaths(
Expand Down Expand Up @@ -377,6 +380,7 @@ extension Configuration {
underlyingError: .init(rawValue: ENOENT)
)
}
#endif
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/_SubprocessCShims/process_shims.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ vm_size_t _subprocess_vm_size(void) {
#endif

// MARK: - Darwin (posix_spawn)
#if TARGET_OS_MAC
#if TARGET_OS_OSX
static int _subprocess_spawn_prefork(
pid_t * _Nonnull pid,
const char * _Nonnull exec_path,
Expand Down Expand Up @@ -247,7 +247,7 @@ int _subprocess_spawn(
return posix_spawn(pid, exec_path, file_actions, spawn_attrs, args, env);
}

#endif // TARGET_OS_MAC
#endif // TARGET_OS_OSX

// MARK: - Linux (fork/exec + posix_spawn fallback)
#if TARGET_OS_LINUX
Expand Down
4 changes: 4 additions & 0 deletions Tests/SubprocessTests/SubprocessTests+Darwin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ struct SubprocessDarwinTests {
}
var platformOptions = PlatformOptions()
platformOptions.preSpawnProcessConfigurator = { spawnAttr, _ in
#if os(macOS)
// Set POSIX_SPAWN_SETSID flag, which implies calls
// to setsid
var flags: Int16 = 0
posix_spawnattr_getflags(&spawnAttr, &flags)
posix_spawnattr_setflags(&spawnAttr, flags | Int16(POSIX_SPAWN_SETSID))
#endif
}
// Check the proces ID (pid), pross group ID (pgid), and
// controling terminal's process group ID (tpgid)
Expand All @@ -56,10 +58,12 @@ struct SubprocessDarwinTests {
let intendedWorkingDir = FileManager.default.temporaryDirectory.path()
var platformOptions = PlatformOptions()
platformOptions.preSpawnProcessConfigurator = { _, fileAttr in
#if os(macOS)
// Change the working directory
intendedWorkingDir.withCString { path in
_ = posix_spawn_file_actions_addchdir_np(&fileAttr, path)
}
#endif
}
let pwdResult = try await Subprocess.run(
.path("/bin/pwd"),
Expand Down
4 changes: 2 additions & 2 deletions Tests/SubprocessTests/SubprocessTests+Linting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private func enableLintingTest() -> Bool {
} catch {
return false
}
#elseif os(Linux) || os(Windows)
#else
// Use swift-format directly
do {
_ = try Executable.name("swift-format")
Expand Down Expand Up @@ -66,7 +66,7 @@ struct SubprocessLintingTest {
executable: .path("/usr/bin/xcrun"),
arguments: ["swift-format", "lint", "-s", "--recursive", sourcePath]
)
#elseif os(Linux) || os(Windows)
#else
let configuration = Configuration(
executable: .name("swift-format"),
arguments: ["lint", "-s", "--recursive", sourcePath]
Expand Down