Releases: swiftlang/swift-subprocess
Subprocess 0.2.1
This is a minor release that fixes two issues:
- #201 Set interface include directory for the subprocess target
- #199 Fix
Environment.updating
for custom andrawBytes
New Contributors
Full Changelog: 0.2...0.2.1
Subprocess 0.2
This release introduces two API changes and several important bug fixes.
API Changes
Introduced CombinedErrorOutput
A new output type for subprocesses that merges the standard error stream with the standard output stream.
When CombinedErrorOutput
is used as the error output for a subprocess, both the standard output and standard error from the child process are combined into a single output stream. This is equivalent to using shell redirection such as 2>&1
.
Updated Environment.updating
to Accept [Key: String?]
This change allows an environment variable to be unset by assigning it a value of nil
.
Important Bug Fixes
- #196 Fixed CMake support. Subprocess can now be used as a dependent project in CMake builds.
- #198 Fixed a hanging issue that occurs in release builds.
Detailed Change Log
- Fix incorrect documentation in Buffer.swift withUnsafeBytes method by @valeriyvan in #178
- Report proper error by @valeriyvan in #177
- Fix some typos by @valeriyvan in #181
- Introudce CombinedErrorOutput by @iCharlesHu in #180
- Fix dependency of Swift System by @0xTim in #187
- Change Environment.updating to accept [Key: String?] by @iCharlesHu in #193
- Add extern "C" to header process_shims.h by @j-hui in #195
- CMake fixes to allow use in dependent projects by @owenv in #196
- Don't suspend/resume the thread while holding an exclusive inout reference by @jakepetroules in #198
New Contributors
- @valeriyvan made their first contribution in #178
- @0xTim made their first contribution in #187
- @j-hui made their first contribution in #195
- @owenv made their first contribution in #196
Full Changelog: 0.1...0.2
Subprocess 0.1
This is the initial release of swift-subprocess
.
API Changes Since Initial Proposal
-
Introduce
preferredBufferSize
parameter to allow custom buffer size when streaming subprocess output (#168)A new
preferredBufferSize
parameter was added to the streaming APIs, allowing developers to control the buffer size when reading subprocess output instead of relying on a fixed default.
public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
_ executable: Executable,
arguments: Arguments = [],
environment: Environment = .inherit,
workingDirectory: FilePath? = nil,
platformOptions: PlatformOptions = PlatformOptions(),
input: Input = .none,
error: Error = .discarded,
preferredBufferSize: Int? = nil, // New API
isolation: isolated (any Actor)? = #isolation,
body: ((Execution, AsyncBufferSequence) async throws -> Result)
) async throws -> ExecutionResult<Result> where Error.OutputType == Void
-
Expand API with
Configuration
-basedrun()
overloads (#164)Added new
run()
overloads that allow subprocesses to be launched using aConfiguration
, bringing parity with APIs that take individual parameters.
// New Configuration-based APIs
public func run<
InputElement: BitwiseCopyable,
Output: OutputProtocol,
Error: OutputProtocol
>(
_ configuration: Configuration,
input: borrowing Span<InputElement>,
output: Output,
error: Error = .discarded
) async throws -> CollectedResult<Output, Error>
public func run<Result, Input: InputProtocol, Output: OutputProtocol, Error: OutputProtocol>(
_ configuration: Configuration,
input: Input = .none,
output: Output = .discarded,
error: Error = .discarded,
isolation: isolated (any Actor)? = #isolation,
body: ((Execution) async throws -> Result)
) async throws -> ExecutionResult<Result> where Error.OutputType == Void
public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
_ configuration: Configuration,
input: Input = .none,
error: Error = .discarded,
isolation: isolated (any Actor)? = #isolation,
body: ((Execution, AsyncBufferSequence) async throws -> Result)
) async throws -> ExecutionResult<Result> where Error.OutputType == Void
public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
_ configuration: Configuration,
input: Input = .none,
output: Output,
isolation: isolated (any Actor)? = #isolation,
body: ((Execution, AsyncBufferSequence) async throws -> Result)
) async throws -> ExecutionResult<Result> where Output.OutputType == Void
public func run<Result, Error: OutputProtocol>(
_ configuration: Configuration,
error: Error = .discarded,
isolation: isolated (any Actor)? = #isolation,
body: ((Execution, StandardInputWriter, AsyncBufferSequence) async throws -> Result)
) async throws -> ExecutionResult<Result> where Error.OutputType == Void
public func run<Result, Output: OutputProtocol>(
_ configuration: Configuration,
output: Output,
isolation: isolated (any Actor)? = #isolation,
body: ((Execution, StandardInputWriter, AsyncBufferSequence) async throws -> Result)
) async throws -> ExecutionResult<Result> where Output.OutputType == Void
-
Remove
preSpawnProcessConfigurator
on LinuxThis property has been removed due to async-signal-safety concerns. It is not possible to offer a safe implementation of this API.
-
Remove the default collected output buffer limit and throw an error when the limit is reached (#130)
The default output buffer has been removed. All run() methods now require developers to explicitly specify the output type and buffer limit. If the limit is reached, an error will be thrown. This change ensures developers choose buffer sizes that best fit their use case.
@@ -9,6 +9,6 @@ public func run<
workingDirectory: FilePath? = nil,
platformOptions: PlatformOptions = PlatformOptions(),
input: Input = .none,
- output: Output = .string,
+ output: Output,
error: Error = .discarded
) async throws -> CollectedResult<Output, Error>
-
Expose platform-specific process file descriptors (#101)
Linux, FreeBSD, and Windows now expose their respective process descriptors (
pidfd
on Linux and FreeBSD,HANDLE
on Windows). These allow integration with system APIs that require descriptors rather than raw process IDs.
@@ -2,7 +2,7 @@
public struct ProcessIdentifier: Sendable, Hashable {
/// The platform-specific process identifier value
public let value: pid_t
- internal let processDescriptor: PlatformFileDescriptor
+ public let processDescriptor: PlatformFileDescriptor
}
#endif
@@ -10,7 +10,7 @@ public struct ProcessIdentifier: Sendable, Hashable {
public struct ProcessIdentifier: Sendable, Hashable {
/// Windows-specific process identifier value
public let value: DWORD
- internal nonisolated(unsafe) let processDescriptor: HANDLE
- internal nonisolated(unsafe) let threadHandle: HANDLE
+ public nonisolated(unsafe) let processDescriptor: HANDLE
+ public nonisolated(unsafe) let threadHandle: HANDLE
}
#endif
-
Remove runDetached API (#95)
runDetached
was originally proposed as the synchronous counterpart torun()
. However, sinceposix_spawn
can block, this API could not be implemented synchronously. It has therefore been removed. -
Make
Configuration.workingDirectory
optional (#74)Configuration.workingDirectory
is now optional. Anil
value means the subprocess will inherit the parent process’s working directory.
@@ -2,6 +2,6 @@ public struct Configuration: Sendable {
public var executable: Executable
public var arguments: Arguments
public var environment: Environment
- public var workingDirectory: FilePath
+ public var workingDirectory: FilePath?
public var platformOptions: PlatformOptions
}
-
AsyncBufferSequence.Buffer
Improvements (#48)Introduced
AsyncBufferSequence.LineSequence
as the preferred way to stream output as text. This converts the rawBuffer
sequence into an asynchronous sequence of lines.
extension AsyncBufferSequence {
public struct LineSequence<Encoding: _UnicodeEncoding>: AsyncSequence, Sendable {
public typealias Element = String
public enum BufferingPolicy: Sendable {
case unbounded
case maxLineLength(Int)
}
public struct AsyncIterator: AsyncIteratorProtocol {
public mutating func next() async throws -> String?
}
public func makeAsyncIterator() -> AsyncIterator
}
public func lines() -> LineSequence<UTF8>
public func lines<Encoding: _UnicodeEncoding>(
encoding: Encoding.Type,
bufferingPolicy: LineSequence<Encoding>.BufferingPolicy = .maxLineLength(128 * 1024)
) -> LineSequence<Encoding>
}
-
Make Environment keys case-insensitive on Windows (#174)
Introduced
Environment.Key
to provide a platform-aware way of accessing environment variables. Keys are now case-insensitive on Windows, while retaining case sensitivity on platforms where that is the convention.
public struct Key: ExpressibleByStringLiteral, Codable, Hashable, RawRepresentable, CustomStringConvertible, Sendable{
public var rawValue: String
public init(stringLiteral rawValue: String)
}