Skip to content

cargo build --benches also builds tests target for the crate #15258

Open
@GuillaumeLagrange

Description

@GuillaumeLagrange

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions