Skip to content

Run with Custom Closure sample code not compiling #15

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
McNight opened this issue Apr 21, 2025 · 0 comments
Open

Run with Custom Closure sample code not compiling #15

McNight opened this issue Apr 21, 2025 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@McNight
Copy link

McNight commented Apr 21, 2025

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!

@McNight McNight added the bug Something isn't working label Apr 21, 2025
@iCharlesHu iCharlesHu self-assigned this May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants