File tree 2 files changed +30
-0
lines changed
src/cargo/core/compiler/build_context
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,7 @@ impl TargetInfo {
153
153
154
154
let cfg = lines
155
155
. map ( |line| Ok ( Cfg :: from_str ( line) ?) )
156
+ . filter ( TargetInfo :: not_user_specific_cfg)
156
157
. collect :: < CargoResult < Vec < _ > > > ( )
157
158
. chain_err ( || {
158
159
format ! (
@@ -189,6 +190,15 @@ impl TargetInfo {
189
190
} )
190
191
}
191
192
193
+ fn not_user_specific_cfg ( cfg : & CargoResult < Cfg > ) -> bool {
194
+ if let Ok ( Cfg :: Name ( cfg_name) ) = cfg {
195
+ if cfg_name == "debug_assertions" || cfg_name == "proc_macro" {
196
+ return false ;
197
+ }
198
+ }
199
+ true
200
+ }
201
+
192
202
/// All the target `cfg` settings.
193
203
pub fn cfg ( & self ) -> & [ Cfg ] {
194
204
& self . cfg
Original file line number Diff line number Diff line change @@ -4739,3 +4739,23 @@ fn build_with_relative_cargo_home_path() {
4739
4739
4740
4740
p. cargo ( "build" ) . env ( "CARGO_HOME" , "./cargo_home/" ) . run ( ) ;
4741
4741
}
4742
+
4743
+ #[ cargo_test]
4744
+ fn user_specific_cfgs_are_filtered_out ( ) {
4745
+ let p = project ( )
4746
+ . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ) )
4747
+ . file ( "src/main.rs" , r#"fn main() {}"# )
4748
+ . file (
4749
+ "build.rs" ,
4750
+ r#"
4751
+ fn main() {
4752
+ assert!(std::env::var_os("CARGO_CFG_PROC_MACRO").is_none());
4753
+ assert!(std::env::var_os("CARGO_CFG_DEBUG_ASSERTIONS").is_none());
4754
+ }"# ,
4755
+ )
4756
+ . build ( ) ;
4757
+
4758
+ p. cargo ( "rustc -- --cfg debug_assertions --cfg proc_macro" )
4759
+ . run ( ) ;
4760
+ p. process ( & p. bin ( "foo" ) ) . run ( ) ;
4761
+ }
You can’t perform that action at this time.
0 commit comments