File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
src/cargo/core/compiler/build_context Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,7 @@ impl TargetInfo {
153153
154154 let cfg = lines
155155 . map ( |line| Ok ( Cfg :: from_str ( line) ?) )
156+ . filter ( TargetInfo :: not_user_specific_cfg)
156157 . collect :: < CargoResult < Vec < _ > > > ( )
157158 . chain_err ( || {
158159 format ! (
@@ -189,6 +190,15 @@ impl TargetInfo {
189190 } )
190191 }
191192
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+
192202 /// All the target `cfg` settings.
193203 pub fn cfg ( & self ) -> & [ Cfg ] {
194204 & self . cfg
Original file line number Diff line number Diff line change @@ -4739,3 +4739,23 @@ fn build_with_relative_cargo_home_path() {
47394739
47404740 p. cargo ( "build" ) . env ( "CARGO_HOME" , "./cargo_home/" ) . run ( ) ;
47414741}
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