From 10a8a75a0817d51642fe60a398aaf21932af94ca Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 21 Apr 2024 15:58:02 +0900 Subject: [PATCH] Respect RUSTC_WRAPPER in rustc version detection --- .cirrus.yml | 1 + .github/workflows/ci.yml | 3 ++- build.rs | 6 ++++++ portable-atomic-util/build.rs | 3 +++ tools/build.sh | 1 + tools/fuchsia-test.sh | 1 + tools/no-std.sh | 1 + tools/test.sh | 1 + version.rs | 16 ++++++++++++++-- 9 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 89997775..9cdac323 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -9,6 +9,7 @@ env: RUSTDOCFLAGS: -D warnings RUSTFLAGS: -D warnings RUSTUP_MAX_RETRIES: '10' + PORTABLE_ATOMIC_DENY_WARNINGS: '1' aarch64_linux_test_task: name: test ($TARGET) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dad01e65..77d5074e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,7 @@ env: RUSTDOCFLAGS: -D warnings RUSTFLAGS: -D warnings RUSTUP_MAX_RETRIES: 10 + PORTABLE_ATOMIC_DENY_WARNINGS: 1 # NB: sync with: # - docs.rs metadata in Cargo.toml # - test_features list in tools/build.sh and tools/test.sh. @@ -380,7 +381,7 @@ jobs: - uses: taiki-e/checkout-action@v1 - uses: taiki-e/cross-platform-actions-action@neoverse-v1 with: - environment_variables: CARGO_INCREMENTAL CARGO_NET_RETRY CARGO_TERM_COLOR RUST_BACKTRACE RUST_TEST_THREADS RUSTDOCFLAGS RUSTFLAGS RUSTUP_MAX_RETRIES TEST_FEATURES + environment_variables: CARGO_INCREMENTAL CARGO_NET_RETRY CARGO_TERM_COLOR RUST_BACKTRACE RUST_TEST_THREADS RUSTDOCFLAGS RUSTFLAGS RUSTUP_MAX_RETRIES PORTABLE_ATOMIC_DENY_WARNINGS TEST_FEATURES operating_system: ${{ matrix.os }} # We don't test x86_64 here because there is no OS-specific code on x86_64. architecture: aarch64 diff --git a/build.rs b/build.rs index 9a3822ad..a119766e 100644 --- a/build.rs +++ b/build.rs @@ -36,6 +36,9 @@ fn main() { let version = match rustc_version() { Some(version) => version, None => { + if env::var_os("PORTABLE_ATOMIC_DENY_WARNINGS").unwrap_or_default() == "1" { + panic!("unable to determine rustc version") + } println!( "cargo:warning={}: unable to determine rustc version; assuming latest stable rustc (1.{})", env!("CARGO_PKG_NAME"), @@ -261,6 +264,9 @@ fn main() { "v4t" | "v5te" => {} _ => { known = false; + if env::var_os("PORTABLE_ATOMIC_DENY_WARNINGS").unwrap_or_default() == "1" { + panic!("unrecognized arm subarch: {}", target) + } println!( "cargo:warning={}: unrecognized arm subarch: {}", env!("CARGO_PKG_NAME"), diff --git a/portable-atomic-util/build.rs b/portable-atomic-util/build.rs index da703408..ccc6349e 100644 --- a/portable-atomic-util/build.rs +++ b/portable-atomic-util/build.rs @@ -17,6 +17,9 @@ fn main() { let version = match rustc_version() { Some(version) => version, None => { + if env::var_os("PORTABLE_ATOMIC_DENY_WARNINGS").unwrap_or_default() == "1" { + panic!("unable to determine rustc version") + } println!( "cargo:warning={}: unable to determine rustc version; assuming latest stable rustc (1.{})", env!("CARGO_PKG_NAME"), diff --git a/tools/build.sh b/tools/build.sh index 7c149a64..8f20b9f6 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -247,6 +247,7 @@ if [[ "${rustc_version}" == *"nightly"* ]] || [[ "${rustc_version}" == *"dev"* ] fi fi export CARGO_TARGET_DIR="${target_dir}" +export PORTABLE_ATOMIC_DENY_WARNINGS=1 has_asm='' # asm! requires 1.59 diff --git a/tools/fuchsia-test.sh b/tools/fuchsia-test.sh index 6da23819..fddfd7f4 100755 --- a/tools/fuchsia-test.sh +++ b/tools/fuchsia-test.sh @@ -57,6 +57,7 @@ case "${1:-}" in esac target="$1-unknown-fuchsia" shift +export PORTABLE_ATOMIC_DENY_WARNINGS=1 cargo_options=() rest_cargo_options=(--test-threads=1) diff --git a/tools/no-std.sh b/tools/no-std.sh index ec304564..07f8e5a1 100755 --- a/tools/no-std.sh +++ b/tools/no-std.sh @@ -99,6 +99,7 @@ if [[ "${rustc_version}" == *"nightly"* ]] || [[ "${rustc_version}" == *"dev"* ] fi fi export QEMU_AUDIO_DRV=none +export PORTABLE_ATOMIC_DENY_WARNINGS=1 run() { local target="$1" diff --git a/tools/test.sh b/tools/test.sh index ea0f3380..f7b93c92 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -143,6 +143,7 @@ if [[ "${rustc_version}" == *"nightly"* ]] || [[ "${rustc_version}" == *"dev"* ] fi fi export RUST_TEST_THREADS=1 +export PORTABLE_ATOMIC_DENY_WARNINGS=1 if [[ -n "${CI:-}" ]]; then if type -P ts &>/dev/null; then TS=ts diff --git a/version.rs b/version.rs index 748498d6..1f03ce01 100644 --- a/version.rs +++ b/version.rs @@ -1,11 +1,23 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT -use std::{env, process::Command, str}; +use std::{env, iter, process::Command, str}; pub(crate) fn rustc_version() -> Option { let rustc = env::var_os("RUSTC")?; + let rustc_wrapper = if env::var_os("CARGO_ENCODED_RUSTFLAGS").is_some() { + env::var_os("RUSTC_WRAPPER").filter(|v| !v.is_empty()) + } else { + // Cargo sets environment variables for wrappers correctly only since https://github.com/rust-lang/cargo/pull/9601. + None + }; + // Do not apply RUSTC_WORKSPACE_WRAPPER: https://github.com/cuviper/autocfg/issues/58#issuecomment-2067625980 + let mut rustc = rustc_wrapper.into_iter().chain(iter::once(rustc)); + let mut cmd = Command::new(rustc.next().unwrap()); + cmd.args(rustc); // Use verbose version output because the packagers add extra strings to the normal version output. - let output = Command::new(rustc).args(&["--version", "--verbose"]).output().ok()?; + // Do not use long flags (--version --verbose) because clippy-deriver doesn't handle them properly. + // -vV is also matched with that cargo internally uses: https://github.com/rust-lang/cargo/blob/14b46ecc62aa671d7477beba237ad9c6a209cf5d/src/cargo/util/rustc.rs#L65 + let output = cmd.arg("-vV").output().ok()?; let verbose_version = str::from_utf8(&output.stdout).ok()?; Version::parse(verbose_version) }