@@ -12,7 +12,7 @@ use crate::core::compiler::{
12
12
BuildOutput , BuildRunner , CompileKind , CompileMode , CompileTarget , CrateType ,
13
13
} ;
14
14
use crate :: core:: { Dependency , Package , Target , TargetKind , Workspace } ;
15
- use crate :: util:: context:: { GlobalContext , StringList , TargetConfig } ;
15
+ use crate :: util:: context:: { GlobalContext , TargetConfig } ;
16
16
use crate :: util:: interning:: InternedString ;
17
17
use crate :: util:: { CargoResult , Rustc } ;
18
18
use anyhow:: Context as _;
@@ -26,7 +26,7 @@ use std::str::{self, FromStr};
26
26
use std:: sync:: Arc ;
27
27
28
28
/// Information about the platform target gleaned from querying rustc and from
29
- /// collating configs.
29
+ /// merging configs.
30
30
///
31
31
/// [`RustcTargetData`] keeps several of these, one for the host and the others
32
32
/// for other specified targets. If no target is specified, it uses a clone from
@@ -162,14 +162,16 @@ impl TargetInfo {
162
162
requested_kinds : & [ CompileKind ] ,
163
163
rustc : & Rustc ,
164
164
kind : CompileKind ,
165
- // This config is used for `links_overrides` and `linker`.
166
- //
167
- // In the case of target_applies_to_host=true (default) it may contain
168
- // incorrect rustflags.
169
165
target_config : & TargetConfig ,
170
166
) -> CargoResult < TargetInfo > {
171
- let mut rustflags =
172
- extra_args ( gctx, requested_kinds, & rustc. host , None , kind, Flags :: Rust ) ?;
167
+ let mut rustflags = extra_args (
168
+ gctx,
169
+ requested_kinds,
170
+ None ,
171
+ target_config,
172
+ kind,
173
+ Flags :: Rust ,
174
+ ) ?;
173
175
let mut turn = 0 ;
174
176
loop {
175
177
let extra_fingerprint = kind. fingerprint_hash ( ) ;
@@ -291,8 +293,8 @@ impl TargetInfo {
291
293
let new_flags = extra_args (
292
294
gctx,
293
295
requested_kinds,
294
- & rustc. host ,
295
296
Some ( & cfg) ,
297
+ target_config,
296
298
kind,
297
299
Flags :: Rust ,
298
300
) ?;
@@ -325,8 +327,8 @@ impl TargetInfo {
325
327
rustdocflags : extra_args (
326
328
gctx,
327
329
requested_kinds,
328
- & rustc. host ,
329
330
Some ( & cfg) ,
331
+ target_config,
330
332
kind,
331
333
Flags :: Rustdoc ,
332
334
) ?
@@ -679,13 +681,6 @@ enum Flags {
679
681
}
680
682
681
683
impl Flags {
682
- fn as_key ( self ) -> & ' static str {
683
- match self {
684
- Flags :: Rust => "rustflags" ,
685
- Flags :: Rustdoc => "rustdocflags" ,
686
- }
687
- }
688
-
689
684
fn as_env ( self ) -> & ' static str {
690
685
match self {
691
686
Flags :: Rust => "RUSTFLAGS" ,
@@ -722,8 +717,8 @@ impl Flags {
722
717
fn extra_args (
723
718
gctx : & GlobalContext ,
724
719
requested_kinds : & [ CompileKind ] ,
725
- host_triple : & str ,
726
720
target_cfg : Option < & [ Cfg ] > ,
721
+ target_config : & TargetConfig ,
727
722
kind : CompileKind ,
728
723
flags : Flags ,
729
724
) -> CargoResult < Vec < String > > {
@@ -743,7 +738,7 @@ fn extra_args(
743
738
// --target. Or, phrased differently, no `--target` behaves the same as `--target
744
739
// <host>`, and host artifacts are always "special" (they don't pick up `RUSTFLAGS` for
745
740
// example).
746
- return Ok ( rustflags_from_host ( gctx , flags, host_triple ) ?. unwrap_or_else ( Vec :: new) ) ;
741
+ return Ok ( rustflags_from_host ( target_config , flags) ?. unwrap_or_else ( Vec :: new) ) ;
747
742
}
748
743
}
749
744
@@ -753,9 +748,7 @@ fn extra_args(
753
748
754
749
if let Some ( rustflags) = rustflags_from_env ( gctx, flags) {
755
750
Ok ( rustflags)
756
- } else if let Some ( rustflags) =
757
- rustflags_from_target ( gctx, host_triple, target_cfg, kind, flags) ?
758
- {
751
+ } else if let Some ( rustflags) = rustflags_from_target ( gctx, target_cfg, target_config, flags) ? {
759
752
Ok ( rustflags)
760
753
} else if let Some ( rustflags) = rustflags_from_build ( gctx, flags) ? {
761
754
Ok ( rustflags)
@@ -794,21 +787,18 @@ fn rustflags_from_env(gctx: &GlobalContext, flags: Flags) -> Option<Vec<String>>
794
787
/// See [`extra_args`] for more.
795
788
fn rustflags_from_target (
796
789
gctx : & GlobalContext ,
797
- host_triple : & str ,
798
790
target_cfg : Option < & [ Cfg ] > ,
799
- kind : CompileKind ,
791
+ target_config : & TargetConfig ,
800
792
flag : Flags ,
801
793
) -> CargoResult < Option < Vec < String > > > {
802
794
let mut rustflags = Vec :: new ( ) ;
803
795
804
- // Then the target.*.rustflags value...
805
- let target = match & kind {
806
- CompileKind :: Host => host_triple,
807
- CompileKind :: Target ( target) => target. short_name ( ) ,
796
+ let config_flags = match flag {
797
+ Flags :: Rust => & target_config. rustflags ,
798
+ Flags :: Rustdoc => & target_config. rustdocflags ,
808
799
} ;
809
- let key = format ! ( "target.{}.{}" , target, flag. as_key( ) ) ;
810
- if let Some ( args) = gctx. get :: < Option < StringList > > ( & key) ? {
811
- rustflags. extend ( args. as_slice ( ) . iter ( ) . cloned ( ) ) ;
800
+ if let Some ( args) = config_flags {
801
+ rustflags. extend ( args. val . as_slice ( ) . iter ( ) . cloned ( ) ) ;
812
802
}
813
803
// ...including target.'cfg(...)'.rustflags
814
804
if let Some ( target_cfg) = target_cfg {
@@ -876,13 +866,11 @@ fn target_linker(
876
866
/// Gets compiler flags from `[host]` section in the config.
877
867
/// See [`extra_args`] for more.
878
868
fn rustflags_from_host (
879
- gctx : & GlobalContext ,
869
+ target_config : & TargetConfig ,
880
870
flag : Flags ,
881
- host_triple : & str ,
882
871
) -> CargoResult < Option < Vec < String > > > {
883
- let target_cfg = gctx. host_cfg_triple ( host_triple) ?;
884
872
let list = match flag {
885
- Flags :: Rust => & target_cfg . rustflags ,
873
+ Flags :: Rust => & target_config . rustflags ,
886
874
Flags :: Rustdoc => {
887
875
// host.rustdocflags is not a thing, since it does not make sense
888
876
return Ok ( None ) ;
@@ -941,9 +929,14 @@ impl<'gctx> RustcTargetData<'gctx> {
941
929
let target_applies_to_host = gctx. target_applies_to_host ( ) ?;
942
930
let host_target = CompileTarget :: new ( & rustc. host ) ?;
943
931
944
- // This config is used for link overrides and choosing a linker.
945
932
let host_config = if target_applies_to_host {
946
- gctx. target_cfg_triple ( & rustc. host ) ?
933
+ let mut config = gctx. target_cfg_triple ( & rustc. host ) ?;
934
+ if requested_kinds != [ CompileKind :: Host ] {
935
+ // When an explicit target flag is passed rustflags are ignored for host artifacts.
936
+ config. rustflags = None ;
937
+ config. rustdocflags = None ;
938
+ }
939
+ config
947
940
} else {
948
941
gctx. host_cfg_triple ( & rustc. host ) ?
949
942
} ;
0 commit comments