@@ -19,7 +19,11 @@ use rustc::ty::TyCtxt;
1919use syntax:: ast:: { self , MetaItemKind , NestedMetaItemKind } ;
2020use std:: path:: PathBuf ;
2121
22- struct MiriCompilerCalls ( RustcDefaultCalls ) ;
22+ struct MiriCompilerCalls {
23+ default : RustcDefaultCalls ,
24+ /// whether we are building for the host
25+ host_target : bool ,
26+ }
2327
2428impl < ' a > CompilerCalls < ' a > for MiriCompilerCalls {
2529 fn early_callback (
@@ -30,7 +34,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
3034 descriptions : & rustc_errors:: registry:: Registry ,
3135 output : ErrorOutputType ,
3236 ) -> Compilation {
33- self . 0 . early_callback (
37+ self . default . early_callback (
3438 matches,
3539 sopts,
3640 cfg,
@@ -47,7 +51,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
4751 ofile : & Option < PathBuf > ,
4852 descriptions : & rustc_errors:: registry:: Registry ,
4953 ) -> Option < ( Input , Option < PathBuf > ) > {
50- self . 0 . no_input (
54+ self . default . no_input (
5155 matches,
5256 sopts,
5357 cfg,
@@ -64,17 +68,17 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
6468 odir : & Option < PathBuf > ,
6569 ofile : & Option < PathBuf > ,
6670 ) -> Compilation {
67- self . 0 . late_callback ( matches, sess, input, odir, ofile)
71+ self . default . late_callback ( matches, sess, input, odir, ofile)
6872 }
6973 fn build_controller (
7074 & mut self ,
7175 sess : & Session ,
7276 matches : & getopts:: Matches ,
7377 ) -> CompileController < ' a > {
74- let mut control = self . 0 . build_controller ( sess, matches) ;
78+ let mut control = self . default . build_controller ( sess, matches) ;
7579 control. after_hir_lowering . callback = Box :: new ( after_hir_lowering) ;
7680 control. after_analysis . callback = Box :: new ( after_analysis) ;
77- if std :: env :: var ( "MIRI_HOST_TARGET" ) != Ok ( "yes" . to_owned ( ) ) {
81+ if ! self . host_target {
7882 // only fully compile targets on the host
7983 control. after_analysis . stop = Compilation :: Stop ;
8084 }
@@ -254,6 +258,16 @@ fn main() {
254258
255259 // for auxilary builds in unit tests
256260 args. push ( "-Zalways-encode-mir" . to_owned ( ) ) ;
261+ let mut host_target = false ;
262+ args. retain ( |arg| if arg == "--miri_host_target" {
263+ host_target = true ;
264+ false // remove the flag, rustc doesn't know it
265+ } else {
266+ true
267+ } ) ;
257268
258- rustc_driver:: run_compiler ( & args, & mut MiriCompilerCalls ( RustcDefaultCalls ) , None , None ) ;
269+ rustc_driver:: run_compiler ( & args, & mut MiriCompilerCalls {
270+ default : RustcDefaultCalls ,
271+ host_target,
272+ } , None , None ) ;
259273}
0 commit comments