File tree Expand file tree Collapse file tree 2 files changed +87
-6
lines changed Expand file tree Collapse file tree 2 files changed +87
-6
lines changed Original file line number Diff line number Diff line change @@ -284,7 +284,9 @@ pub trait ArgMatchesExt {
284284 ws. set_require_optional_deps ( false ) ;
285285 }
286286 if ws. is_virtual ( ) && !config. cli_unstable ( ) . package_features {
287- for flag in & [ "features" , "all-features" , "no-default-features" ] {
287+ // --all-features is actually honored. In general, workspaces and
288+ // feature flags are a bit of a mess right now.
289+ for flag in & [ "features" , "no-default-features" ] {
288290 if self . _is_present ( flag) {
289291 bail ! (
290292 "--{} is not allowed in the root of a virtual workspace" ,
Original file line number Diff line number Diff line change @@ -2026,11 +2026,6 @@ fn virtual_ws_flags() {
20262026 . with_status ( 101 )
20272027 . run ( ) ;
20282028
2029- p. cargo ( "build --all-features" )
2030- . with_stderr ( "[ERROR] --all-features is not allowed in the root of a virtual workspace" )
2031- . with_status ( 101 )
2032- . run ( ) ;
2033-
20342029 // It's OK if cwd is in a member.
20352030 p. cargo ( "check --features=f1 -v" )
20362031 . cwd ( "a" )
@@ -2057,3 +2052,87 @@ fn virtual_ws_flags() {
20572052 )
20582053 . run ( ) ;
20592054}
2055+
2056+ #[ cargo_test]
2057+ fn all_features_virtual_ws ( ) {
2058+ // What happens with `--all-features` in the root of a virtual workspace.
2059+ // Some of this behavior is a little strange (member dependencies also
2060+ // have all features enabled, one might expect `f4` to be disabled).
2061+ let p = project ( )
2062+ . file (
2063+ "Cargo.toml" ,
2064+ r#"
2065+ [workspace]
2066+ members = ["a", "b"]
2067+ "# ,
2068+ )
2069+ . file (
2070+ "a/Cargo.toml" ,
2071+ r#"
2072+ [package]
2073+ name = "a"
2074+ version = "0.1.0"
2075+ edition = "2018"
2076+
2077+ [dependencies]
2078+ b = {path="../b", optional=true}
2079+
2080+ [features]
2081+ default = ["f1"]
2082+ f1 = []
2083+ f2 = []
2084+ "# ,
2085+ )
2086+ . file (
2087+ "a/src/main.rs" ,
2088+ r#"
2089+ fn main() {
2090+ if cfg!(feature="f1") {
2091+ println!("f1");
2092+ }
2093+ if cfg!(feature="f2") {
2094+ println!("f2");
2095+ }
2096+ #[cfg(feature="b")]
2097+ b::f();
2098+ }
2099+ "# ,
2100+ )
2101+ . file (
2102+ "b/Cargo.toml" ,
2103+ r#"
2104+ [package]
2105+ name = "b"
2106+ version = "0.1.0"
2107+
2108+ [features]
2109+ default = ["f3"]
2110+ f3 = []
2111+ f4 = []
2112+ "# ,
2113+ )
2114+ . file (
2115+ "b/src/lib.rs" ,
2116+ r#"
2117+ pub fn f() {
2118+ if cfg!(feature="f3") {
2119+ println!("f3");
2120+ }
2121+ if cfg!(feature="f4") {
2122+ println!("f4");
2123+ }
2124+ }
2125+ "# ,
2126+ )
2127+ . build ( ) ;
2128+
2129+ p. cargo ( "run" ) . with_stdout ( "f1\n " ) . run ( ) ;
2130+ p. cargo ( "run --all-features" )
2131+ . with_stdout ( "f1\n f2\n f3\n f4\n " )
2132+ . run ( ) ;
2133+ // In `a`, it behaves differently. :(
2134+ p. cargo ( "run --all-features" )
2135+ . cwd ( "a" )
2136+ . with_stdout ( "f1\n f2\n f3\n " )
2137+ . run ( ) ;
2138+ }
You can’t perform that action at this time.
0 commit comments