alice
June 11, 2025, 8:45am
1
For dependencies you can use
[target.'cfg(unix)'.dependencies]
to specify target-specific dependencies. How can you do the same for benches?
Using [[target.'cfg(unix)'.bench]]
instead of [[bench]]
does not work and results in this warning:
warning: <dir>/benches/Cargo.toml: unused manifest key: target.cfg(unix).bench
jofas
June 11, 2025, 9:35am
2
The RFC for the [package.supported-targets]
field mentions adding said field to a target table as a future possibility for extending the RFC:
- Feature Name: `supported-targets`
- Start Date: 2025-01-08
- Pre-RFC: [Rust
internals](https://internals.rust-lang.org/t/pre-rfc-allow-packages-to-specify-a-set-of-supported-targets/21979)
- RFC PR: [rust-lang/rfcs#3759](https://github.com/rust-lang/rfcs/pull/3759)
- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000)
The word _target_ is extensively used in this document. The
[glossary](https://doc.rust-lang.org/cargo/appendix/glossary.html#target) defines its many meanings.
Here, _target_ refers to the "Target Architecture" for which a package is built. Otherwise, the
terms "cargo-target" and "target-tuple" are used in accordance with their definitions in the
glossary.
# Summary
The addition of `supported-targets` to `Cargo.toml`. This field is a `cfg` string that restricts the
set of targets which a package supports. Packages can only be built for targets that satisfy their
`supported-targets`.
```toml
This file has been truncated. show original
which would at least fail compiling a benchmark for a platform it is not designed to run on, judging from the RFC's description. I would presume one would design this in a way that cargo bench --target=x86_64-pc-windows-msvc
will ignore all benchmarks that don't support the x86_64-pc-windows-msvc
platform.