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

Support -Zmultitarget in cargo config #10473

Merged
merged 8 commits into from
Mar 31, 2022

Conversation

weihanglo
Copy link
Member

@weihanglo weihanglo commented Mar 11, 2022

What does this PR try to resolve?

Support -Zmultitarget in cargo config. This patch also takes care of backward compatibility, so basically it means that build.target accepts input from both string and array.

#8176 (comment)

[unstable]
multitarget = true

[build]
target = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]

How should we test and review this PR?

Several new tests in multitarget.

I didn't add tests for all compile modes, since doing that would produce too many duplications. If anyone thinks it necessary to avoid potential regression please tell me.

Unresolved questions

  • How to handle CARGO_BUILD_TARGET environment variable? Should it remain accepting a single target value only and hope advanced-env save us?
  • This unstable feature on CLI has landed for a while. What are other difficulties blocking it from stabilizing?

@rust-highfive
Copy link

r? @ehuss

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 11, 2022
@edwincoronado
Copy link

thanks for getting to this so fast @weihanglo ! I have one quick question, it looks like I would still have to do cargo build -Zmultitarget correct? Would adding the

[unstable]
multitarget = true

basically do the same so that I only have to do cargo build?

@weihanglo
Copy link
Member Author

weihanglo commented Mar 12, 2022

@edwincoronado that's correct. You might need on nightly channel at this moment to turn on -Zmultitarget feature.

Anything which can be configured with a -Z flag can also be set in the cargo config file (.cargo/config.toml) in the unstable table. For example:

Ref: https://doc.rust-lang.org/1.59.0/cargo/reference/unstable.html#unstable-features

@egdeeno
Copy link

egdeeno commented Mar 13, 2022

maybe use word "targets" instead of "target" ?
targets = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
vs
target = "x86_64-unknown-linux-gnu"

@weihanglo
Copy link
Member Author

@edgeone89 I've considered the solution and it's indeed more intuitive. However, when we want to maintain the backwards compatibility we need to preserve build.target. Then it ends up becoming two configs build.target and build.targets, as well as their counterparts CARGO_BUILD_TARGET and CARGO_BUILD_TARGETS environment variables. To make things simple, I prefer to reuse build.target and accept both string and array values.

@egdeeno
Copy link

egdeeno commented Mar 14, 2022

@weihanglo ok, thanks.
In case of target = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"] what will be default target? 0-indexed ?

@weihanglo
Copy link
Member Author

In case of target = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"] what will be default target? 0-indexed ?

Every target listed in build.target will be built by default. If this behavior is so-called a default target, I think all of them are default targets.

Note that when using build.target config or --target cli arg, the build cache and artifacts will be placed under target/$TRIPLE/ for each target platform instead of the root target/.

@edwincoronado
Copy link

any update on this?

tests/testsuite/multitarget.rs Outdated Show resolved Hide resolved
src/cargo/util/config/mod.rs Outdated Show resolved Hide resolved
src/cargo/util/config/mod.rs Outdated Show resolved Hide resolved
src/cargo/core/compiler/compile_kind.rs Outdated Show resolved Hide resolved
@weihanglo
Copy link
Member Author

All review comments are resolved.

I was trying to avoid extra allocation, but it turns that the relevant code is not in the hot path during compilations. Your suggestion indeed reduces the code complexity. Thank you!

The relevant is not in the hot path for a cargo build, so it acceptable
to allocation String in order to reduce code coomplexity
let values = match &self.inner.val {
BuildTargetConfigInner::One(s) => vec![map(s)],
BuildTargetConfigInner::Many(v) => {
if v.len() > 1 && !config.cli_unstable().multitarget {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this skip the length check, just to prevent target = ["foo"], which would be new syntax?

Suggested change
if v.len() > 1 && !config.cli_unstable().multitarget {
if !config.cli_unstable().multitarget {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, missed that one. Thanks!
Should be fixed now and I tweak the error message a bit.

@ehuss
Copy link
Contributor

ehuss commented Mar 31, 2022

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 31, 2022

📌 Commit c18275b has been approved by ehuss

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 31, 2022
@bors
Copy link
Collaborator

bors commented Mar 31, 2022

⌛ Testing commit c18275b with merge 1ef1e0a...

@bors
Copy link
Collaborator

bors commented Mar 31, 2022

☀️ Test successful - checks-actions
Approved by: ehuss
Pushing 1ef1e0a to master...

@bors bors merged commit 1ef1e0a into rust-lang:master Mar 31, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 31, 2022
Update cargo

13 commits in 109bfbd055325ef87a6e7f63d67da7e838f8300b..1ef1e0a12723ce9548d7da2b63119de9002bead8
2022-03-17 21:43:09 +0000 to 2022-03-31 00:17:18 +0000
- Support `-Zmultitarget` in cargo config (rust-lang/cargo#10473)
- doc: Fix document url for libcurl format (rust-lang/cargo#10515)
- Fix wrong info in "Environment variables" docs (rust-lang/cargo#10513)
- Use the correct flag in --locked --offline error message (rust-lang/cargo#10512)
- Don't treat host/target duplicates as duplicates (rust-lang/cargo#10466)
- Unstable --keep-going flag (rust-lang/cargo#10383)
- Part 1 of RFC2906 - Packages can inherit fields from their root workspace (rust-lang/cargo#10497)
- Remove unused profile support for -Zpanic-abort-tests (rust-lang/cargo#10495)
- HTTP registry implementation (rust-lang/cargo#10470)
- Add a notice about review capacity. (rust-lang/cargo#10501)
- Add tests for ignoring symlinks (rust-lang/cargo#10047)
- Update doc string for deps_of/compute_deps. (rust-lang/cargo#10494)
- Consistently use crate::display_error on errors during drain (rust-lang/cargo#10394)
@weihanglo weihanglo deleted the multitarget-config branch March 31, 2022 11:52
@ehuss ehuss added this to the 1.61.0 milestone Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants