Skip to content

Implement host-target substitution #15838

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

Merged
merged 5 commits into from
Aug 18, 2025
Merged

Conversation

zdivelbiss
Copy link
Contributor

What does this PR try to resolve?

This PR resolves: #13051

Namely, it allows users to invoke cargo subcommands that accept a --target directive to specify the host target, which is later substituted in the command processing layer by the host's real target triple (for instance, on most Linux distributions, cargo build --target host would effectively run cargo build --target x86_64-unknown-linux-gnu).

This additionally applies to usage within config.toml, like so:

# .cargo/config.toml

[build]
target = "host"

@rustbot
Copy link
Collaborator

rustbot commented Aug 14, 2025

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2025
@zdivelbiss
Copy link
Contributor Author

zdivelbiss commented Aug 14, 2025

In writing up this PR's explanation, I was unsure how to properly outline the following:

### How to test and review this PR?

... due to my unfamiliarity with how testing the program that tests programs would exactly work. Perhaps, simply clone the PR and try to run --target host?

Thanks.

@zdivelbiss
Copy link
Contributor Author

zdivelbiss commented Aug 15, 2025

I have additionally tested locally that the following host specifications do not compile:

  • [target.<triple>] in .cargo/config.toml
  • [target.<triple>.dependencies] in Cargo.toml

Should I somehow mirror this within the PR, rather than just ensuring locally that builds with the above conditions do not compile? I think I could write an always-fail test that does this, but I wanted to make sure that's the way we want it done.

@rustbot rustbot added A-documenting-cargo-itself Area: Cargo's documentation A-cli-help Area: built-in command-line help labels Aug 16, 2025
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Sorry I added more writing style suggestions then.

Also, feel free to rebase and organize your git history to make it more clearer to read and trace.

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Thanks. I believe this is the last review round!

BTW, would you mind cleanup your commit history. There are some intermediate commits that may be good if we squash them for easy git diff tracing in the future.

Possible values:
- Any supported target in `rustc --print target-list`.
- `"host"`, which will internally be substituted by the host's target. This can be particularly useful if you're cross-compiling some crates, and don't want to specify your host's machine as a target (for instance, an `xtask` in a shared project that may be worked on by many hosts).
- A path to a custom target specification. See [Custom Target Lookup Path](https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path) for more information.
Copy link
Member

Choose a reason for hiding this comment

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

We usually use relative paths to link to docs under the same toolchain versions.

Suggested change
- A path to a custom target specification. See [Custom Target Lookup Path](https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path) for more information.
- A path to a custom target specification. See [Custom Target Lookup Path](../../rustc/targets/custom.html#custom-target-lookup-path) for more information.

(Doesn't matter for man pages as they don't support relative paths beyond cargo book)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wondered about that! Thank you.

Copy link
Member

Choose a reason for hiding this comment

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

I just realized manpage also support it. Nice. However, we forgot to update config.md (which is this file).

@zdivelbiss
Copy link
Contributor Author

@weihanglo Yes, I plan to clean up the history some time today. It's been a while since I've done a rebase & squash, so I'll need to do some research to make sure I don't permanently damage something with Git.

@weihanglo
Copy link
Member

It's been a while since I've done a rebase & squash, so I'll need to do some research to make sure I don't permanently damage something with Git.

See some resources Rust Compiler Development Guide: https://rustc-dev-guide.rust-lang.org/git.html#rebasing-and-conflicts. And I just explained why/how we maintain good Git history in Cargo in another PR 😆

@weihanglo
Copy link
Member

I can also do the rebase for you, if you don't mind no longer being the committer of those commits. You will still be the author of those and GitHub gives contribution credits to authors AFAIK.

@zdivelbiss
Copy link
Contributor Author

That's alright, I can do it. It's valuable knowledge, this git-fu. Thank you for the resources. I'm working on it now.

@zdivelbiss zdivelbiss force-pushed the master branch 2 times, most recently from 31c33a7 to 6993a86 Compare August 17, 2025 17:57
@zdivelbiss
Copy link
Contributor Author

zdivelbiss commented Aug 17, 2025

This commit history looks good to me. Any concerns?

Possible values:
- Any supported target in `rustc --print target-list`.
- `"host"`, which will internally be substituted by the host's target. This can be particularly useful if you're cross-compiling some crates, and don't want to specify your host's machine as a target (for instance, an `xtask` in a shared project that may be worked on by many hosts).
- A path to a custom target specification. See [Custom Target Lookup Path](https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-path) for more information.
Copy link
Member

Choose a reason for hiding this comment

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

I just realized manpage also support it. Nice. However, we forgot to update config.md (which is this file).

We also rebuilt the manual pages, to ensure they're up-to-date with the changes made in the `host` target specifier PR.
@zdivelbiss
Copy link
Contributor Author

zdivelbiss commented Aug 17, 2025

Thank you for catching the URL usage in the config.md changes. I didn't quite understand what the URI you suggested was relative to, but I see now that's is relative to docs.rust-lang.org.

It may be worth considering expanding the contribution guide to include more information on how documentation is written and contributed. There were many elements in this PR that were directly related to things that aren't covered in the contribution guide: syntax (e.g. that a special documentation preprocessor is used), relative pathing (confusion above), the need to run cargo build-man, general styling (may not be possible to document? thinking of my extensive paren usage, which is out-of-place in the docs). It may help cut down on documentation-based nits, though I'm obviously not sure how often this actually affects contributors' efficiency.

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Thanks for working with us for this feature!

I noticed and understood the frictions when contributing to doc. To me, writing docs is never an easy task. Natural langauges, unlike programming languages, is too ambiguous and people tend to be opinioned on writing. Even among maintainers we often disagree each other's writing. You're right that there should be a clearer writing guideline. We do have one but is not really useful.

Based on your comment #15838 (comment), I've created a doc PR #15854 to improve this situation a bit. Hope it will help others. And again sorry for the frustration 😞.

@weihanglo weihanglo added this pull request to the merge queue Aug 18, 2025
Merged via the queue into rust-lang:master with commit 206e3fe Aug 18, 2025
23 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 18, 2025
@zdivelbiss
Copy link
Contributor Author

@weihanglo No frustration at all; just thinking of how to make the process smoother for contributors in the future. Thanks for your help in getting this PR merged so quickly—it was great to receive such quick feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add target="host" meaning the current host
4 participants