Skip to content

Commit

Permalink
Auto merge of rust-lang#3413 - RalfJung:cargo-miri-misc, r=RalfJung
Browse files Browse the repository at this point in the history
phase_rustdoc: add a heuristic to make us more certain that this is really rustdoc

Also add anyhow to test-cargo-miri; it has a custom build probe and is widely used so let's make sure the build script does not fail.
  • Loading branch information
bors committed Mar 25, 2024
2 parents cf172a8 + 98e1cbb commit c461170
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/tools/miri/cargo-miri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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()),
);
}
}
}
2 changes: 1 addition & 1 deletion src/tools/miri/cargo-miri/src/phases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {

// 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());
Expand Down
7 changes: 7 additions & 0 deletions src/tools/miri/test-cargo-miri/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/tools/miri/test-cargo-miri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c461170

Please sign in to comment.