@@ -135,7 +135,11 @@ fn compile_time_sysroot() -> Option<String> {
135
135
}
136
136
137
137
/// 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
+ ) -> ! {
139
143
// Make sure we use the right default sysroot. The default sysroot is wrong,
140
144
// because `get_or_default_sysroot` in `librustc_session` bases that on `current_exe`.
141
145
//
@@ -151,9 +155,11 @@ fn run_compiler(mut args: Vec<String>, callbacks: &mut (dyn rustc_driver::Callba
151
155
}
152
156
}
153
157
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
+ }
157
163
158
164
// Invoke compiler, and handle return code.
159
165
let exit_code = rustc_driver:: catch_with_exit_code ( move || {
@@ -166,11 +172,24 @@ fn main() {
166
172
rustc_driver:: install_ice_hook ( ) ;
167
173
168
174
// 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" ) {
170
176
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
+
171
190
// We cannot use `rustc_driver::main` as we need to adjust the CLI arguments.
172
191
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 )
174
193
}
175
194
176
195
// Init loggers the Miri way.
@@ -300,5 +319,5 @@ fn main() {
300
319
301
320
debug ! ( "rustc arguments: {:?}" , rustc_args) ;
302
321
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 )
304
323
}
0 commit comments