Skip to content

Commit

Permalink
Respect RUSTC_WRAPPER in rustc version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Apr 21, 2024
1 parent 9a83e7e commit 10a8a75
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
3 changes: 3 additions & 0 deletions portable-atomic-util/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tools/fuchsia-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tools/no-std.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tools/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions version.rs
Original file line number Diff line number Diff line change
@@ -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<Version> {
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)
}
Expand Down

0 comments on commit 10a8a75

Please sign in to comment.