@@ -519,7 +519,7 @@ pub fn rustc_cargo(builder: &Builder, cargo: &mut Command) {
519519 rustc_cargo_env ( builder, cargo) ;
520520}
521521
522- fn rustc_cargo_env ( builder : & Builder , cargo : & mut Command ) {
522+ pub fn rustc_cargo_env ( builder : & Builder , cargo : & mut Command ) {
523523 // Set some configuration variables picked up by build scripts and
524524 // the compiler alike
525525 cargo. env ( "CFG_RELEASE" , builder. rust_release ( ) )
@@ -614,21 +614,22 @@ impl Step for CodegenBackend {
614614 run. builder . ensure ( CodegenBackend {
615615 compiler : run. builder . compiler ( run. builder . top_stage , run. host ) ,
616616 target : run. target ,
617- backend
617+ backend,
618618 } ) ;
619619 }
620620
621621 fn run ( self , builder : & Builder ) {
622622 let compiler = self . compiler ;
623623 let target = self . target ;
624+ let backend = self . backend ;
624625
625626 builder. ensure ( Rustc { compiler, target } ) ;
626627
627628 if builder. force_use_stage1 ( compiler, target) {
628629 builder. ensure ( CodegenBackend {
629630 compiler : builder. compiler ( 1 , builder. config . build ) ,
630631 target,
631- backend : self . backend ,
632+ backend,
632633 } ) ;
633634 return ;
634635 }
@@ -639,52 +640,7 @@ impl Step for CodegenBackend {
639640 . arg ( builder. src . join ( "src/librustc_trans/Cargo.toml" ) ) ;
640641 rustc_cargo_env ( builder, & mut cargo) ;
641642
642- match & * self . backend {
643- "llvm" | "emscripten" => {
644- // Build LLVM for our target. This will implicitly build the
645- // host LLVM if necessary.
646- let llvm_config = builder. ensure ( native:: Llvm {
647- target,
648- emscripten : self . backend == "emscripten" ,
649- } ) ;
650-
651- if self . backend == "emscripten" {
652- features. push_str ( " emscripten" ) ;
653- }
654-
655- builder. info ( & format ! ( "Building stage{} codegen artifacts ({} -> {}, {})" ,
656- compiler. stage, & compiler. host, target, self . backend) ) ;
657-
658- // Pass down configuration from the LLVM build into the build of
659- // librustc_llvm and librustc_trans.
660- if builder. is_rust_llvm ( target) {
661- cargo. env ( "LLVM_RUSTLLVM" , "1" ) ;
662- }
663- cargo. env ( "LLVM_CONFIG" , & llvm_config) ;
664- if self . backend != "emscripten" {
665- let target_config = builder. config . target_config . get ( & target) ;
666- if let Some ( s) = target_config. and_then ( |c| c. llvm_config . as_ref ( ) ) {
667- cargo. env ( "CFG_LLVM_ROOT" , s) ;
668- }
669- }
670- // Building with a static libstdc++ is only supported on linux right now,
671- // not for MSVC or macOS
672- if builder. config . llvm_static_stdcpp &&
673- !target. contains ( "freebsd" ) &&
674- !target. contains ( "windows" ) &&
675- !target. contains ( "apple" ) {
676- let file = compiler_file ( builder,
677- builder. cxx ( target) . unwrap ( ) ,
678- target,
679- "libstdc++.a" ) ;
680- cargo. env ( "LLVM_STATIC_STDCPP" , file) ;
681- }
682- if builder. config . llvm_link_shared {
683- cargo. env ( "LLVM_LINK_SHARED" , "1" ) ;
684- }
685- }
686- _ => panic ! ( "unknown backend: {}" , self . backend) ,
687- }
643+ features += & build_codegen_backend ( & builder, & mut cargo, & compiler, target, backend) ;
688644
689645 let tmp_stamp = builder. cargo_out ( compiler, Mode :: Librustc , target)
690646 . join ( ".tmp.stamp" ) ;
@@ -711,12 +667,69 @@ impl Step for CodegenBackend {
711667 codegen_backend. display( ) ,
712668 f. display( ) ) ;
713669 }
714- let stamp = codegen_backend_stamp ( builder, compiler, target, self . backend ) ;
670+ let stamp = codegen_backend_stamp ( builder, compiler, target, backend) ;
715671 let codegen_backend = codegen_backend. to_str ( ) . unwrap ( ) ;
716672 t ! ( t!( File :: create( & stamp) ) . write_all( codegen_backend. as_bytes( ) ) ) ;
717673 }
718674}
719675
676+ pub fn build_codegen_backend ( builder : & Builder ,
677+ cargo : & mut Command ,
678+ compiler : & Compiler ,
679+ target : Interned < String > ,
680+ backend : Interned < String > ) -> String {
681+ let mut features = String :: new ( ) ;
682+
683+ match & * backend {
684+ "llvm" | "emscripten" => {
685+ // Build LLVM for our target. This will implicitly build the
686+ // host LLVM if necessary.
687+ let llvm_config = builder. ensure ( native:: Llvm {
688+ target,
689+ emscripten : backend == "emscripten" ,
690+ } ) ;
691+
692+ if backend == "emscripten" {
693+ features. push_str ( " emscripten" ) ;
694+ }
695+
696+ builder. info ( & format ! ( "Building stage{} codegen artifacts ({} -> {}, {})" ,
697+ compiler. stage, & compiler. host, target, backend) ) ;
698+
699+ // Pass down configuration from the LLVM build into the build of
700+ // librustc_llvm and librustc_trans.
701+ if builder. is_rust_llvm ( target) {
702+ cargo. env ( "LLVM_RUSTLLVM" , "1" ) ;
703+ }
704+ cargo. env ( "LLVM_CONFIG" , & llvm_config) ;
705+ if backend != "emscripten" {
706+ let target_config = builder. config . target_config . get ( & target) ;
707+ if let Some ( s) = target_config. and_then ( |c| c. llvm_config . as_ref ( ) ) {
708+ cargo. env ( "CFG_LLVM_ROOT" , s) ;
709+ }
710+ }
711+ // Building with a static libstdc++ is only supported on linux right now,
712+ // not for MSVC or macOS
713+ if builder. config . llvm_static_stdcpp &&
714+ !target. contains ( "freebsd" ) &&
715+ !target. contains ( "windows" ) &&
716+ !target. contains ( "apple" ) {
717+ let file = compiler_file ( builder,
718+ builder. cxx ( target) . unwrap ( ) ,
719+ target,
720+ "libstdc++.a" ) ;
721+ cargo. env ( "LLVM_STATIC_STDCPP" , file) ;
722+ }
723+ if builder. config . llvm_link_shared {
724+ cargo. env ( "LLVM_LINK_SHARED" , "1" ) ;
725+ }
726+ }
727+ _ => panic ! ( "unknown backend: {}" , backend) ,
728+ }
729+
730+ features
731+ }
732+
720733/// Creates the `codegen-backends` folder for a compiler that's about to be
721734/// assembled as a complete compiler.
722735///
@@ -795,6 +808,8 @@ pub fn librustc_stamp(builder: &Builder, compiler: Compiler, target: Interned<St
795808 builder. cargo_out ( compiler, Mode :: Librustc , target) . join ( ".librustc.stamp" )
796809}
797810
811+ /// Cargo's output path for librustc_trans in a given stage, compiled by a particular
812+ /// compiler for the specified target and backend.
798813fn codegen_backend_stamp ( builder : & Builder ,
799814 compiler : Compiler ,
800815 target : Interned < String > ,
@@ -803,7 +818,7 @@ fn codegen_backend_stamp(builder: &Builder,
803818 . join ( format ! ( ".librustc_trans-{}.stamp" , backend) )
804819}
805820
806- fn compiler_file ( builder : & Builder ,
821+ pub fn compiler_file ( builder : & Builder ,
807822 compiler : & Path ,
808823 target : Interned < String > ,
809824 file : & str ) -> PathBuf {
0 commit comments