Closed NobodyXu closed 5 months ago
Since the API surface I proposed is a bit large, I think it makes sense to implement them separately, under different feature flags.
As per the discussion on zulip, I've updated the API to be platform-independent instead of unix-specific, since windows, WASI and most of the other OSes seem to have annoymous pipe and named fifo support.
We discussed this in the libs-api meeting. As you said, the API surface is a bit large, and we think it can be split up. We're happy to accept a subset: the API for anonymous pipes, without the (Linux) extension methods. However, instead of the cloexec
API, the close-on-exec flag should be set by default on creation (just like for any other file descriptor that the standard library opens). (Passing file descriptors to a child process should be the job of the Command
API.)
The (Linux) extension methods and named pipes part of this ACP should be left for separate ACPs.
Thanks, I've opened PR rust-lang/rust#127153 to add the anonymous pipe API
Opened #416 for named fifo
Proposal
Problem statement
Annoymous and named pipe are widely used, there is crate
os_pipe
which just provides an abstraction for pipe on unix and has 15 million download.While having a third-party crate for it is enough for many crates, I think it'd be better if it's in stdlib so that it can be used without having to another dependency for this.
It would also enable better integration with the
std::process
API, since users might want to pipe output of multiple processes to one pipe and read them.Motivating examples or use cases
jobserver-rs, for example, is used by cc-rs and pulled in as
build-dependencies
quite often.It internally implements all kinds of API for annoymous pipe and named fifo, contains a bunch of
unsafe
code for this and quite some code for just managing the pipe/fifo.It'd be great if we could move them to stdlib and make jobserver-rs easier to maintain. It might also speedup jobserver-rs compilation since it could've drop the
libc
dependency.tokio, the widely used async executor, already provide pipe support in mod
tokio::net::unix::pipe
.Solution sketch
I suppose we can use os_pipe as basis and then add in more functions used by jobserver-rs, and functions provided by rustix:
The basic API for annoymous pipe:
The basic API for named fifo:
Extension methods for unix:
Extension methods for Linux:
Alternatives
Alternatively, we could first implement a subset of the API I proposed here to reduce the scope. Then we could consider adding more methods that are needed.
Or we could just leave them up to third-party crates, which is the current status-quo, which is OK-ish but not good enough for users who need pipe/fifo, they would have to grab a third-party crate for this.
Links and related work
tokio::net::unix::pipe
rustix::pipe