@@ -1580,9 +1580,18 @@ impl Step for RustcLink {
15801580#[ derive( Clone ) ]
15811581pub struct GccDylibSet {
15821582 dylibs : BTreeMap < TargetSelection , GccOutput > ,
1583+ host_target : TargetSelection ,
15831584}
15841585
15851586impl GccDylibSet {
1587+ /// Returns the libgccjit.so dylib that corresponds to a host target on which `cg_gcc` will be
1588+ /// executed.
1589+ fn host_dylib ( & self ) -> & GccOutput {
1590+ self . dylibs . get ( & self . host_target ) . unwrap_or_else ( || {
1591+ panic ! ( "libgccjit.so was not build for host target {}" , self . host_target)
1592+ } )
1593+ }
1594+
15861595 /// Install the libgccjit dylibs to the corresponding target directories of the given compiler.
15871596 pub fn install_to ( & self , builder : & Builder < ' _ > , compiler : Compiler ) {
15881597 if builder. config . dry_run ( ) {
@@ -1640,9 +1649,14 @@ pub struct GccCodegenBackend {
16401649
16411650impl GccCodegenBackend {
16421651 /// Create a cg_gcc backend that can compile code for all targets for which we build the
1643- /// standard library.
1652+ /// standard library, plus the host target on which `cg_gcc` will run, so that it can compile
1653+ /// host code (e.g. proc macros).
16441654 pub fn for_all_std_targets ( builder : & Builder < ' _ > , compilers : RustcPrivateCompilers ) -> Self {
1645- let mut targets = builder. targets . clone ( ) ;
1655+ // All std targets + the cg_gcc host target
1656+ let target_set: HashSet < TargetSelection > =
1657+ builder. targets . iter ( ) . copied ( ) . chain ( std:: iter:: once ( compilers. target ( ) ) ) . collect ( ) ;
1658+
1659+ let mut targets: Vec < TargetSelection > = target_set. into_iter ( ) . collect ( ) ;
16461660 // Sort targets to improve step cache hits
16471661 targets. sort ( ) ;
16481662 Self { compilers, targets }
@@ -1682,6 +1696,7 @@ impl Step for GccCodegenBackend {
16821696 . iter ( )
16831697 . map ( |& target| ( target, builder. ensure ( Gcc { target } ) ) )
16841698 . collect ( ) ,
1699+ host_target : target,
16851700 } ;
16861701
16871702 if builder. config . keep_stage . contains ( & build_compiler. stage ) {
@@ -1706,13 +1721,7 @@ impl Step for GccCodegenBackend {
17061721 cargo. arg ( "--manifest-path" ) . arg ( builder. src . join ( "compiler/rustc_codegen_gcc/Cargo.toml" ) ) ;
17071722 rustc_cargo_env ( builder, & mut cargo, target) ;
17081723
1709- add_cg_gcc_cargo_flags (
1710- & mut cargo,
1711- & dylib_set
1712- . dylibs
1713- . get ( & build_compiler. host )
1714- . expect ( "libgccjit was not build for the host target" ) ,
1715- ) ;
1724+ add_cg_gcc_cargo_flags ( & mut cargo, & dylib_set. host_dylib ( ) ) ;
17161725
17171726 let _guard =
17181727 builder. msg ( Kind :: Build , "codegen backend gcc" , Mode :: Codegen , build_compiler, target) ;
0 commit comments