diff --git a/build.rs b/build.rs index 8aab1330d3e8..3845ad1d3ede 100644 --- a/build.rs +++ b/build.rs @@ -40,6 +40,9 @@ const ALLOWED_CFGS: &[&str] = &[ "musl_redir_time64", "vxworks_lt_25_09", "libc_pauthtest", + // Global flag to enable one of `linux_time_bits64` or `gnu_time_bits64`. + // The musl flags are enabled by default on supported platforms. + "time64", ]; // Extra values to allow for check-cfg. @@ -169,6 +172,9 @@ fn main() { // OpenHarmony uses a fork of the musl libc let musl = target_env == "musl" || target_env == "ohos"; + // Single entry-point to enable `time64` on supported platforms. + let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); + // loongarch64, hexagon, ohos and pauthtest only exist with recent musl if target_arch == "loongarch64" || target_arch == "hexagon" @@ -190,7 +196,7 @@ fn main() { } let uclibc_use_time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64"); - if target_env == "uclibc" && uclibc_use_time64 { + if target_env == "uclibc" && (uclibc_use_time64 || time64) { set_cfg("linux_time_bits64"); } @@ -230,7 +236,7 @@ fn main() { } }; - if timebits == "64" { + if timebits == "64" || time64 { set_cfg("linux_time_bits64"); set_cfg("gnu_file_offset_bits64"); set_cfg("gnu_time_bits64"); diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs index fc05c0df16c1..93afdfdd0904 100755 --- a/libc-test/build/main.rs +++ b/libc-test/build/main.rs @@ -724,6 +724,7 @@ fn test_windows(t: &Target) { } cfg.define("_WIN32_WINNT", Some("0x8000")); + let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); let win_gnu_x86_time64 = match env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS") { Ok(v) if v == "64" => true, Ok(v) if v == "32" => false, @@ -736,7 +737,7 @@ fn test_windows(t: &Target) { // Needed for the Windows `time_t` test. println!("cargo::rustc-check-cfg=cfg(gnu_time_bits64)"); - if x86_32 && gnu && win_gnu_x86_time64 { + if x86_32 && gnu && (win_gnu_x86_time64 || time64) { cfg.cfg("gnu_time_bits64", None); println!("cargo::rustc-cfg=gnu_time_bits64"); } @@ -3830,6 +3831,7 @@ fn config_gnu_bits(t: &Target, cfg: &mut ctest::TestGenerator) { if t.gnu() && t.linux() && !t.x32() && !t.riscv32() && t.pointer_width == P32 { let defaultbits = "32"; let mut tb_env = env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS"); + let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); // FIXME: remove these fallbacks in a few releases if let Ok(old_tb_env) = env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS") { @@ -3858,7 +3860,7 @@ fn config_gnu_bits(t: &Target, cfg: &mut ctest::TestGenerator) { } }; - if timebits == "64" { + if timebits == "64" || time64 { cfg.define("_TIME_BITS", Some("64")); cfg.define("_FILE_OFFSET_BITS", Some("64")); cfg.cfg("linux_time_bits64", None); @@ -3923,6 +3925,8 @@ fn test_linux(t: &Target) { None => panic!("failed to detect kernel version for Linux target {t:?}",), }; + let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); + let mut musl_v1_2 = env_flag("CARGO_CFG_LIBC_UNSTABLE_MUSL_V1_2"); if musl_v1_2 { assert!(musl); @@ -3949,7 +3953,7 @@ fn test_linux(t: &Target) { } let uclibc_use_time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64"); - if uclibc && uclibc_use_time64 { + if uclibc && (uclibc_use_time64 || time64) { cfg.cfg("linux_time_bits64", None); } cfg.define("_GNU_SOURCE", None)