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

[profile.test.package."*"] is not used for tests #8904

Closed
Urcra opened this issue Nov 27, 2020 · 2 comments
Closed

[profile.test.package."*"] is not used for tests #8904

Urcra opened this issue Nov 27, 2020 · 2 comments
Labels
C-bug Category: bug

Comments

@Urcra
Copy link

Urcra commented Nov 27, 2020

Problem

When specifying overrides for cargo test to optimise tests in some workspace member on would expect to use

[profile.test.package.MEMBER]
opt-level = 2

[profile.test.package."*"]
opt-level = 2

But this won't actually apply the opt-level = 2 to the dependencies when invoking cargo test, instead if one needs dependencies to be optimized for the tests the following should be specified

[profile.test.package.MEMBER]
opt-level = 2

[profile.dev.package."*"]
opt-level = 2

Steps

  1. Create some tests that requires dependencies to be optimized to run
  2. Use Cargo.toml with [profile.test.package."*"]
  3. Check that the tests are still not running due to non-optimized dependencies
  4. Use Cargo.toml with [profile.dev.package."*"]
  5. Verify that the tests are now running due to optimized dependencies

Possible Solution(s)

I'm guessing this happens since the dependencies used by cargo test is compiled with dev such that the same dependencies can be reused for debug builds and for testing, which seems fine.

Having a warning be triggered to note users that [profile.test.package."*"] doesn't do anything seems like a fair fix

Alternatively allowing [profile.test.package."*"] and applying it to test dependencies instead of [profile.dev.package."*"]

Notes

Output of cargo version: cargo 1.48.0 (65cbdd2 2020-10-14)

@Urcra Urcra added the C-bug Category: bug label Nov 27, 2020
@ehuss
Copy link
Contributor

ehuss commented Nov 27, 2020

This is expected behavior. The test profile only applies to the final test executable. This is described a little bit at https://doc.rust-lang.org/cargo/reference/profiles.html#profile-selection. I realize it may be a little confusing, but there are historical reasons why it works that way. We're looking to change that behavior as part of custom named profiles.

@ehuss
Copy link
Contributor

ehuss commented Nov 30, 2020

I'm going to close this as it is expected behavior. You can subscribe to #6988 for further updates towards this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants