Skip to content

Run with Custom Closure sample code not compiling #15

@McNight

Description

@McNight

Describe the bug
The sample code provided in Run with Custom Closure section (requiring SubprocessSpan trait) is not compiling.

To Reproduce
Steps to reproduce the behavior:

  1. Make sure you have a Swift 6.2 development snapshot installed & configured with swiftly
  2. swift package init --type executable
  3. Make swift-subprocess a dependency & provide the SubprocessSpan trait
  4. Use the sample code provided in the Run with Custom Closure

Expected behavior
It compiles and runs fine.

Environment (please complete the following information):

  • OS: macOS 15.4.1
  • Swift version: Apple Swift version 6.2-dev (LLVM 81ab6d9f7e4810f, Swift 9cc1947527bacea)

Additional context
I had trouble running the sample code provided in Run with Custom Closure section.

First, pls correct me if I'm wrong: I think we should specify that this sample would work only if you specify the SubprocessSpan trait.

Then, even with the trait enabled, you have to provide these arguments to the run function:

try await run(
    .path("/bin/dd"),
    arguments: ["if=/path/to/document"],
    input: .none, // <-- here...
    output: .sequence, // <-- here...
    error: .discarded // <-- and here.
)

I don't know if it could be interesting to provide default values to these parameters for these Run with Closure family of APIs, or if this is intended.

Then, the body of the closure in itself doesn't build, especially this line:

let string = chunk.withUnsafeBytes { String(decoding: $0, as: UTF8.self) }

withUnsafeBytes is not available when SubprocessSpan is set.

If you change it to:

let string = chunk.bytes.withUnsafeBytes { String(decoding: $0, as: UTF8.self) } // bytes is the newly introduced RawSpan

then you get the following error: Lifetime-dependent value escapes its scope.

What's funny though is that I first tried to run this on Asahi Linux Fedora 42 and it worked fine (I didn't get the lifetime value error).

To circumvent this lifetime error on macOS (it wasn't needed on Linux), I added this extension:

public func stringFromBytes() -> String {
    bytes.withUnsafeBytes { String(decoding: $0, as: UTF8.self) }
}

but I don't know if it's correct, I'm not yet familiar with the new ~Escapable capabilities and RawSpac introduced in Swift 6.2...

Finally, with this extension, it built fine but when I tried to run it, I got this runtime issue:

dyld[3790]: Symbol not found: _$ss7RawSpanVN

So, sorry for the long text, and for the multiple issues, the library looks really cool though and I would be glad to help if some of my modifications made sense!

Thanks for your help!

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions