@@ -135,7 +135,11 @@ fn compile_time_sysroot() -> Option<String> {
135135}
136136
137137/// Execute a compiler with the given CLI arguments and callbacks.
138- fn run_compiler ( mut args : Vec < String > , callbacks : & mut ( dyn rustc_driver:: Callbacks + Send ) ) -> ! {
138+ fn run_compiler (
139+ mut args : Vec < String > ,
140+ callbacks : & mut ( dyn rustc_driver:: Callbacks + Send ) ,
141+ insert_default_args : bool ,
142+ ) -> ! {
139143 // Make sure we use the right default sysroot. The default sysroot is wrong,
140144 // because `get_or_default_sysroot` in `librustc_session` bases that on `current_exe`.
141145 //
@@ -151,9 +155,11 @@ fn run_compiler(mut args: Vec<String>, callbacks: &mut (dyn rustc_driver::Callba
151155 }
152156 }
153157
154- // Some options have different defaults in Miri than in plain rustc; apply those by making
155- // them the first arguments after the binary name (but later arguments can overwrite them).
156- args. splice ( 1 ..1 , miri:: MIRI_DEFAULT_ARGS . iter ( ) . map ( ToString :: to_string) ) ;
158+ if insert_default_args {
159+ // Some options have different defaults in Miri than in plain rustc; apply those by making
160+ // them the first arguments after the binary name (but later arguments can overwrite them).
161+ args. splice ( 1 ..1 , miri:: MIRI_DEFAULT_ARGS . iter ( ) . map ( ToString :: to_string) ) ;
162+ }
157163
158164 // Invoke compiler, and handle return code.
159165 let exit_code = rustc_driver:: catch_with_exit_code ( move || {
@@ -166,11 +172,24 @@ fn main() {
166172 rustc_driver:: install_ice_hook ( ) ;
167173
168174 // If the environment asks us to actually be rustc, then do that.
169- if env:: var_os ( "MIRI_BE_RUSTC" ) . is_some ( ) {
175+ if let Some ( crate_kind ) = env:: var_os ( "MIRI_BE_RUSTC" ) {
170176 rustc_driver:: init_rustc_env_logger ( ) ;
177+
178+ // Don't insert `MIRI_DEFAULT_ARGS`, in particular, `--cfg=miri`, if we are building a
179+ // "host" crate. That may cause procedural macros (and probably build scripts) to depend
180+ // on Miri-only symbols, such as `miri_resolve_frame`:
181+ // https://github.com/rust-lang/miri/issues/1760
182+ let insert_default_args = if crate_kind == "target" {
183+ true
184+ } else if crate_kind == "host" {
185+ false
186+ } else {
187+ panic ! ( "invalid `MIRI_BE_RUSTC` value: {:?}" , crate_kind)
188+ } ;
189+
171190 // We cannot use `rustc_driver::main` as we need to adjust the CLI arguments.
172191 let mut callbacks = rustc_driver:: TimePassesCallbacks :: default ( ) ;
173- run_compiler ( env:: args ( ) . collect ( ) , & mut callbacks)
192+ run_compiler ( env:: args ( ) . collect ( ) , & mut callbacks, insert_default_args )
174193 }
175194
176195 // Init loggers the Miri way.
@@ -300,5 +319,5 @@ fn main() {
300319
301320 debug ! ( "rustc arguments: {:?}" , rustc_args) ;
302321 debug ! ( "crate arguments: {:?}" , miri_config. args) ;
303- run_compiler ( rustc_args, & mut MiriCompilerCalls { miri_config } )
322+ run_compiler ( rustc_args, & mut MiriCompilerCalls { miri_config } , /* insert_default_args: */ true )
304323}
0 commit comments