From e64fc4163c0273f6f4f377fcf43b6b6975ae6e78 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 3 Mar 2023 22:25:25 -0800 Subject: [PATCH 1/5] Use `weak!` for `setns`, `preadv64v2`, and `pwritev64v2` on GLIBC. (#556) `setns`, `preadv64v2`, and `pwritev64v2` were introduced more recently than the earliest glibc we support, so use the `weak!` mechanism for them, with fallbacks using `syscall`. --- src/backend/libc/offset.rs | 123 ++++++++++++++++++++++++---- src/backend/libc/thread/syscalls.rs | 8 +- 2 files changed, 116 insertions(+), 15 deletions(-) diff --git a/src/backend/libc/offset.rs b/src/backend/libc/offset.rs index 8aae9d073..6e8ce49a2 100644 --- a/src/backend/libc/offset.rs +++ b/src/backend/libc/offset.rs @@ -213,8 +213,21 @@ pub(super) use c::posix_fadvise64 as libc_posix_fadvise; pub(super) use c::{pread as libc_pread, pwrite as libc_pwrite}; #[cfg(any(target_os = "android", target_os = "linux", target_os = "emscripten"))] pub(super) use c::{pread64 as libc_pread, pwrite64 as libc_pwrite}; +#[cfg(not(any( + windows, + target_os = "android", + target_os = "emscripten", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos", + target_os = "redox", + target_os = "solaris", +)))] +pub(super) use c::{preadv as libc_preadv, pwritev as libc_pwritev}; #[cfg(any(target_os = "linux", target_os = "emscripten"))] pub(super) use c::{preadv64 as libc_preadv, pwritev64 as libc_pwritev}; + #[cfg(target_os = "android")] mod readwrite_pv64 { use super::c; @@ -302,20 +315,9 @@ mod readwrite_pv64 { } } } -#[cfg(not(any( - windows, - target_os = "android", - target_os = "emscripten", - target_os = "haiku", - target_os = "ios", - target_os = "linux", - target_os = "macos", - target_os = "redox", - target_os = "solaris", -)))] -pub(super) use c::{preadv as libc_preadv, pwritev as libc_pwritev}; #[cfg(target_os = "android")] pub(super) use readwrite_pv64::{preadv64 as libc_preadv, pwritev64 as libc_pwritev}; + // macOS added preadv and pwritev in version 11.0 #[cfg(any(target_os = "ios", target_os = "macos"))] mod readwrite_pv { @@ -337,11 +339,104 @@ mod readwrite_pv { ) -> c::ssize_t } } -#[cfg(all(target_os = "linux", target_env = "gnu"))] -pub(super) use c::{preadv64v2 as libc_preadv2, pwritev64v2 as libc_pwritev2}; #[cfg(any(target_os = "ios", target_os = "macos"))] pub(super) use readwrite_pv::{preadv as libc_preadv, pwritev as libc_pwritev}; +// GLIBC added `preadv64v2` and `pwritev64v2` in version 2.26. +#[cfg(all(target_os = "linux", target_env = "gnu"))] +mod readwrite_pv64v2 { + use super::c; + + // 64-bit offsets on 32-bit platforms are passed in endianness-specific + // lo/hi pairs. See src/backend/linux_raw/conv.rs for details. + #[cfg(all(target_endian = "little", target_pointer_width = "32"))] + fn lo(x: u64) -> usize { + (x >> 32) as usize + } + #[cfg(all(target_endian = "little", target_pointer_width = "32"))] + fn hi(x: u64) -> usize { + (x & 0xffff_ffff) as usize + } + #[cfg(all(target_endian = "big", target_pointer_width = "32"))] + fn lo(x: u64) -> usize { + (x & 0xffff_ffff) as usize + } + #[cfg(all(target_endian = "big", target_pointer_width = "32"))] + fn hi(x: u64) -> usize { + (x >> 32) as usize + } + + pub(in super::super) unsafe fn preadv64v2( + fd: c::c_int, + iov: *const c::iovec, + iovcnt: c::c_int, + offset: c::off64_t, + flags: c::c_int, + ) -> c::ssize_t { + // Older GLIBC lacks `preadv64v2`, so use the `weak!` mechanism to + // test for it, and call back to `c::syscall`. We don't use + // `weak_or_syscall` here because we need to pass the 64-bit offset + // specially. + weak! { + fn preadv64v2(c::c_int, *const c::iovec, c::c_int, c::off64_t, c::c_int) -> c::ssize_t + } + if let Some(fun) = preadv64v2.get() { + fun(fd, iov, iovcnt, offset, flags) + } else { + #[cfg(target_pointer_width = "32")] + { + c::syscall( + c::SYS_preadv, + fd, + iov, + iovcnt, + hi(offset as u64), + lo(offset as u64), + flags, + ) as c::ssize_t + } + #[cfg(target_pointer_width = "64")] + { + c::syscall(c::SYS_preadv2, fd, iov, iovcnt, offset, flags) as c::ssize_t + } + } + } + pub(in super::super) unsafe fn pwritev64v2( + fd: c::c_int, + iov: *const c::iovec, + iovcnt: c::c_int, + offset: c::off64_t, + flags: c::c_int, + ) -> c::ssize_t { + // See the comments in `preadv64v2`. + weak! { + fn pwritev64v2(c::c_int, *const c::iovec, c::c_int, c::off64_t, c::c_int) -> c::ssize_t + } + if let Some(fun) = pwritev64v2.get() { + fun(fd, iov, iovcnt, offset, flags) + } else { + #[cfg(target_pointer_width = "32")] + { + c::syscall( + c::SYS_pwritev, + fd, + iov, + iovcnt, + hi(offset as u64), + lo(offset as u64), + flags, + ) as c::ssize_t + } + #[cfg(target_pointer_width = "64")] + { + c::syscall(c::SYS_pwritev2, fd, iov, iovcnt, offset, flags) as c::ssize_t + } + } + } +} +#[cfg(all(target_os = "linux", target_env = "gnu"))] +pub(super) use readwrite_pv64v2::{preadv64v2 as libc_preadv2, pwritev64v2 as libc_pwritev2}; + #[cfg(not(any( windows, target_os = "aix", diff --git a/src/backend/libc/thread/syscalls.rs b/src/backend/libc/thread/syscalls.rs index 4f69b8f63..7877d46b5 100644 --- a/src/backend/libc/thread/syscalls.rs +++ b/src/backend/libc/thread/syscalls.rs @@ -291,7 +291,13 @@ pub(crate) fn gettid() -> Pid { #[cfg(any(target_os = "android", target_os = "linux"))] #[inline] pub(crate) fn setns(fd: BorrowedFd, nstype: c::c_int) -> io::Result { - unsafe { ret_c_int(c::setns(borrowed_fd(fd), nstype)) } + // `setns` wasn't supported in glibc until 2.14, and musl until 0.9.5, + // so use `syscall`. + weak_or_syscall! { + fn setns(fd: c::c_int, nstype: c::c_int) via SYS_setns -> c::c_int + } + + unsafe { ret_c_int(setns(borrowed_fd(fd), nstype)) } } #[cfg(any(target_os = "android", target_os = "linux"))] From a0be9a2ba52d5a122833034a5daec1d74f5f4a42 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 9 Feb 2023 16:41:59 -0800 Subject: [PATCH 2/5] Fix `use-libc-auxv` to use a weak dependency on `getauxval`. (#535) * Fix `use-libc-auxv` to use a weak dependency on `getauxval`. glibc <= 2.15 lacks `getauxval`, so avoid a strong dependency on it in the `use-libc-auxv` implementation. --- src/backend/linux_raw/mod.rs | 5 + src/backend/linux_raw/param/libc_auxv.rs | 37 ++-- src/backend/linux_raw/weak.rs | 228 +++++++++++++++++++++++ 3 files changed, 256 insertions(+), 14 deletions(-) create mode 100644 src/backend/linux_raw/weak.rs diff --git a/src/backend/linux_raw/mod.rs b/src/backend/linux_raw/mod.rs index e7e073e32..1b91fc3ab 100644 --- a/src/backend/linux_raw/mod.rs +++ b/src/backend/linux_raw/mod.rs @@ -14,6 +14,11 @@ //! such as which pointers are array slices, out parameters, or in-out //! parameters, which integers are owned or borrowed file descriptors, etc. +// Weak symbols used by the use-libc-auxv feature for glibc 2.15 support. +#[cfg(feature = "use-libc-auxv")] +#[macro_use] +mod weak; + #[macro_use] mod arch; mod conv; diff --git a/src/backend/linux_raw/param/libc_auxv.rs b/src/backend/linux_raw/param/libc_auxv.rs index 1597fd727..467a2800c 100644 --- a/src/backend/linux_raw/param/libc_auxv.rs +++ b/src/backend/linux_raw/param/libc_auxv.rs @@ -5,14 +5,15 @@ //! This uses raw pointers to locate and read the kernel-provided auxv array. #![allow(unsafe_code)] -#[cfg(any(feature = "param", feature = "runtime"))] -use super::super::c; use super::super::elf::*; #[cfg(feature = "param")] use crate::ffi::CStr; #[cfg(feature = "runtime")] use core::slice; +// `getauxval` wasn't supported in glibc until 2.16. +weak!(fn getauxval(libc::c_ulong) -> *mut libc::c_void); + #[cfg(feature = "param")] #[inline] pub(crate) fn page_size() -> usize { @@ -22,35 +23,39 @@ pub(crate) fn page_size() -> usize { #[cfg(feature = "param")] #[inline] pub(crate) fn clock_ticks_per_second() -> u64 { - unsafe { libc::getauxval(libc::AT_CLKTCK) as u64 } + unsafe { libc::sysconf(libc::_SC_CLK_TCK) as u64 } } #[cfg(feature = "param")] #[inline] pub(crate) fn linux_hwcap() -> (usize, usize) { - unsafe { - ( - libc::getauxval(libc::AT_HWCAP) as usize, - libc::getauxval(libc::AT_HWCAP2) as usize, - ) + if let Some(libc_getauxval) = getauxval.get() { + unsafe { + let hwcap = libc_getauxval(libc::AT_HWCAP) as usize; + let hwcap2 = libc_getauxval(libc::AT_HWCAP2) as usize; + (hwcap, hwcap2) + } + } else { + (0, 0) } } #[cfg(feature = "param")] #[inline] pub(crate) fn linux_execfn() -> &'static CStr { - unsafe { - let execfn = libc::getauxval(libc::AT_EXECFN) as *const c::c_char; - CStr::from_ptr(execfn.cast()) + if let Some(libc_getauxval) = getauxval.get() { + unsafe { CStr::from_ptr(libc_getauxval(libc::AT_EXECFN).cast()) } + } else { + cstr!("") } } #[cfg(feature = "runtime")] #[inline] -pub(crate) fn exe_phdrs() -> (*const c::c_void, usize) { +pub(crate) fn exe_phdrs() -> (*const libc::c_void, usize) { unsafe { ( - libc::getauxval(libc::AT_PHDR) as *const c::c_void, + libc::getauxval(libc::AT_PHDR) as *const libc::c_void, libc::getauxval(libc::AT_PHNUM) as usize, ) } @@ -70,5 +75,9 @@ pub(in super::super) fn exe_phdrs_slice() -> &'static [Elf_Phdr] { /// so if we don't see it, this function returns a null pointer. #[inline] pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr { - unsafe { libc::getauxval(linux_raw_sys::general::AT_SYSINFO_EHDR.into()) as *const Elf_Ehdr } + if let Some(libc_getauxval) = getauxval.get() { + unsafe { libc_getauxval(linux_raw_sys::general::AT_SYSINFO_EHDR.into()) as *const Elf_Ehdr } + } else { + core::ptr::null() + } } diff --git a/src/backend/linux_raw/weak.rs b/src/backend/linux_raw/weak.rs new file mode 100644 index 000000000..265d8b701 --- /dev/null +++ b/src/backend/linux_raw/weak.rs @@ -0,0 +1,228 @@ +// Implementation derived from `weak` in Rust's +// library/std/src/sys/unix/weak.rs at revision +// fd0cb0cdc21dd9c06025277d772108f8d42cb25f. + +#![allow(unsafe_code)] + +//! Support for "weak linkage" to symbols on Unix +//! +//! Some I/O operations we do in libstd require newer versions of OSes but we +//! need to maintain binary compatibility with older releases for now. In order +//! to use the new functionality when available we use this module for +//! detection. +//! +//! One option to use here is weak linkage, but that is unfortunately only +//! really workable on Linux. Hence, use dlsym to get the symbol value at +//! runtime. This is also done for compatibility with older versions of glibc, +//! and to avoid creating dependencies on `GLIBC_PRIVATE` symbols. It assumes +//! that we've been dynamically linked to the library the symbol comes from, +//! but that is currently always the case for things like libpthread/libc. +//! +//! A long time ago this used weak linkage for the `__pthread_get_minstack` +//! symbol, but that caused Debian to detect an unnecessarily strict versioned +//! dependency on libc6 (#23628). + +// There are a variety of `#[cfg]`s controlling which targets are involved in +// each instance of `weak!` and `syscall!`. Rather than trying to unify all of +// that, we'll just allow that some unix targets don't use this module at all. +#![allow(dead_code, unused_macros)] +#![allow(clippy::doc_markdown)] + +use crate::ffi::CStr; +use core::ffi::c_void; +use core::ptr::null_mut; +use core::sync::atomic::{self, AtomicPtr, Ordering}; +use core::{marker, mem}; + +const NULL: *mut c_void = null_mut(); +const INVALID: *mut c_void = 1 as *mut c_void; + +macro_rules! weak { + ($vis:vis fn $name:ident($($t:ty),*) -> $ret:ty) => ( + #[allow(non_upper_case_globals)] + $vis static $name: $crate::backend::weak::Weak $ret> = + $crate::backend::weak::Weak::new(concat!(stringify!($name), '\0')); + ) +} + +pub(crate) struct Weak { + name: &'static str, + addr: AtomicPtr, + _marker: marker::PhantomData, +} + +impl Weak { + pub(crate) const fn new(name: &'static str) -> Self { + Self { + name, + addr: AtomicPtr::new(INVALID), + _marker: marker::PhantomData, + } + } + + pub(crate) fn get(&self) -> Option { + assert_eq!(mem::size_of::(), mem::size_of::()); + unsafe { + // Relaxed is fine here because we fence before reading through the + // pointer (see the comment below). + match self.addr.load(Ordering::Relaxed) { + INVALID => self.initialize(), + NULL => None, + addr => { + let func = mem::transmute_copy::<*mut c_void, F>(&addr); + // The caller is presumably going to read through this value + // (by calling the function we've dlsymed). This means we'd + // need to have loaded it with at least C11's consume + // ordering in order to be guaranteed that the data we read + // from the pointer isn't from before the pointer was + // stored. Rust has no equivalent to memory_order_consume, + // so we use an acquire fence (sorry, ARM). + // + // Now, in practice this likely isn't needed even on CPUs + // where relaxed and consume mean different things. The + // symbols we're loading are probably present (or not) at + // init, and even if they aren't the runtime dynamic loader + // is extremely likely have sufficient barriers internally + // (possibly implicitly, for example the ones provided by + // invoking `mprotect`). + // + // That said, none of that's *guaranteed*, and so we fence. + atomic::fence(Ordering::Acquire); + Some(func) + } + } + } + } + + // Cold because it should only happen during first-time initialization. + #[cold] + unsafe fn initialize(&self) -> Option { + let val = fetch(self.name); + // This synchronizes with the acquire fence in `get`. + self.addr.store(val, Ordering::Release); + + match val { + NULL => None, + addr => Some(mem::transmute_copy::<*mut c_void, F>(&addr)), + } + } +} + +unsafe fn fetch(name: &str) -> *mut c_void { + let name = match CStr::from_bytes_with_nul(name.as_bytes()) { + Ok(c_str) => c_str, + Err(..) => return null_mut(), + }; + libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr().cast()) +} + +#[cfg(not(any(target_os = "android", target_os = "linux")))] +macro_rules! syscall { + (fn $name:ident($($arg_name:ident: $t:ty),*) via $_sys_name:ident -> $ret:ty) => ( + unsafe fn $name($($arg_name: $t),*) -> $ret { + weak! { fn $name($($t),*) -> $ret } + + if let Some(fun) = $name.get() { + fun($($arg_name),*) + } else { + libc_errno::set_errno(libc_errno::Errno(libc::ENOSYS)); + -1 + } + } + ) +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +macro_rules! syscall { + (fn $name:ident($($arg_name:ident: $t:ty),*) via $sys_name:ident -> $ret:ty) => ( + unsafe fn $name($($arg_name:$t),*) -> $ret { + // This looks like a hack, but concat_idents only accepts idents + // (not paths). + use libc::*; + + trait AsSyscallArg { + type SyscallArgType; + fn into_syscall_arg(self) -> Self::SyscallArgType; + } + + // Pass pointer types as pointers, to preserve provenance. + impl AsSyscallArg for *mut T { + type SyscallArgType = *mut T; + fn into_syscall_arg(self) -> Self::SyscallArgType { self } + } + impl AsSyscallArg for *const T { + type SyscallArgType = *const T; + fn into_syscall_arg(self) -> Self::SyscallArgType { self } + } + + // Pass `BorrowedFd` values as the integer value. + impl AsSyscallArg for $crate::fd::BorrowedFd<'_> { + type SyscallArgType = c::c_long; + fn into_syscall_arg(self) -> Self::SyscallArgType { + $crate::fd::AsRawFd::as_raw_fd(&self) as _ + } + } + + // Coerce integer values into `c_long`. + impl AsSyscallArg for i32 { + type SyscallArgType = c::c_long; + fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } + } + impl AsSyscallArg for u32 { + type SyscallArgType = c::c_long; + fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } + } + impl AsSyscallArg for usize { + type SyscallArgType = c::c_long; + fn into_syscall_arg(self) -> Self::SyscallArgType { self as _ } + } + + // `concat_idents is unstable, so we take an extra `sys_name` + // parameter and have our users do the concat for us for now. + /* + syscall( + concat_idents!(SYS_, $name), + $($arg_name.into_syscall_arg()),* + ) as $ret + */ + + syscall($sys_name, $($arg_name.into_syscall_arg()),*) as $ret + } + ) +} + +macro_rules! weakcall { + ($vis:vis fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => ( + $vis unsafe fn $name($($arg_name: $t),*) -> $ret { + weak! { fn $name($($t),*) -> $ret } + + // Use a weak symbol from libc when possible, allowing `LD_PRELOAD` + // interposition, but if it's not found just fail. + if let Some(fun) = $name.get() { + fun($($arg_name),*) + } else { + libc_errno::set_errno(libc_errno::Errno(libc::ENOSYS)); + -1 + } + } + ) +} + +/// A combination of `weakcall` and `syscall`. Use the libc function if it's +/// available, and fall back to `libc::syscall` otherwise. +macro_rules! weak_or_syscall { + ($vis:vis fn $name:ident($($arg_name:ident: $t:ty),*) via $sys_name:ident -> $ret:ty) => ( + $vis unsafe fn $name($($arg_name: $t),*) -> $ret { + weak! { fn $name($($t),*) -> $ret } + + // Use a weak symbol from libc when possible, allowing `LD_PRELOAD` + // interposition, but if it's not found just fail. + if let Some(fun) = $name.get() { + fun($($arg_name),*) + } else { + syscall! { fn $name($($arg_name: $t),*) via $sys_name -> $ret } + $name($($arg_name),*) + } + } + ) +} From 8ec514e0d1ce0a9d1459b50fd7a814a5f95632b4 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 3 Feb 2023 14:01:04 -0800 Subject: [PATCH 3/5] Disable FreeBSD CI for now. (#530) FreeBSD CI has been broken for some time with this error ``` [4/4] Extracting curl-7.87.0_1: .......... done curl https://sh.rustup.rs -sSf --output rustup.sh ld-elf.so.1: /usr/local/lib/libcurl.so.4: Undefined symbol "nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation" ``` Comment it out for now. --- .cirrus.yml | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 599acbd12..ca05e2b00 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,16 +1,22 @@ # Implementation derived from `.cirrus.yml` in Rust's libc bindings # at revision 7f4774e76bd5cb9ccb7140d71ef9be9c16009cdf. -task: - name: stable x86_64-unknown-freebsd-13 - freebsd_instance: - image_family: freebsd-13-0-snap - setup_script: - - pkg install -y curl - - curl https://sh.rustup.rs -sSf --output rustup.sh - - sh rustup.sh --default-toolchain stable -y --profile=minimal - - . $HOME/.cargo/env - - rustup default stable - test_script: - - . $HOME/.cargo/env - - cargo test --workspace --features=all-apis +# Disable FreeBSD testing for now, as we currently hit this error: +# +# [4/4] Extracting curl-7.87.0_1: .......... done +# curl https://sh.rustup.rs -sSf --output rustup.sh +# ld-elf.so.1: /usr/local/lib/libcurl.so.4: Undefined symbol "nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation" + +#task: +# name: stable x86_64-unknown-freebsd-13 +# freebsd_instance: +# image_family: freebsd-13-0-snap +# setup_script: +# - pkg install -y curl +# - curl https://sh.rustup.rs -sSf --output rustup.sh +# - sh rustup.sh --default-toolchain stable -y --profile=minimal +# - . $HOME/.cargo/env +# - rustup default stable +# test_script: +# - . $HOME/.cargo/env +# - cargo test --workspace --features=all-apis From a8791826ce375c69d7e3dbe99f5fd19f1a64bf44 Mon Sep 17 00:00:00 2001 From: Val Packett Date: Wed, 22 Feb 2023 18:03:10 -0300 Subject: [PATCH 4/5] Reenable FreeBSD CI with correct image family (#540) The issue was using snapshots of already released versions, which is not supported. --- .cirrus.yml | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index ca05e2b00..211dd9eb2 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,22 +1,16 @@ # Implementation derived from `.cirrus.yml` in Rust's libc bindings # at revision 7f4774e76bd5cb9ccb7140d71ef9be9c16009cdf. -# Disable FreeBSD testing for now, as we currently hit this error: -# -# [4/4] Extracting curl-7.87.0_1: .......... done -# curl https://sh.rustup.rs -sSf --output rustup.sh -# ld-elf.so.1: /usr/local/lib/libcurl.so.4: Undefined symbol "nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation" - -#task: -# name: stable x86_64-unknown-freebsd-13 -# freebsd_instance: -# image_family: freebsd-13-0-snap -# setup_script: -# - pkg install -y curl -# - curl https://sh.rustup.rs -sSf --output rustup.sh -# - sh rustup.sh --default-toolchain stable -y --profile=minimal -# - . $HOME/.cargo/env -# - rustup default stable -# test_script: -# - . $HOME/.cargo/env -# - cargo test --workspace --features=all-apis +task: + name: stable x86_64-unknown-freebsd-13 + freebsd_instance: + image_family: freebsd-13-1 + setup_script: + - pkg install -y curl + - curl https://sh.rustup.rs -sSf --output rustup.sh + - sh rustup.sh --default-toolchain stable -y --profile=minimal + - . $HOME/.cargo/env + - rustup default stable + test_script: + - . $HOME/.cargo/env + - cargo test --workspace --features=all-apis From 0c73bbddfe9d6ce28b01b36785090f5380906d69 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 27 Feb 2023 20:00:58 -0800 Subject: [PATCH 5/5] Add more `cargo:rerun-if-env-changed`'s to build.rs (#544) * Add more `cargo:rerun-if-env-changed`'s to build.rs Add more `cargo:rerun-if-env-changed`'s to build.rs for rustix's features, configuration flags, and the toolchain variables rustix uses for autoconfiguration, to hopefully ensure it gets rerun when anything changes. See also #526. * Don't include all the cargo features. --- build.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/build.rs b/build.rs index 697110771..4ee4fedcb 100644 --- a/build.rs +++ b/build.rs @@ -107,6 +107,18 @@ fn main() { } println!("cargo:rerun-if-env-changed=CARGO_CFG_RUSTIX_USE_EXPERIMENTAL_ASM"); + println!("cargo:rerun-if-env-changed=CARGO_CFG_RUSTIX_USE_LIBC"); + + // Rerun this script if any of our features or configuration flags change, + // or if the toolchain we used for feature detection changes. + println!("cargo:rerun-if-env-changed=CARGO_FEATURE_USE_LIBC"); + println!("cargo:rerun-if-env-changed=CARGO_FEATURE_RUSTC_DEP_OF_STD"); + println!("cargo:rerun-if-env-changed=CARGO_CFG_MIRI"); + println!("cargo:rerun-if-env-changed=CARGO_ENCODED_RUSTFLAGS"); + println!("cargo:rerun-if-env-changed=RUSTC"); + println!("cargo:rerun-if-env-changed=TARGET"); + println!("cargo:rerun-if-env-changed=CARGO_RUSTC_WRAPPER"); + println!("cargo:rerun-if-env-changed=PROFILE"); } /// Link in the desired version of librustix_outline_{arch}.a, containing the