From 33f33c5f41373982826df674809f6a7a1802d7fc Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sat, 13 Jan 2024 15:45:42 -0600 Subject: [PATCH] Simplify (and fix?) build.rs HAVE_XXX detection Since none of the compiles(xxx) calls are to particularly complex code, we can just use `rsconf` directly to test for the presence of the symbols or headers as needed. Note that it seems at least some of the previous detection was not working correctly; in particular HAVE_PIPE2 was evaluating to false on my WSL install where pipe2(2) was available (caught because it revealed some compilation errors in that conditional compilation path after porting). I kept the cfg names and the tests themselves mostly as-is, though we might want to change that to conform with the rust convention of lowercase cfg names and decide whether we want to prefix all these with have_, fish_, or nothing at all. Also the posix_spawn() test should probably check for the symbol `posix_spawn()` rather than the header `spawn.h` since we don't use it via the header but rather via the symbol (but in reality they're almost certainly going to give the same result). --- build.rs | 17 ++++------------- src/cfg/eventfd.c | 1 - src/cfg/pipe2.c | 2 -- src/cfg/spawn.c | 1 - src/cfg/w_exitcode.cpp | 2 -- 5 files changed, 4 insertions(+), 19 deletions(-) delete mode 100644 src/cfg/eventfd.c delete mode 100644 src/cfg/pipe2.c delete mode 100644 src/cfg/spawn.c delete mode 100644 src/cfg/w_exitcode.cpp diff --git a/build.rs b/build.rs index f94702ef8..efc944fa6 100644 --- a/build.rs +++ b/build.rs @@ -55,19 +55,6 @@ fn main() { .include(&build_dir) .compile("flibc.a"); - if compiles("src/cfg/w_exitcode.cpp") { - println!("cargo:rustc-cfg=HAVE_WAITSTATUS_SIGNAL_RET"); - } - if compiles("src/cfg/eventfd.c") { - println!("cargo:rustc-cfg=HAVE_EVENTFD"); - } - if compiles("src/cfg/pipe2.c") { - println!("cargo:rustc-cfg=HAVE_PIPE2"); - } - if compiles("src/cfg/spawn.c") { - println!("cargo:rustc-cfg=FISH_USE_POSIX_SPAWN"); - } - let mut build = cc::Build::new(); // Add to the default library search path build.flag_if_supported("-L/usr/local/lib/"); @@ -102,6 +89,10 @@ fn detect_cfgs(target: Target) { ("gettext", &have_gettext), // See if the system headers provide the thread-safe localeconv_l(3) alternative to localeconv(3). ("localeconv_l", &|target| Ok(target.has_symbol_in::("localeconv_l", &[]))), + ("FISH_USE_POSIX_SPAWN", &|target| Ok(target.has_header("spawn.h"))), + ("HAVE_PIPE2", &|target| Ok(target.has_symbol_in::("pipe2", &[]))), + ("HAVE_EVENTFD", &|target| Ok(target.has_header("sys/eventfd.h"))), + ("HAVE_WAITSTATUS_SIGNAL_RET", &|target| Ok(target.r#if("WEXITSTATUS(0x007f) == 0x7f", "sys/wait.h"))), ] { match handler(&target) { Err(e) => rsconf::warn!("{}: {}", name, e), diff --git a/src/cfg/eventfd.c b/src/cfg/eventfd.c deleted file mode 100644 index fd6df4dee..000000000 --- a/src/cfg/eventfd.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/src/cfg/pipe2.c b/src/cfg/pipe2.c deleted file mode 100644 index c31e0f3bc..000000000 --- a/src/cfg/pipe2.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -int ok = pipe2(0, 0); diff --git a/src/cfg/spawn.c b/src/cfg/spawn.c deleted file mode 100644 index e6233bcb9..000000000 --- a/src/cfg/spawn.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/src/cfg/w_exitcode.cpp b/src/cfg/w_exitcode.cpp deleted file mode 100644 index 87bf484ef..000000000 --- a/src/cfg/w_exitcode.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include -static_assert(WEXITSTATUS(0x007f) == 0x7f, "");