@@ -192,12 +192,14 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
192
192
"WARNING: Ignoring `RUSTC` environment variable; set `MIRI` if you want to control the binary used as the driver."
193
193
) ;
194
194
}
195
- // Build scripts (and also cargo: https://github.com/rust-lang/cargo/issues/10885) will invoke
196
- // `rustc` even when `RUSTC_WRAPPER` is set. To make sure everything is coherent, we want that
197
- // to be the Miri driver, but acting as rustc, on the target level. (Target, rather than host,
198
- // is needed for cross-interpretation situations.) This is not a perfect emulation of real rustc
199
- // (it might be unable to produce binaries since the sysroot is check-only), but it's as close
200
- // as we can get, and it's good enough for autocfg.
195
+ // Ideally we would set RUSTC to some non-existent path, so we can be sure our wrapping is
196
+ // always applied. However, buggy build scripts (https://github.com/eyre-rs/eyre/issues/84) and
197
+ // also cargo (https://github.com/rust-lang/cargo/issues/10885) will invoke `rustc` even when
198
+ // `RUSTC_WRAPPER` is set, bypassing the wrapper. To make sure everything is coherent, we want
199
+ // that to be the Miri driver, but acting as rustc, on the target level. (Target, rather than
200
+ // host, is needed for cross-interpretation situations.) This is not a perfect emulation of real
201
+ // rustc (it might be unable to produce binaries since the sysroot is check-only), but it's as
202
+ // close as we can get, and it's good enough for autocfg.
201
203
//
202
204
// In `main`, we need the value of `RUSTC` to distinguish RUSTC_WRAPPER invocations from rustdoc
203
205
// or TARGET_RUNNER invocations, so we canonicalize it here to make it exceedingly unlikely that
@@ -251,6 +253,16 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
251
253
/// Cargo does not give us this information directly, so we need to check
252
254
/// various command-line flags.
253
255
fn is_runnable_crate ( ) -> bool {
256
+ // Determine whether this is cargo invoking rustc to get some infos. Ideally we'd check "is
257
+ // there a filename passed to rustc", but that's very hard as we would have to know whether
258
+ // e.g. `--print foo` is a booolean flag `--print` followed by filename `foo` or equivalent
259
+ // to `--print=foo`. So instead we use this more fragile approach of detecting the presence
260
+ // of a "query" flag rather than the absence of a filename.
261
+ let info_query = get_arg_flag_value ( "--print" ) . is_some ( ) || has_arg_flag ( "-vV" ) ;
262
+ if info_query {
263
+ // Nothing to run.
264
+ return false ;
265
+ }
254
266
let is_bin = get_arg_flag_value ( "--crate-type" ) . as_deref ( ) . unwrap_or ( "bin" ) == "bin" ;
255
267
let is_test = has_arg_flag ( "--test" ) ;
256
268
is_bin || is_test
@@ -297,8 +309,6 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
297
309
let verbose = std:: env:: var ( "MIRI_VERBOSE" )
298
310
. map_or ( 0 , |verbose| verbose. parse ( ) . expect ( "verbosity flag must be an integer" ) ) ;
299
311
let target_crate = is_target_crate ( ) ;
300
- // Determine whether this is cargo invoking rustc to get some infos.
301
- let info_query = get_arg_flag_value ( "--print" ) . is_some ( ) || has_arg_flag ( "-vV" ) ;
302
312
303
313
let store_json = |info : CrateRunInfo | {
304
314
if get_arg_flag_value ( "--emit" ) . unwrap_or_default ( ) . split ( ',' ) . any ( |e| e == "dep-info" ) {
@@ -325,7 +335,7 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
325
335
}
326
336
} ;
327
337
328
- let runnable_crate = !info_query && is_runnable_crate ( ) ;
338
+ let runnable_crate = is_runnable_crate ( ) ;
329
339
330
340
if runnable_crate && target_crate {
331
341
assert ! (
@@ -399,7 +409,7 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
399
409
let mut emit_link_hack = false ;
400
410
// Arguments are treated very differently depending on whether this crate is
401
411
// for interpretation by Miri, or for use by a build script / proc macro.
402
- if !info_query && target_crate {
412
+ if target_crate {
403
413
// Forward arguments, but remove "link" from "--emit" to make this a check-only build.
404
414
let emit_flag = "--emit" ;
405
415
while let Some ( arg) = args. next ( ) {
@@ -433,17 +443,14 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
433
443
cmd. arg ( "-C" ) . arg ( "panic=abort" ) ;
434
444
}
435
445
} else {
436
- // For host crates (but not when we are just printing some info),
437
- // we might still have to set the sysroot.
438
- if !info_query {
439
- // When we're running `cargo-miri` from `x.py` we need to pass the sysroot explicitly
440
- // due to bootstrap complications.
441
- if let Some ( sysroot) = std:: env:: var_os ( "MIRI_HOST_SYSROOT" ) {
442
- cmd. arg ( "--sysroot" ) . arg ( sysroot) ;
443
- }
446
+ // This is a host crate.
447
+ // When we're running `cargo-miri` from `x.py` we need to pass the sysroot explicitly
448
+ // due to bootstrap complications.
449
+ if let Some ( sysroot) = std:: env:: var_os ( "MIRI_HOST_SYSROOT" ) {
450
+ cmd. arg ( "--sysroot" ) . arg ( sysroot) ;
444
451
}
445
452
446
- // For host crates or when we are printing, just forward everything.
453
+ // Forward everything.
447
454
cmd. args ( args) ;
448
455
}
449
456
@@ -455,9 +462,7 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
455
462
456
463
// Run it.
457
464
if verbose > 0 {
458
- eprintln ! (
459
- "[cargo-miri rustc] target_crate={target_crate} runnable_crate={runnable_crate} info_query={info_query}"
460
- ) ;
465
+ eprintln ! ( "[cargo-miri rustc] target_crate={target_crate} runnable_crate={runnable_crate}" ) ;
461
466
}
462
467
463
468
// Create a stub .rlib file if "link" was requested by cargo.
@@ -546,15 +551,13 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
546
551
// but when we run here, cargo does not interpret the JSON any more. `--json`
547
552
// then also needs to be dropped.
548
553
let mut args = info. args . into_iter ( ) ;
549
- let error_format_flag = "--error-format" ;
550
- let json_flag = "--json" ;
551
554
while let Some ( arg) = args. next ( ) {
552
555
if arg == "--extern" {
553
556
forward_patched_extern_arg ( & mut args, & mut cmd) ;
554
- } else if let Some ( suffix) = arg. strip_prefix ( error_format_flag ) {
557
+ } else if let Some ( suffix) = arg. strip_prefix ( "--error-format" ) {
555
558
assert ! ( suffix. starts_with( '=' ) ) ;
556
559
// Drop this argument.
557
- } else if let Some ( suffix) = arg. strip_prefix ( json_flag ) {
560
+ } else if let Some ( suffix) = arg. strip_prefix ( "--json" ) {
558
561
assert ! ( suffix. starts_with( '=' ) ) ;
559
562
// Drop this argument.
560
563
} else {
@@ -592,13 +595,11 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
592
595
// just default to a straight-forward invocation for now:
593
596
let mut cmd = Command :: new ( "rustdoc" ) ;
594
597
595
- let extern_flag = "--extern" ;
596
- let runtool_flag = "--runtool" ;
597
598
while let Some ( arg) = args. next ( ) {
598
- if arg == extern_flag {
599
+ if arg == "--extern" {
599
600
// Patch --extern arguments to use *.rmeta files, since phase_cargo_rustc only creates stub *.rlib files.
600
601
forward_patched_extern_arg ( & mut args, & mut cmd) ;
601
- } else if arg == runtool_flag {
602
+ } else if arg == "--runtool" {
602
603
// An existing --runtool flag indicates cargo is running in cross-target mode, which we don't support.
603
604
// Note that this is only passed when cargo is run with the unstable -Zdoctest-xcompile flag;
604
605
// otherwise, we won't be called as rustdoc at all.
0 commit comments