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 build --benches also builds tests target for the crate #15258

Open
GuillaumeLagrange opened this issue Mar 3, 2025 · 1 comment
Open
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@GuillaumeLagrange
Copy link

GuillaumeLagrange commented Mar 3, 2025

Problem

Hello,

When running cargo build --benches, one might expect to only build the bench targets.
This is also the case for cargo bench command.

When building the

Steps

  1. Create a hello world crate with some basic tests
  2. Add a basic bench
  3. Add a compilation error in a test
  4. Run cargo build --benches, see compilation error

Possible Solution(s)

I have not deep dived into the cargo code, but bench targets should not build the test target, especially since benches are generally built in a release profile, it kind of makes no sense to build the targets in the release profile as well.

Notes

Sorry if this makes no sense or if it's a duplicate.

If instructions on how to reproduce are not clear enough I can provide a simple repository!

Version

cargo 1.85.0 (d73d2caf9 2024-12-31)
release: 1.85.0
commit-hash: d73d2caf9e41a39daf2a8d6ce60ec80bf354d2a7
commit-date: 2024-12-31
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: NixOS 25.5.0 [64-bit]
@GuillaumeLagrange GuillaumeLagrange added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Mar 3, 2025
@ehuss
Copy link
Contributor

ehuss commented Mar 3, 2025

Thanks for the report! I believe this is somewhat expected behavior (in some ways similar to #6454). Building benchmarks also sets cfg(test) and that is what #[test] annotated functions use to determine if they are compiled or not. I don't know what @rust-lang/testing-devex thinks, I'm not aware of any intentions to adding a separate cfg just for benchmarks (and would be difficult to removing cfg(test) without an edition).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants