Skip to content

Commit c461170

Browse files
committed
Auto merge of rust-lang#3413 - RalfJung:cargo-miri-misc, r=RalfJung
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.
2 parents cf172a8 + 98e1cbb commit c461170

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/tools/miri/cargo-miri/src/main.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ use std::{env, iter};
1111

1212
use crate::phases::*;
1313

14+
/// Returns `true` if our flags look like they may be for rustdoc, i.e., this is cargo calling us to
15+
/// be rustdoc. It's hard to be sure as cargo does not have a RUSTDOC_WRAPPER or an env var that
16+
/// would let us get a clear signal.
17+
fn looks_like_rustdoc() -> bool {
18+
// The `--test-run-directory` flag only exists for rustdoc and cargo always passes it. Perfect!
19+
env::args().any(|arg| arg == "--test-run-directory")
20+
}
21+
1422
fn main() {
1523
// Rustc does not support non-UTF-8 arguments so we make no attempt either.
1624
// (We do support non-UTF-8 environment variables though.)
17-
let mut args = std::env::args();
25+
let mut args = env::args();
1826
// Skip binary name.
1927
args.next().unwrap();
2028

@@ -91,10 +99,16 @@ fn main() {
9199
// (see https://github.com/rust-lang/cargo/issues/10886).
92100
phase_rustc(args, RustcPhase::Build)
93101
}
94-
_ => {
95-
// Everything else must be rustdoc. But we need to get `first` "back onto the iterator",
102+
_ if looks_like_rustdoc() => {
103+
// This is probably rustdoc. But we need to get `first` "back onto the iterator",
96104
// it is some part of the rustdoc invocation.
97105
phase_rustdoc(iter::once(first).chain(args));
98106
}
107+
_ => {
108+
show_error!(
109+
"`cargo-miri` failed to recognize which phase of the build process this is, please report a bug.\nThe command-line arguments were: {:#?}",
110+
Vec::from_iter(env::args()),
111+
);
112+
}
99113
}
100114
}

src/tools/miri/cargo-miri/src/phases.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
620620

621621
// The `--test-builder` and `--runtool` arguments are unstable rustdoc features,
622622
// which are disabled by default. We first need to enable them explicitly:
623-
cmd.arg("-Z").arg("unstable-options");
623+
cmd.arg("-Zunstable-options");
624624

625625
// rustdoc needs to know the right sysroot.
626626
cmd.arg("--sysroot").arg(env::var_os("MIRI_SYSROOT").unwrap());

src/tools/miri/test-cargo-miri/Cargo.lock

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# It is not intended for manual editing.
33
version = 3
44

5+
[[package]]
6+
name = "anyhow"
7+
version = "1.0.81"
8+
source = "registry+https://github.com/rust-lang/crates.io-index"
9+
checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247"
10+
511
[[package]]
612
name = "autocfg"
713
version = "1.1.0"
@@ -24,6 +30,7 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
2430
name = "cargo-miri-test"
2531
version = "0.1.0"
2632
dependencies = [
33+
"anyhow",
2734
"autocfg",
2835
"byteorder 0.5.3",
2936
"byteorder 1.4.3",

src/tools/miri/test-cargo-miri/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ issue_rust_86261 = { path = "issue-rust-86261" }
2222
byteorder_2 = { package = "byteorder", version = "0.5" } # to test dev-dependencies behave as expected, with renaming
2323
# Not actually used, but exercises some unique code path (`--extern` .so file).
2424
serde_derive = "1.0.185"
25+
# Not actually used, but uses a custom build probe so let's make sure that works.
26+
# (Ideally we'd check if the probe was successful, but that's not easily possible.)
27+
anyhow = "1.0"
2528

2629
[build-dependencies]
2730
autocfg = "1"

0 commit comments

Comments
 (0)