File tree Expand file tree Collapse file tree 2 files changed +58
-2
lines changed Expand file tree Collapse file tree 2 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -946,8 +946,8 @@ fn resolve_all_features(
946
946
// Include features enabled for use by dependencies so targets can also use them with the
947
947
// required-features field when deciding whether to be built or skipped.
948
948
for ( dep_id, deps) in resolve_with_overrides. deps ( package_id) {
949
- for feature in resolved_features . activated_features ( dep_id , false ) {
950
- for dep in deps {
949
+ for dep in deps {
950
+ for feature in resolved_features . activated_features ( dep_id , dep . is_build ( ) ) {
951
951
features. insert ( dep. name_in_toml ( ) . to_string ( ) + "/" + & feature) ;
952
952
}
953
953
}
Original file line number Diff line number Diff line change @@ -765,3 +765,59 @@ fn all_feature_opts() {
765
765
. env ( "EXPECTED_FEATS" , "5" )
766
766
. run ( ) ;
767
767
}
768
+
769
+ #[ cargo_test]
770
+ fn required_features_build_dep ( ) {
771
+ // Check that required-features handles build-dependencies correctly.
772
+ let p = project ( )
773
+ . file (
774
+ "Cargo.toml" ,
775
+ r#"
776
+ [package]
777
+ name = "foo"
778
+ version = "0.1.0"
779
+ edition = "2018"
780
+
781
+ [[bin]]
782
+ name = "x"
783
+ required-features = ["bdep/f1"]
784
+
785
+ [build-dependencies]
786
+ bdep = {path="bdep"}
787
+ "# ,
788
+ )
789
+ . file ( "build.rs" , "fn main() {}" )
790
+ . file (
791
+ "src/bin/x.rs" ,
792
+ r#"
793
+ fn main() {}
794
+ "# ,
795
+ )
796
+ . file (
797
+ "bdep/Cargo.toml" ,
798
+ r#"
799
+ [package]
800
+ name = "bdep"
801
+ version = "0.1.0"
802
+
803
+ [features]
804
+ f1 = []
805
+ "# ,
806
+ )
807
+ . file ( "bdep/src/lib.rs" , "" )
808
+ . build ( ) ;
809
+
810
+ p. cargo ( "run" )
811
+ . with_status ( 101 )
812
+ . with_stderr (
813
+ "\
814
+ [ERROR] target `x` in package `foo` requires the features: `bdep/f1`
815
+ Consider enabling them by passing, e.g., `--features=\" bdep/f1\" `
816
+ " ,
817
+ )
818
+ . run ( ) ;
819
+
820
+ p. cargo ( "run --features bdep/f1 -Zfeatures=build_dep" )
821
+ . masquerade_as_nightly_cargo ( )
822
+ . run ( ) ;
823
+ }
You can’t perform that action at this time.
0 commit comments