@@ -532,8 +532,7 @@ fn phase_cargo_rustc(args: env::Args) {
532532 fn is_runnable_crate ( ) -> bool {
533533 let is_bin = get_arg_flag_value ( "--crate-type" ) . as_deref ( ) . unwrap_or ( "bin" ) == "bin" ;
534534 let is_test = has_arg_flag ( "--test" ) ;
535- let print = get_arg_flag_value ( "--print" ) . is_some ( ) ;
536- ( is_bin || is_test) && !print
535+ is_bin || is_test
537536 }
538537
539538 fn out_filename ( prefix : & str , suffix : & str ) -> PathBuf {
@@ -552,8 +551,21 @@ fn phase_cargo_rustc(args: env::Args) {
552551
553552 let verbose = std:: env:: var_os ( "MIRI_VERBOSE" ) . is_some ( ) ;
554553 let target_crate = is_target_crate ( ) ;
554+ let print = get_arg_flag_value ( "--print" ) . is_some ( ) ; // whether this is cargo passing `--print` to get some infos
555+
556+ // rlib and cdylib are just skipped, we cannot interpret them and do not need them
557+ // for the rest of the build either.
558+ match get_arg_flag_value ( "--crate-type" ) . as_deref ( ) {
559+ Some ( "rlib" ) | Some ( "cdylib" ) => {
560+ if verbose {
561+ eprint ! ( "[cargo-miri rustc] (rlib/cdylib skipped)" ) ;
562+ }
563+ return ;
564+ }
565+ _ => { } ,
566+ }
555567
556- if target_crate && is_runnable_crate ( ) {
568+ if !print && target_crate && is_runnable_crate ( ) {
557569 // This is the binary or test crate that we want to interpret under Miri.
558570 // But we cannot run it here, as cargo invoked us as a compiler -- our stdin and stdout are not
559571 // like we want them.
@@ -577,7 +589,7 @@ fn phase_cargo_rustc(args: env::Args) {
577589 let mut emit_link_hack = false ;
578590 // Arguments are treated very differently depending on whether this crate is
579591 // for interpretation by Miri, or for use by a build script / proc macro.
580- if target_crate {
592+ if !print && target_crate {
581593 // Forward arguments, but remove "link" from "--emit" to make this a check-only build.
582594 let emit_flag = "--emit" ;
583595 for arg in args {
@@ -607,7 +619,7 @@ fn phase_cargo_rustc(args: env::Args) {
607619 cmd. arg ( "--sysroot" ) ;
608620 cmd. arg ( sysroot) ;
609621 } else {
610- // For host crates, just forward everything.
622+ // For host crates or when we are printing , just forward everything.
611623 cmd. args ( args) ;
612624 }
613625
0 commit comments