@@ -23,6 +23,7 @@ use std::cell::RefCell;
2323use std:: collections:: hash_map:: { Entry , HashMap } ;
2424use std:: path:: { Path , PathBuf } ;
2525use std:: str:: { self , FromStr } ;
26+ use std:: sync:: Arc ;
2627
2728/// Information about the platform target gleaned from querying rustc.
2829///
@@ -52,7 +53,7 @@ pub struct TargetInfo {
5253 /// target libraries.
5354 pub sysroot_target_libdir : PathBuf ,
5455 /// Extra flags to pass to `rustc`, see [`extra_args`].
55- pub rustflags : Vec < String > ,
56+ pub rustflags : Arc < [ String ] > ,
5657 /// Extra flags to pass to `rustdoc`, see [`extra_args`].
5758 pub rustdocflags : Vec < String > ,
5859 /// Whether or not rustc (stably) supports the `--check-cfg` flag.
@@ -312,7 +313,7 @@ impl TargetInfo {
312313 crate_types : RefCell :: new ( map) ,
313314 sysroot,
314315 sysroot_target_libdir,
315- rustflags,
316+ rustflags : rustflags . into ( ) ,
316317 rustdocflags : extra_args (
317318 gctx,
318319 requested_kinds,
@@ -867,7 +868,10 @@ pub struct RustcTargetData<'gctx> {
867868
868869 /// Build information for the "host", which is information about when
869870 /// `rustc` is invoked without a `--target` flag. This is used for
870- /// procedural macros, build scripts, etc.
871+ /// selecting a linker, and applying link overrides.
872+ ///
873+ /// The configuration read into this depends on whether or not
874+ /// `target-applies-to-host=true`.
871875 host_config : TargetConfig ,
872876 /// Information about the host platform.
873877 host_info : TargetInfo ,
@@ -889,7 +893,10 @@ impl<'gctx> RustcTargetData<'gctx> {
889893 let mut target_config = HashMap :: new ( ) ;
890894 let mut target_info = HashMap :: new ( ) ;
891895 let target_applies_to_host = gctx. target_applies_to_host ( ) ?;
896+ let host_target = CompileTarget :: new ( & rustc. host ) ?;
892897 let host_info = TargetInfo :: new ( gctx, requested_kinds, & rustc, CompileKind :: Host ) ?;
898+
899+ // This config is used for link overrides and choosing a linker.
893900 let host_config = if target_applies_to_host {
894901 gctx. target_cfg_triple ( & rustc. host ) ?
895902 } else {
@@ -902,9 +909,21 @@ impl<'gctx> RustcTargetData<'gctx> {
902909 // needs access to the target config data, create a copy so that it
903910 // can be found. See `rebuild_unit_graph_shared` for why this is done.
904911 if requested_kinds. iter ( ) . any ( CompileKind :: is_host) {
905- let ct = CompileTarget :: new ( & rustc. host ) ?;
906- target_info. insert ( ct, host_info. clone ( ) ) ;
907- target_config. insert ( ct, gctx. target_cfg_triple ( & rustc. host ) ?) ;
912+ target_config. insert ( host_target, gctx. target_cfg_triple ( & rustc. host ) ?) ;
913+
914+ // If target_applies_to_host is true, the host_info is the target info,
915+ // otherwise we need to build target info for the target.
916+ if target_applies_to_host {
917+ target_info. insert ( host_target, host_info. clone ( ) ) ;
918+ } else {
919+ let host_target_info = TargetInfo :: new (
920+ gctx,
921+ requested_kinds,
922+ & rustc,
923+ CompileKind :: Target ( host_target) ,
924+ ) ?;
925+ target_info. insert ( host_target, host_target_info) ;
926+ }
908927 } ;
909928
910929 let mut res = RustcTargetData {
0 commit comments