Skip to content

Commit

Permalink
Unrolled build for rust-lang#137463
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#137463 - sunshowers:illumos-posix-spawn, r=Mark-Simulacrum

[illumos] attempt to use posix_spawn to spawn processes

illumos has `posix_spawn`, and the very newest versions also have `_addchdir`, so use that. POSIX standardized this function so I also added a weak symbol lookup for the non `_np` version. (illumos has both.)

This probably also works on Solaris, but I don't have access to an installation to validate this so I decided to focus on illumos instead.

This is a nice ~4x performance improvement for process creation. My go-to as usual is nextest against the clap repo, which acts as a stress test for process creation -- with [this commit]:

```console
$ cargo nextest run -E 'not test(ui_tests) and not test(example_tests)'
before: Summary [   1.747s] 879 tests run: 879 passed, 2 skipped
after:  Summary [   0.445s] 879 tests run: 879 passed, 2 skipped
```

[this commit]: clap-rs/clap@fde45f9
  • Loading branch information
rust-timer authored Mar 5, 2025
2 parents 4559163 + b340545 commit 69b725a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ dependencies = [

[[package]]
name = "libc"
version = "0.2.169"
version = "0.2.170"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ miniz_oxide = { version = "0.8.0", optional = true, default-features = false }
addr2line = { version = "0.24.0", optional = true, default-features = false }

[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2.169", default-features = false, features = [
libc = { version = "0.2.170", default-features = false, features = [
'rustc-dep-of-std',
], public = true }

Expand Down
17 changes: 16 additions & 1 deletion library/std/src/sys/pal/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ impl Command {

#[cfg(not(any(
target_os = "freebsd",
target_os = "illumos",
all(target_os = "linux", target_env = "gnu"),
all(target_os = "linux", target_env = "musl"),
target_os = "nto",
Expand All @@ -427,6 +428,7 @@ impl Command {
// directly.
#[cfg(any(
target_os = "freebsd",
target_os = "illumos",
all(target_os = "linux", target_env = "gnu"),
all(target_os = "linux", target_env = "musl"),
target_os = "nto",
Expand Down Expand Up @@ -584,14 +586,27 @@ impl Command {
fn get_posix_spawn_addchdir() -> Option<PosixSpawnAddChdirFn> {
use crate::sys::weak::weak;

// POSIX.1-2024 standardizes this function:
// https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_spawn_file_actions_addchdir.html.
// The _np version is more widely available, though, so try that first.

weak! {
fn posix_spawn_file_actions_addchdir_np(
*mut libc::posix_spawn_file_actions_t,
*const libc::c_char
) -> libc::c_int
}

posix_spawn_file_actions_addchdir_np.get()
weak! {
fn posix_spawn_file_actions_addchdir(
*mut libc::posix_spawn_file_actions_t,
*const libc::c_char
) -> libc::c_int
}

posix_spawn_file_actions_addchdir_np
.get()
.or_else(|| posix_spawn_file_actions_addchdir.get())
}

/// Get the function pointer for adding a chdir action to a
Expand Down

0 comments on commit 69b725a

Please sign in to comment.