From f63b1b1be6ac59862ff9dd433f639324d19c4866 Mon Sep 17 00:00:00 2001 From: KaiTomotake Date: Sat, 17 Jan 2026 23:07:45 +0900 Subject: [PATCH] add 'environ' variable Add the environ variable to unix/mod.rs. add aarch64_macos_15_5_or_newer cfg --- build.rs | 15 +++++++++++++++ libc-test/semver/unix.txt | 1 + src/unix/mod.rs | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/build.rs b/build.rs index cbebca6207f2a..cba29c0d7508f 100644 --- a/build.rs +++ b/build.rs @@ -31,6 +31,7 @@ const ALLOWED_CFGS: &[&str] = &[ // Corresponds to `_REDIR_TIME64` in musl "musl32_time64", "vxworks_lt_25_09", + "aarch64_macos_15_5_or_newer", ]; // Extra values to allow for check-cfg. @@ -65,6 +66,20 @@ fn main() { let target_ptr_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default(); let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); + println!("cargo:rerun-if-env-changed=MACOSX_DEPLOYMENT_TARGET"); + + if target_os == "macos" && target_arch == "aarch64" { + if let Ok(deployment) = env::var("MACOSX_DEPLOYMENT_TARGET") { + let mut it = deployment.split('.'); + let major = it.next().and_then(|x| x.parse::().ok()).unwrap_or(0); + let minor = it.next().and_then(|x| x.parse::().ok()).unwrap_or(0); + + if (major, minor) >= (15, 5) { + set_cfg("aarch64_macos_15_5_or_newer"); + } + } + } + // The ABI of libc used by std is backward compatible with FreeBSD 12. // The ABI of libc from crates.io is backward compatible with FreeBSD 12. // diff --git a/libc-test/semver/unix.txt b/libc-test/semver/unix.txt index 052c24178dfcc..ae447cc7627e0 100644 --- a/libc-test/semver/unix.txt +++ b/libc-test/semver/unix.txt @@ -505,6 +505,7 @@ dlopen dlsym dup dup2 +environ execl execle execlp diff --git a/src/unix/mod.rs b/src/unix/mod.rs index f5f8d954fdadf..fae6cef059f23 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -2429,3 +2429,8 @@ cfg_if! { // Unknown target_os } } + +extern "C" { + #[cfg(not(aarch64_macos_15_5_or_newer))] + pub static mut environ: *mut *mut crate::c_char; +}