Move posix_spawn detection to build.rs

This is *simpler*, and would have made us detect the issue with broken
includes before.

Part of #12055
This commit is contained in:
Fabian Boehm
2025-11-19 17:37:19 +01:00
parent d99aa696db
commit f598186574
2 changed files with 10 additions and 19 deletions

View File

@@ -92,7 +92,15 @@ fn detect_cfgs(target: &mut Target) {
target.has_symbol("localeconv_l")
}),
("have_pipe2", &|target| target.has_symbol("pipe2")),
("have_posix_spawn", &|target| target.has_header("spawn.h")),
("have_posix_spawn", &|target| {
if target_os() == "openbsd" {
// OpenBSD's posix_spawn returns status 127 instead of erroring with ENOEXEC when faced with a
// shebang-less script. Disable posix_spawn on OpenBSD.
false
} else {
target.has_header("spawn.h")
}
}),
("small_main_stack", &has_small_stack),
("use_prebuilt_docs", &|_| {
env_var("FISH_USE_PREBUILT_DOCS").is_some_and(|v| v == "TRUE")

View File

@@ -311,7 +311,7 @@ fn handle_term_change(vars: &EnvStack) {
fn handle_fish_use_posix_spawn_change(vars: &EnvStack) {
// Note that if the variable is missing or empty we default to true (if allowed).
if !allow_use_posix_spawn() {
if !cfg!(have_posix_spawn) {
USE_POSIX_SPAWN.store(false, Ordering::Relaxed);
} else if let Some(var) = vars.get(L!("fish_use_posix_spawn")) {
let use_posix_spawn =
@@ -538,20 +538,3 @@ fn init_locale(vars: &EnvStack) {
pub fn use_posix_spawn() -> bool {
USE_POSIX_SPAWN.load(Ordering::Relaxed)
}
/// Whether or not we are running on an OS where we allow ourselves to use `posix_spawn()`.
const fn allow_use_posix_spawn() -> bool {
// OpenBSD's posix_spawn returns status 127 instead of erroring with ENOEXEC when faced with a
// shebang-less script. Disable posix_spawn on OpenBSD.
if cfg!(target_os = "openbsd") {
false
} else if cfg!(not(target_os = "linux")) {
true
} else {
// The C++ code used __GLIBC_PREREQ(2, 24) && !defined(__UCLIBC__) to determine if we'll use
// posix_spawn() by default on Linux. Surprise! We don't have to worry about porting that
// logic here because the libc crate only supports 2.26+ atm.
// See https://github.com/rust-lang/libc/issues/1412
true
}
}