@@ -11,7 +11,7 @@ use std::sync::Arc;
11
11
use core:: { Package , PackageId , PackageSet , Resolve , Target , Profile } ;
12
12
use core:: { TargetKind , Profiles , Dependency , Workspace } ;
13
13
use core:: dependency:: Kind as DepKind ;
14
- use util:: { self , CargoResult , ChainError , internal, Config , profile, Cfg , human} ;
14
+ use util:: { self , CargoResult , ChainError , internal, Config , profile, Cfg , CfgExpr , human} ;
15
15
16
16
use super :: TargetConfig ;
17
17
use super :: custom_build:: { BuildState , BuildScripts } ;
@@ -178,6 +178,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
178
178
-> CargoResult < ( ) > {
179
179
let rustflags = env_args ( self . config ,
180
180
& self . build_config ,
181
+ & self . info ( & kind) ,
181
182
kind,
182
183
"RUSTFLAGS" ) ?;
183
184
let mut process = self . config . rustc ( ) ?. process ( ) ;
@@ -872,22 +873,30 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
872
873
}
873
874
874
875
pub fn rustflags_args ( & self , unit : & Unit ) -> CargoResult < Vec < String > > {
875
- env_args ( self . config , & self . build_config , unit. kind , "RUSTFLAGS" )
876
+ env_args ( self . config , & self . build_config , self . info ( & unit . kind ) , unit. kind , "RUSTFLAGS" )
876
877
}
877
878
878
879
pub fn rustdocflags_args ( & self , unit : & Unit ) -> CargoResult < Vec < String > > {
879
- env_args ( self . config , & self . build_config , unit. kind , "RUSTDOCFLAGS" )
880
+ env_args ( self . config , & self . build_config , self . info ( & unit . kind ) , unit. kind , "RUSTDOCFLAGS" )
880
881
}
881
882
882
883
pub fn show_warnings ( & self , pkg : & PackageId ) -> bool {
883
884
pkg. source_id ( ) . is_path ( ) || self . config . extra_verbose ( )
884
885
}
886
+
887
+ fn info ( & self , kind : & Kind ) -> & TargetInfo {
888
+ match * kind {
889
+ Kind :: Host => & self . host_info ,
890
+ Kind :: Target => & self . target_info ,
891
+ }
892
+ }
885
893
}
886
894
887
895
// Acquire extra flags to pass to the compiler from the
888
896
// RUSTFLAGS environment variable and similar config values
889
897
fn env_args ( config : & Config ,
890
898
build_config : & BuildConfig ,
899
+ target_info : & TargetInfo ,
891
900
kind : Kind ,
892
901
name : & str ) -> CargoResult < Vec < String > > {
893
902
// We *want* to apply RUSTFLAGS only to builds for the
@@ -928,13 +937,34 @@ fn env_args(config: &Config,
928
937
return Ok ( args. collect ( ) ) ;
929
938
}
930
939
940
+ let mut rustflags = Vec :: new ( ) ;
941
+
931
942
let name = name. chars ( ) . flat_map ( |c| c. to_lowercase ( ) ) . collect :: < String > ( ) ;
932
- // Then the target.*.rustflags value
943
+ // Then the target.*.rustflags value...
933
944
let target = build_config. requested_target . as_ref ( ) . unwrap_or ( & build_config. host_triple ) ;
934
945
let key = format ! ( "target.{}.{}" , target, name) ;
935
946
if let Some ( args) = config. get_list_or_split_string ( & key) ? {
936
947
let args = args. val . into_iter ( ) ;
937
- return Ok ( args. collect ( ) ) ;
948
+ rustflags. extend ( args) ;
949
+ }
950
+ // ...including target.'cfg(...)'.rustflags
951
+ if let Some ( ref target_cfg) = target_info. cfg {
952
+ if let Some ( table) = config. get_table ( "target" ) ? {
953
+ let cfgs = table. val . iter ( ) . map ( |( t, _) | ( CfgExpr :: from_str ( t) , t) )
954
+ . filter_map ( |( c, n) | c. map ( |c| ( c, n) ) . ok ( ) )
955
+ . filter ( |& ( ref c, _) | c. matches ( target_cfg) ) ;
956
+ for ( _, n) in cfgs {
957
+ let key = format ! ( "target.'{}'.{}" , n, name) ;
958
+ if let Some ( args) = config. get_list_or_split_string ( & key) ? {
959
+ let args = args. val . into_iter ( ) ;
960
+ rustflags. extend ( args) ;
961
+ }
962
+ }
963
+ }
964
+ }
965
+
966
+ if !rustflags. is_empty ( ) {
967
+ return Ok ( rustflags) ;
938
968
}
939
969
940
970
// Then the build.rustflags value
0 commit comments