Skip to main content

Crate bun_spawn

Crate bun_spawn 

Source
Expand description

bun_spawn — process-spawn implementation extracted from src/runtime/api/bun/process.zig so that bun_install, bun_jsc, and bun_patch can construct/track child processes without depending on bun_runtime (cycle: bun_runtime → bun_install/bun_jsc).

LAYERING: this crate owns the spawn implementation (not just data shapes). Process, Poller, WaiterThread, spawn_process, and sync::spawn were MOVED DOWN here from bun_runtime::api::bun::process; bun_runtime re-exports them. The only non-leaf dependencies are bun_io (FilePoll/KeepAlive/EventLoopCtx), bun_ptr (ThreadSafeRefCount), bun_io (BufferedWriter), bun_event_loop, bun_threading, and bun_crash_handler — none of which depend back on this crate, so no cycle.

Zig source of truth: src/runtime/api/bun/process.zig, src/runtime/api/bun/spawn.zig, src/runtime/api/bun/subprocess/StaticPipeWriter.zig.

Re-exports§

pub use process::Exited;
pub use process::Poller;
pub use process::Process;
pub use process::SignalCodeExt;
pub use process::SpawnOptions;
pub use process::SpawnProcessResult;
pub use process::SpawnResultExt;
pub use process::Status;
pub use process::WaiterThread;
pub use process::spawn_process;
pub use bun_sys as spawn_sys;

Modules§

ffi
posix_spawn
posix_spawn(2) FFI wrappers (Actions / Attr / spawn_z / wait4). MOVE_DOWN: implementation now lives in bun_spawn_sys; re-exported here with the higher-tier process::* glue (Process/Status/spawn_process/ sync) restored so existing bun_spawn::posix_spawn::bun_spawn::* paths keep resolving.
process
Process / Poller / WaiterThread / spawn_process / sync / Status / SpawnOptions / SpawnResult. Port of src/runtime/api/bun/process.zig.
static_pipe_writer
Generic StaticPipeWriter<P> (jsc.Subprocess.NewStaticPipeWriter). Port of src/runtime/api/bun/subprocess/StaticPipeWriter.zig.
subprocess
sync
bun.spawnSync (process.zig pub const sync).

Macros§

link_impl_ProcessExit

Structs§

Dup2
PosixSpawnOptions
PosixSpawnResult
ProcessExit
RunOptions
Options for run — port of std.process.Child.RunOptions (subset used by repository.zig).
RunResult
Result of run — port of std.process.Child.RunResult.
WaitPidResult
posix_spawn::WaitPidResult — re-exported from bun_spawn_sys. status is u32 there (Zig c_int reinterpreted via the W* macros); Status::from casts before matching.

Enums§

EventLoopHandle
ExtraPipe
Entry in extra_pipes for a stdio slot at index >= 3.
ProcessExitKind
Stdio
StdioKind
bun.jsc.Subprocess.StdioKind — defined here (not in subprocess) to keep the spawn-sys layer leaf. Re-exported up through bun_spawn::process → bun_runtime::api::{bun_process, JscSubprocess} → shell::subproc.
Term
Port of std.process.Child.Term.

Traits§

RusageFields
Platform-uniform field accessors over Rusage. The underlying alias has divergent field names (ru_* on every Unix libc::rusage; bare names on WinRusage with several u0/absent counters). This trait gives JS-facing getters one cfg-free body, matching the Zig spec’s uniform names.

Functions§

run
Port of std.process.Child.run — blocking spawn that captures stdout/stderr.

Type Aliases§

Argv
[*:null]?[*:0]const u8 — null-terminated array of NUL-terminated C strings (the argv shape posix_spawn/execve accept). Build as Vec<*const c_char> with a trailing core::ptr::null(), then .as_ptr().
CStrPtr
Element type for an owned Vec backing an Argv/Envp. Null is the sentinel; never wrap in Option.
Envp
Same shape as Argv for the environment block.
ExtraFd
Alias for the per-extra-fd Stdio entry passed in SpawnOptions::extra_fds.
PidT
ProcessExitHandler
None = no handler set (the default for Process::exit_handler).
Rusage
SpawnResult