diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 91c1d7a37593..b9159c0ee226 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -186,30 +186,30 @@ jobs: - target: aarch64-linux-android - target: aarch64-unknown-linux-musl - target: aarch64-unknown-linux-musl - env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 } + env: { TEST_MUSL_V1_2_3: 1 } artifact-tag: new-musl - target: arm-linux-androideabi - target: arm-unknown-linux-gnueabihf - target: arm-unknown-linux-musleabihf - target: arm-unknown-linux-musleabihf - env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 } + env: { TEST_MUSL_V1_2_3: 1 } artifact-tag: new-musl # FIXME(#4297): Disabled due to spurious failue # - target: i686-linux-android - target: i686-unknown-linux-musl - target: i686-unknown-linux-musl - env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 } + env: { TEST_MUSL_V1_2_3: 1 } artifact-tag: new-musl - target: loongarch64-unknown-linux-gnu - target: loongarch64-unknown-linux-musl - target: loongarch64-unknown-linux-musl - env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 } + env: { TEST_MUSL_V1_2_3: 1 } artifact-tag: new-musl - target: powerpc64-unknown-linux-gnu - target: powerpc64le-unknown-linux-gnu - target: powerpc64le-unknown-linux-musl - target: powerpc64le-unknown-linux-musl - env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 } + env: { TEST_MUSL_V1_2_3: 1 } artifact-tag: new-musl - target: riscv64gc-unknown-linux-gnu - target: s390x-unknown-linux-gnu @@ -223,7 +223,7 @@ jobs: # - target: x86_64-unknown-linux-gnux32 - target: x86_64-unknown-linux-musl - target: x86_64-unknown-linux-musl - env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 } + env: { TEST_MUSL_V1_2_3: 1 } artifact-tag: new-musl # FIXME: It seems some items in `src/unix/mod.rs` aren't defined on redox actually. # - target: x86_64-unknown-redox diff --git a/build.rs b/build.rs index cbebca6207f2..0a016899c3bf 100644 --- a/build.rs +++ b/build.rs @@ -70,9 +70,8 @@ fn main() { // // On CI, we detect the actual FreeBSD version and match its ABI exactly, // running tests to ensure that the ABI is correct. - println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_FREEBSD_VERSION"); // Allow overriding the default version for testing - let which_freebsd = if let Ok(version) = env::var("RUST_LIBC_UNSTABLE_FREEBSD_VERSION") { + let which_freebsd = if let Ok(version) = env::var("CARGO_CFG_LIBC_UNSTABLE_FREEBSD_VERSION") { let vers = version.parse().unwrap(); println!("cargo:warning=setting FreeBSD version to {vers}"); vers @@ -104,8 +103,7 @@ fn main() { _ => (), } - let mut musl_v1_2_3 = env_flag("RUST_LIBC_UNSTABLE_MUSL_V1_2_3"); - println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_MUSL_V1_2_3"); + let mut musl_v1_2_3 = env_flag("CARGO_CFG_LIBC_UNSTABLE_MUSL_V1_2_3"); // OpenHarmony uses a fork of the musl libc let musl = target_env == "musl" || target_env == "ohos"; @@ -123,13 +121,6 @@ fn main() { } } - let linux_time_bits64 = env::var("RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64").is_ok(); - println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64"); - if linux_time_bits64 { - set_cfg("linux_time_bits64"); - } - println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"); - println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_TIME_BITS"); if target_env == "gnu" && target_os == "linux" && target_ptr_width == "32" @@ -138,25 +129,33 @@ fn main() { { let defaultbits = "32".to_string(); let (timebits, filebits) = match ( - env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS"), - env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"), + env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS"), + env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"), ) { - (Ok(_), Ok(_)) => panic!("Do not set both RUST_LIBC_UNSTABLE_GNU_TIME_BITS and RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"), + (Ok(_), Ok(_)) => panic!( + "Do not set both `libc_unstable_gnu_time_bits` and \ + `libc_unstable_gnu_file_offset_bits`" + ), (Err(_), Err(_)) => (defaultbits.clone(), defaultbits.clone()), (Ok(tb), Err(_)) if tb == "64" => (tb.clone(), tb.clone()), (Ok(tb), Err(_)) if tb == "32" => (tb, defaultbits.clone()), - (Ok(_), Err(_)) => panic!("Invalid value for RUST_LIBC_UNSTABLE_GNU_TIME_BITS, must be 32 or 64"), + (Ok(_), Err(_)) => { + panic!("Invalid value for libc_unstable_gnu_time_bits, must be 32 or 64") + } (Err(_), Ok(fb)) if fb == "32" || fb == "64" => (defaultbits.clone(), fb), - (Err(_), Ok(_)) => panic!("Invalid value for RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS, must be 32 or 64"), + (Err(_), Ok(_)) => { + panic!("Invalid value for `libc_unstable_gnu_file_offset_bits`, must be 32 or 64") + } }; let valid_bits = ["32", "64"]; assert!( valid_bits.contains(&filebits.as_str()) && valid_bits.contains(&timebits.as_str()), - "Invalid value for RUST_LIBC_UNSTABLE_GNU_TIME_BITS or RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS, must be 32, 64 or unset" + "Invalid value for `libc_unstable_gnu_time_bits` or `libc_unstable_gnu_file_offset_bits`, \ + must be 32, 64 or unset" ); assert!( !(filebits == "32" && timebits == "64"), - "RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS must be 64 or unset if RUST_LIBC_UNSTABLE_GNU_TIME_BITS is 64" + "`libc_unstable_gnu_file_offset_bits` must be 64 or unset if `libc_unstable_gnu_time_bits` is 64" ); if timebits == "64" { set_cfg("linux_time_bits64"); diff --git a/ci/run-docker.sh b/ci/run-docker.sh index 838ba10543a7..47c1e7213e60 100755 --- a/ci/run-docker.sh +++ b/ci/run-docker.sh @@ -37,7 +37,8 @@ run() { ) if [[ "$run_target" = *"musl"* ]]; then - if [ -n "${RUST_LIBC_UNSTABLE_MUSL_V1_2_3:-}" ]; then + if [ -n "${TEST_MUSL_V1_2_3:-}" ]; then + export RUSTFLAGS="$RUSTFLAGS libc_unstable_musl_v1_2_3" build_args+=("--build-arg=MUSL_VERSION=new") else build_args+=("--build-arg=MUSL_VERSION=old") @@ -62,9 +63,6 @@ run() { --env RUSTFLAGS \ --env RUSTDOCFLAGS \ --env RUST_BACKTRACE \ - --env RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS \ - --env RUST_LIBC_UNSTABLE_GNU_TIME_BITS \ - --env RUST_LIBC_UNSTABLE_MUSL_V1_2_3 \ --env CARGO_TERM_COLOR \ --env CARGO_TERM_VERBOSE \ --env CARGO_HOME=/cargo \ diff --git a/ci/run.sh b/ci/run.sh index 96e5750945df..f44a461c3fd1 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -51,7 +51,7 @@ $cmd --features extra_traits -- $test_flags if [ "$env" = "gnu" ] && [ "$bits" = "32" ]; then # shellcheck disable=SC2086 - RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS=64 $cmd -- $test_flags + RUSTFLAGS="$RUSTFLAGS libc_unstable_gnu_file_offset_bits='64'" $cmd -- $test_flags # shellcheck disable=SC2086 - RUST_LIBC_UNSTABLE_GNU_TIME_BITS=64 $cmd -- $test_flags + RUSTFLAGS="$RUSTFLAGS libc_unstable_gnu_time_bits='64'" $cmd -- $test_flags fi diff --git a/ci/verify-build.py b/ci/verify-build.py index 831c1cdb3d3e..fa4f0dc500e3 100755 --- a/ci/verify-build.py +++ b/ci/verify-build.py @@ -242,8 +242,15 @@ def run( args: Sequence[str | Path], *, env: Optional[dict[str, str]] = None, + extra_rustflags: Optional[str] = None, check: bool = True, ) -> sp.CompletedProcess: + if env is None: + env = os.environ.copy() + + if extra_rustflags is not None: + env["RUSTFLAGS"] = env.get("RUSTFLAGS", "") + " " + extra_rustflags + xtrace(args, env=env) return sp.run(args, env=env, check=check) @@ -358,7 +365,7 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult: """Run tests for a single target.""" start = time.time() env = os.environ.copy() - env.setdefault("RUSTFLAGS", "") + rustflags = "" tname = target.name target_cfg = check_output(["rustc", "--print=cfg", "--target", tname]) @@ -383,7 +390,7 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult: cmd += ["-Zbuild-std=core"] # FIXME: With `the build-std` feature, `compiler_builtins` emits a lot of # lint warnings. - env["RUSTFLAGS"] += " -Aimproper_ctypes_definitions" + rustflags += " -Aimproper_ctypes_definitions" else: run(["rustup", "target", "add", tname, "--toolchain", cfg.toolchain_name]) @@ -393,13 +400,16 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult: if "gnu" in target_env and target_bits == "32": # Equivalent of _FILE_OFFSET_BITS=64 - run(cmd, env=env | {"RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS": "64"}) + run( + cmd, + extra_rustflags=rustflags + " libc_unstable_gnu_file_offset_bits='64'", + ) # Equivalent of _TIME_BITS=64 - run(cmd, env=env | {"RUST_LIBC_UNSTABLE_GNU_TIME_BITS": "64"}) + run(cmd, extra_rustflags=rustflags + " libc_unstable_gnu_time_bits='64'") if "musl" in target_env: # Check with breaking changes from musl, including 64-bit time_t on 32-bit - run(cmd, env=env | {"RUST_LIBC_UNSTABLE_MUSL_V1_2_3": "1"}) + run(cmd, extra_rustflags=rustflags + " libc_unstable_musl_v1_2_3") # Test again without default features, i.e. without `std` run([*cmd, "--no-default-features"]) @@ -413,10 +423,16 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult: # if on nightly or stable if "freebsd" in tname and cfg.toolchain >= Toolchain.STABLE: for version in FREEBSD_VERSIONS: - run(cmd, env=env | {"RUST_LIBC_UNSTABLE_FREEBSD_VERSION": str(version)}) + + run( + cmd, + extra_rustflags=rustflags + + f" libc_unstable_freebsd_version = '{str(version)}'", + ) run( [*cmd, "--no-default-features"], - env=env | {"RUST_LIBC_UNSTABLE_FREEBSD_VERSION": str(version)}, + extra_rustflags=rustflags + + f" libc_unstable_freebsd_version = '{str(version)}'", ) if cfg.skip_semver: diff --git a/libc-test/build.rs b/libc-test/build.rs index 1cbacfde9d97..c8f0a8c0697e 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2275,7 +2275,7 @@ fn test_freebsd(target: &str) { assert!(target.contains("freebsd")); let mut cfg = ctest_cfg(); - let freebsd_ver = if let Ok(version) = env::var("RUST_LIBC_UNSTABLE_FREEBSD_VERSION") { + let freebsd_ver = if let Ok(version) = env::var("CARGO_CFG_LIBC_UNSTABLE_FREEBSD_VERSION") { let vers = version.parse().unwrap(); println!("cargo:warning=setting FreeBSD version to {vers}"); Some(vers) @@ -3607,25 +3607,33 @@ fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) { { let defaultbits = "32".to_string(); let (timebits, filebits) = match ( - env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS"), - env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"), + env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS"), + env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"), ) { - (Ok(_), Ok(_)) => panic!("Do not set both RUST_LIBC_UNSTABLE_GNU_TIME_BITS and RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"), + (Ok(_), Ok(_)) => panic!( + "Do not set both `libc_unstable_gnu_time_bits` and \ + `libc_unstable_gnu_file_offset_bits`" + ), (Err(_), Err(_)) => (defaultbits.clone(), defaultbits.clone()), (Ok(tb), Err(_)) if tb == "64" => (tb.clone(), tb.clone()), (Ok(tb), Err(_)) if tb == "32" => (tb, defaultbits.clone()), - (Ok(_), Err(_)) => panic!("Invalid value for RUST_LIBC_UNSTABLE_GNU_TIME_BITS, must be 32 or 64"), + (Ok(_), Err(_)) => { + panic!("Invalid value for libc_unstable_gnu_time_bits, must be 32 or 64") + } (Err(_), Ok(fb)) if fb == "32" || fb == "64" => (defaultbits.clone(), fb), - (Err(_), Ok(_)) => panic!("Invalid value for RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS, must be 32 or 64"), + (Err(_), Ok(_)) => { + panic!("Invalid value for `libc_unstable_gnu_file_offset_bits`, must be 32 or 64") + } }; let valid_bits = ["32", "64"]; assert!( valid_bits.contains(&filebits.as_str()) && valid_bits.contains(&timebits.as_str()), - "Invalid value for RUST_LIBC_UNSTABLE_GNU_TIME_BITS or RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS, must be 32, 64 or unset" + "Invalid value for `libc_unstable_gnu_time_bits` or `libc_unstable_gnu_file_offset_bits`, \ + must be 32, 64 or unset" ); assert!( !(filebits == "32" && timebits == "64"), - "RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS must be 64 or unset if RUST_LIBC_UNSTABLE_GNU_TIME_BITS is 64" + "`libc_unstable_gnu_file_offset_bits` must be 64 or unset if `libc_unstable_gnu_time_bits` is 64" ); if timebits == "64" { cfg.define("_TIME_BITS", Some("64")); @@ -3692,7 +3700,7 @@ fn test_linux(target: &str) { let mips64 = target.contains("mips64"); let mips32 = mips && !mips64; - let musl_v1_2_3 = env::var("RUST_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok(); + let musl_v1_2_3 = env::var("CARGO_CFG_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok(); if musl_v1_2_3 { assert!(musl); }