rust-lang / rust-lang/cargo

The new `per-package-target` feature does not work with `-Zbuild-std`

Open
#9,451 17 comments 16 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug S-needs-mentor Z-build-std
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

Problem

I just tried to use the new per-package-target feature implemented in https://github.com/rust-lang/cargo/pull/9030 (tracking issue) together with -Zbuild-std, but it results in an error: -Zbuild-std requires --target.

Steps

  1. Add a default-target or forced-target key in Cargo.toml.
  2. Try to compile by running cargo build -Zbuild-std=core.

Possible Solution(s)

I think the issue is that the target check already happens here: https://github.com/rust-lang/cargo/blob/db741ac733f3744c2d7ee593d5a01b18e6158b69/src/cargo/ops/cargo_compile.rs#L394-L399

But the default-target/forced-target fields are only considered later in generate_targets: https://github.com/rust-lang/cargo/blob/db741ac733f3744c2d7ee593d5a01b18e6158b69/src/cargo/ops/cargo_compile.rs#L925-L943

The generate_targets function is invoked here: https://github.com/rust-lang/cargo/blob/db741ac733f3744c2d7ee593d5a01b18e6158b69/src/cargo/ops/cargo_compile.rs#L470-L488
Notes

Output of cargo version:

cargo 1.53.0-nightly (4369396ce 2021-04-27)
release: 1.53.0
commit-hash: 4369396ce7d270972955d876eaa4954bea56bcd9
commit-date: 2021-04-27

cc @Ekleog

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/cargo/ops/cargo_compile.rs, comparing the early -Zbuild-std target check with the later generate_targets handling of default-target and forced-target. Reproduce the issue with Cargo.toml containing one of those keys and cargo build -Zbuild-std=core. Done means the command no longer reports that -Zbuild-std requires --target when the per-package target configuration supplies the target.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.