Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo test --all don't honor --no-default-features for member project #7160

Open
BusyJay opened this issue Jul 22, 2019 · 4 comments
Open

cargo test --all don't honor --no-default-features for member project #7160

BusyJay opened this issue Jul 22, 2019 · 4 comments
Labels
A-features Area: features — conditional compilation C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@BusyJay
Copy link
Contributor

BusyJay commented Jul 22, 2019

Project layout looks like

a/
  Cargo.toml
  b/
    Cargo.toml

a/Cargo.toml looks like

[package]
name = "a"
version = "0.1.0"
edition = "2018"

[features]
default = ["feature-a"]
feature-a = []
feature-b = []

[workspace]
members = ["b"]

b/Cargo.toml looks like

[package]
name = "b"
version = "0.1.0"
edition = "2018"


[features]
default = ["feature-a"]
feature-a = ["a/feature-a"]
feature-b = ["a/feature-b"]

[dependencies]
a = { path = "..", default-features = false }

And cargo test --all will not honor the --no-default-features flag.

 % cargo test --all --no-default-features --features feature-b --verbose
   Compiling a v0.1.0 (/tmp/a)
     Running `rustc --edition=2018 --crate-name a src/lib.rs --color always --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg 'feature="feature-a"' --cfg 'feature="feature-b"' -C metadata=09792cb50711fca8 -C extra-filename=-09792cb50711fca8 --out-dir /tmp/a/target/debug/deps -C incremental=/tmp/a/target/debug/incremental -L dependency=/tmp/a/target/debug/deps`
     Running `rustc --edition=2018 --crate-name a src/lib.rs --color always --emit=dep-info,metadata,link -C debuginfo=2 --test --cfg 'feature="feature-a"' --cfg 'feature="feature-b"' -C metadata=7aec07bce955fd6c -C extra-filename=-7aec07bce955fd6c --out-dir /tmp/a/target/debug/deps -C incremental=/tmp/a/target/debug/incremental -L dependency=/tmp/a/target/debug/deps`
   Compiling b v0.1.0 (/tmp/a/b)
     Running `rustc --edition=2018 --crate-name b b/src/lib.rs --color always --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg 'feature="a"' --cfg 'feature="default"' --cfg 'feature="feature-a"' -C metadata=f8a1d0b2c22c9971 -C extra-filename=-f8a1d0b2c22c9971 --out-dir /tmp/a/target/debug/deps -C incremental=/tmp/a/target/debug/incremental -L dependency=/tmp/a/target/debug/deps --extern a=/tmp/a/target/debug/deps/liba-09792cb50711fca8.rlib`
     Running `rustc --edition=2018 --crate-name b b/src/lib.rs --color always --emit=dep-info,metadata,link -C debuginfo=2 --test --cfg 'feature="a"' --cfg 'feature="default"' --cfg 'feature="feature-a"' -C metadata=4af8985939a1dfde -C extra-filename=-4af8985939a1dfde --out-dir /tmp/a/target/debug/deps -C incremental=/tmp/a/target/debug/incremental -L dependency=/tmp/a/target/debug/deps --extern a=/tmp/a/target/debug/deps/liba-09792cb50711fca8.rlib`
     Running `rustc --edition=2018 --crate-name tests b/tests/tests.rs --color always --emit=dep-info,link -C debuginfo=2 --test --cfg 'feature="a"' --cfg 'feature="default"' --cfg 'feature="feature-a"' -C metadata=e05b77e250661b9b -C extra-filename=-e05b77e250661b9b --out-dir /tmp/a/target/debug/deps -C incremental=/tmp/a/target/debug/incremental -L dependency=/tmp/a/target/debug/deps --extern a=/tmp/a/target/debug/deps/liba-09792cb50711fca8.rlib --extern b=/tmp/a/target/debug/deps/libb-f8a1d0b2c22c9971.rlib`
    Finished dev [unoptimized + debuginfo] target(s) in 0.36s

b will be compiled with default features hence enable a's feature-a.

@BusyJay BusyJay added the C-bug Category: bug label Jul 22, 2019
@ehuss
Copy link
Contributor

ehuss commented Jul 22, 2019

Unfortunately I think this is another case of #5364. The -Zpackage-features flag makes it behave correctly. I think what is happening is that --no-default-features in the top a directory is only disabling the default feature for a. b continues to use its default features which transitively enables a/feature-a. If you cd into b you can see it behave differently.

@ehuss ehuss added the A-features Area: features — conditional compilation label Jul 22, 2019
@BusyJay
Copy link
Contributor Author

BusyJay commented Jul 23, 2019

Yes. But when I mix --all with --no-default-features, I will want it be enabled in all projects.

@Skgland
Copy link

Skgland commented Mar 3, 2021

Unfortunately I think this is another case of #5364. The -Zpackage-features flag makes it behave correctly. I think what is happening is that --no-default-features in the top a directory is only disabling the default feature for a. b continues to use its default features which transitively enables a/feature-a. If you cd into b you can see it behave differently.

It appears that #5364 only fixes this for virtual workspaces, but not for workspaces with a root package. I have created a small repo with both scenarios for reference at https://github.com/Skgland/inconsistent-package-features where I would expect both ./test_virtual_workspace.sh and ./test_root_package.sh to build successfully but only the first does.

eeeebbbbrrrr added a commit to pgcentralfoundation/pgrx that referenced this issue Dec 18, 2022
… due to rust-lang/cargo#7160 and how if it were default we wouldn't be able to turn it off from a top-level `cargo test --all --no-default-features --features pg14`.
@Alvenix
Copy link

Alvenix commented Sep 25, 2023

Unfortunately I think this is another case of #5364. The -Zpackage-features flag makes it behave correctly. I think what is happening is that --no-default-features in the top a directory is only disabling the default feature for a. b continues to use its default features which transitively enables a/feature-a. If you cd into b you can see it behave differently.

It appears that #5364 only fixes this for virtual workspaces, but not for workspaces with a root package. I have created a small repo with both scenarios for reference at https://github.com/Skgland/inconsistent-package-features where I would expect both ./test_virtual_workspace.sh and ./test_root_package.sh to build successfully but only the first does.

I am having this problem although I am using a virtual workspace.

cclaudio added a commit to cclaudio/svsm that referenced this issue Feb 20, 2024
Add the default-test cargo feature to control what features we want to enable in
the tests. The vtpm/mstpm/wrappers.rs, for example, can't run in the test
environment because its malloc() etc functions conflict with the libc standard
libraries.

This was working before, but now it is not working as expected.
"cargo test --workspace" is not honoring --no-default-features for workspace members.
rust-lang/cargo#7160

Signed-off-by: Claudio Carvalho <[email protected]>
@epage epage added the S-triage Status: This issue is waiting on initial triage. label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-features Area: features — conditional compilation C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

5 participants