From 828d41f7b91287f2242ed657cd5d42ca3a09e8bd Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 11 Jan 2025 19:42:26 +0100 Subject: [PATCH 1/2] adjust the way we build miri-script in RA, to fix proc-macros --- etc/rust_analyzer_vscode.json | 10 ++++------ miri | 10 +++++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/etc/rust_analyzer_vscode.json b/etc/rust_analyzer_vscode.json index 5e51c3e888..c646953e92 100644 --- a/etc/rust_analyzer_vscode.json +++ b/etc/rust_analyzer_vscode.json @@ -5,21 +5,19 @@ "cargo-miri/Cargo.toml", "miri-script/Cargo.toml", ], - "rust-analyzer.check.invocationLocation": "root", "rust-analyzer.check.invocationStrategy": "once", "rust-analyzer.check.overrideCommand": [ - "env", - "MIRI_AUTO_OPS=no", "./miri", "clippy", // make this `check` when working with a locally built rustc "--message-format=json", ], + "rust-analyzer.cargo.extraEnv": { + "MIRI_AUTO_OPS": "no", + "MIRI_IN_RA": "1", + }, // Contrary to what the name suggests, this also affects proc macros. - "rust-analyzer.cargo.buildScripts.invocationLocation": "root", "rust-analyzer.cargo.buildScripts.invocationStrategy": "once", "rust-analyzer.cargo.buildScripts.overrideCommand": [ - "env", - "MIRI_AUTO_OPS=no", "./miri", "check", "--message-format=json", diff --git a/miri b/miri index ac1a7211c4..b1b146d799 100755 --- a/miri +++ b/miri @@ -3,12 +3,16 @@ set -e # We want to call the binary directly, so we need to know where it ends up. ROOT_DIR="$(dirname "$0")" MIRI_SCRIPT_TARGET_DIR="$ROOT_DIR"/miri-script/target -# If stdout is not a terminal and we are not on CI, assume that we are being invoked by RA, and use JSON output. -if ! [ -t 1 ] && [ -z "$CI" ]; then +TOOLCHAIN="+nightly" +# If we are being invoked for RA, use JSON output and the default toolchain (to make proc-macros +# work in RA). This needs a different target dir to avoid mixing up the builds. +if [ -n "$MIRI_IN_RA" ]; then MESSAGE_FORMAT="--message-format=json" + TOOLCHAIN="" + MIRI_SCRIPT_TARGET_DIR="$MIRI_SCRIPT_TARGET_DIR"/ra fi # We need a nightly toolchain, for `-Zroot-dir`. -cargo +nightly build $CARGO_EXTRA_FLAGS --manifest-path "$ROOT_DIR"/miri-script/Cargo.toml \ +cargo $TOOLCHAIN build $CARGO_EXTRA_FLAGS --manifest-path "$ROOT_DIR"/miri-script/Cargo.toml \ -Zroot-dir="$ROOT_DIR" \ -q --target-dir "$MIRI_SCRIPT_TARGET_DIR" $MESSAGE_FORMAT || \ ( echo "Failed to build miri-script. Is the 'nightly' toolchain installed?"; exit 1 ) From 937019775155aecc91eb4b9bae488a54a7a89f80 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 11 Jan 2025 19:42:47 +0100 Subject: [PATCH 2/2] avoid issues due to MIRI_TEST_TARGET being set from the outside --- miri-script/src/commands.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/miri-script/src/commands.rs b/miri-script/src/commands.rs index be2517aa6d..17a7c06b52 100644 --- a/miri-script/src/commands.rs +++ b/miri-script/src/commands.rs @@ -564,6 +564,10 @@ impl Command { if bless { e.sh.set_var("RUSTC_BLESS", "Gesundheit"); } + if e.sh.var("MIRI_TEST_TARGET").is_ok() { + // Avoid trouble due to an incorrectly set env var. + bail!("MIRI_TEST_TARGET must not be set when invoking `./miri test`"); + } if let Some(target) = target { // Tell the harness which target to test. e.sh.set_var("MIRI_TEST_TARGET", target);