@@ -23,6 +23,7 @@ use std::cell::RefCell;
23
23
use std:: collections:: hash_map:: { Entry , HashMap } ;
24
24
use std:: path:: { Path , PathBuf } ;
25
25
use std:: str:: { self , FromStr } ;
26
+ use std:: sync:: Arc ;
26
27
27
28
/// Information about the platform target gleaned from querying rustc.
28
29
///
@@ -52,7 +53,7 @@ pub struct TargetInfo {
52
53
/// target libraries.
53
54
pub sysroot_target_libdir : PathBuf ,
54
55
/// Extra flags to pass to `rustc`, see [`extra_args`].
55
- pub rustflags : Vec < String > ,
56
+ pub rustflags : Arc < [ String ] > ,
56
57
/// Extra flags to pass to `rustdoc`, see [`extra_args`].
57
58
pub rustdocflags : Vec < String > ,
58
59
/// Whether or not rustc (stably) supports the `--check-cfg` flag.
@@ -312,7 +313,7 @@ impl TargetInfo {
312
313
crate_types : RefCell :: new ( map) ,
313
314
sysroot,
314
315
sysroot_target_libdir,
315
- rustflags,
316
+ rustflags : rustflags . into ( ) ,
316
317
rustdocflags : extra_args (
317
318
gctx,
318
319
requested_kinds,
@@ -867,7 +868,10 @@ pub struct RustcTargetData<'gctx> {
867
868
868
869
/// Build information for the "host", which is information about when
869
870
/// `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`.
871
875
host_config : TargetConfig ,
872
876
/// Information about the host platform.
873
877
host_info : TargetInfo ,
@@ -889,7 +893,10 @@ impl<'gctx> RustcTargetData<'gctx> {
889
893
let mut target_config = HashMap :: new ( ) ;
890
894
let mut target_info = HashMap :: new ( ) ;
891
895
let target_applies_to_host = gctx. target_applies_to_host ( ) ?;
896
+ let host_target = CompileTarget :: new ( & rustc. host ) ?;
892
897
let host_info = TargetInfo :: new ( gctx, requested_kinds, & rustc, CompileKind :: Host ) ?;
898
+
899
+ // This config is used for link overrides and choosing a linker.
893
900
let host_config = if target_applies_to_host {
894
901
gctx. target_cfg_triple ( & rustc. host ) ?
895
902
} else {
@@ -902,9 +909,21 @@ impl<'gctx> RustcTargetData<'gctx> {
902
909
// needs access to the target config data, create a copy so that it
903
910
// can be found. See `rebuild_unit_graph_shared` for why this is done.
904
911
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
+ }
908
927
} ;
909
928
910
929
let mut res = RustcTargetData {
0 commit comments