From 8afc4862d0d2b968a0f023d88eb81eef6a3701aa Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 25 Mar 2024 14:23:42 +0100 Subject: [PATCH 1/2] test-cargo-miri: test anyhow --- src/tools/miri/test-cargo-miri/Cargo.lock | 7 +++++++ src/tools/miri/test-cargo-miri/Cargo.toml | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/tools/miri/test-cargo-miri/Cargo.lock b/src/tools/miri/test-cargo-miri/Cargo.lock index d5e57a66a8d61..f75d68f4e2983 100644 --- a/src/tools/miri/test-cargo-miri/Cargo.lock +++ b/src/tools/miri/test-cargo-miri/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "anyhow" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" + [[package]] name = "autocfg" version = "1.1.0" @@ -24,6 +30,7 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" name = "cargo-miri-test" version = "0.1.0" dependencies = [ + "anyhow", "autocfg", "byteorder 0.5.3", "byteorder 1.4.3", diff --git a/src/tools/miri/test-cargo-miri/Cargo.toml b/src/tools/miri/test-cargo-miri/Cargo.toml index 1688096fd9a4b..58c451741bb50 100644 --- a/src/tools/miri/test-cargo-miri/Cargo.toml +++ b/src/tools/miri/test-cargo-miri/Cargo.toml @@ -22,6 +22,9 @@ issue_rust_86261 = { path = "issue-rust-86261" } byteorder_2 = { package = "byteorder", version = "0.5" } # to test dev-dependencies behave as expected, with renaming # Not actually used, but exercises some unique code path (`--extern` .so file). serde_derive = "1.0.185" +# Not actually used, but uses a custom build probe so let's make sure that works. +# (Ideally we'd check if the probe was successful, but that's not easily possible.) +anyhow = "1.0" [build-dependencies] autocfg = "1" From 98e1cbbc020e1a17b18fabf00a21e0fa868a1289 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 25 Mar 2024 14:38:57 +0100 Subject: [PATCH 2/2] phase_rustdoc: add a heuristic to make us more certain that this is really rustdoc --- src/tools/miri/cargo-miri/src/main.rs | 20 +++++++++++++++++--- src/tools/miri/cargo-miri/src/phases.rs | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/tools/miri/cargo-miri/src/main.rs b/src/tools/miri/cargo-miri/src/main.rs index c5fada6fe55b8..9fdd4c3e47043 100644 --- a/src/tools/miri/cargo-miri/src/main.rs +++ b/src/tools/miri/cargo-miri/src/main.rs @@ -11,10 +11,18 @@ use std::{env, iter}; use crate::phases::*; +/// Returns `true` if our flags look like they may be for rustdoc, i.e., this is cargo calling us to +/// be rustdoc. It's hard to be sure as cargo does not have a RUSTDOC_WRAPPER or an env var that +/// would let us get a clear signal. +fn looks_like_rustdoc() -> bool { + // The `--test-run-directory` flag only exists for rustdoc and cargo always passes it. Perfect! + env::args().any(|arg| arg == "--test-run-directory") +} + fn main() { // Rustc does not support non-UTF-8 arguments so we make no attempt either. // (We do support non-UTF-8 environment variables though.) - let mut args = std::env::args(); + let mut args = env::args(); // Skip binary name. args.next().unwrap(); @@ -91,10 +99,16 @@ fn main() { // (see https://github.com/rust-lang/cargo/issues/10886). phase_rustc(args, RustcPhase::Build) } - _ => { - // Everything else must be rustdoc. But we need to get `first` "back onto the iterator", + _ if looks_like_rustdoc() => { + // This is probably rustdoc. But we need to get `first` "back onto the iterator", // it is some part of the rustdoc invocation. phase_rustdoc(iter::once(first).chain(args)); } + _ => { + show_error!( + "`cargo-miri` failed to recognize which phase of the build process this is, please report a bug.\nThe command-line arguments were: {:#?}", + Vec::from_iter(env::args()), + ); + } } } diff --git a/src/tools/miri/cargo-miri/src/phases.rs b/src/tools/miri/cargo-miri/src/phases.rs index 81ff68545ccd3..e547599d954a4 100644 --- a/src/tools/miri/cargo-miri/src/phases.rs +++ b/src/tools/miri/cargo-miri/src/phases.rs @@ -620,7 +620,7 @@ pub fn phase_rustdoc(mut args: impl Iterator) { // The `--test-builder` and `--runtool` arguments are unstable rustdoc features, // which are disabled by default. We first need to enable them explicitly: - cmd.arg("-Z").arg("unstable-options"); + cmd.arg("-Zunstable-options"); // rustdoc needs to know the right sysroot. cmd.arg("--sysroot").arg(env::var_os("MIRI_SYSROOT").unwrap());