13072 Commits

Author SHA1 Message Date
Weihang Lo
ec49c758bb
Add missing truncate when writing .crate files (#16688)
<!--
_Thanks for the pull request 🎉!_
_Please read the contribution guide: <https://doc.crates.io/contrib/>._
-->

### What does this PR try to resolve?

Fixes #16683 by adding manuall truncate.
<!--
_Explain the motivation behind this change._
_A clear overview along with an in-depth explanation are helpful._
-->

### How to test and review this PR?

See the original issue for mCVE.
<!--
_Demonstrate how you test this change and guide reviewers through your
PR._
_With a smooth review process, a pull request usually gets reviewed
quicker._
-->
2026-03-06 11:27:50 -05:00
Ed Page
493d9c6162 fix(script): surpress unused_features lint for embedded (#16714)
### What does this PR try to resolve?

https://github.com/rust-lang/rust/pull/152164 added a warn-by-default
`unused_features` lint.
Cargo injects  `#![feature(frontmatter)]` for all embedded scripts,
but scripts without frontmatter syntax never trigger feature gate check,
and causes causing the lint warning.

Given the stabilization FCP of frontmatter [is
complete](https://github.com/rust-lang/rust/pull/148051#issuecomment-3868109254)
already,
we could expect it will soon be stabilized (?).

It should be fine we suppress this new unstable lint.

### How to test and review this PR?

Test suite passes.
See
<https://github.com/rust-lang/cargo/pull/16713#issuecomment-4009762370>
for more.
2026-03-06 06:32:59 -08:00
Arlo Siemsen
92ffa00c63 fix(host-config): fix panic when cross compiling
When cross compiling (with `--target`), cargo panics with -Zhost-config.

This changes the explicit addition of the host target to only occur if
the `requested_kinds` includes the host.

Otherwise looking up the target_runner for the explicit_host_kind
attempts to look up an entry in the target_config map that does not
exist.
2026-02-24 15:16:46 -06:00
Vivek
b3882b18a7 doc: add reading target configuration example 2026-02-24 18:12:41 +05:30
Vivek
9dbb29cd26 doc: clarify cfg! vs CARGO_CFG_* in build scripts 2026-02-24 18:07:01 +05:30
Vivek
c695dbfe10 doc: clarify cfg! vs CARGO_CFG_* in build scripts 2026-02-24 17:08:10 +05:30
Ed Page
5d9fc0bc2e
Fix typo in cargo-yank docs (#16656)
This fixes a (very small) typo in the docs for `cargo-yank`.
Specifically, since "unintentional SemVer breakages" is plural, the "an"
that was at the beginning of that sentence was incorrect.

### What does this PR try to resolve?

There wasn't an issue, just a very tiny typo

### How to test and review this PR?

Hopefully this shouldn't need any testing... it's just a change to a
markdown file
2026-02-23 20:40:44 +00:00
Alex Rao
bd1036d73f
doc: Fix typo in cargo-yank docs
This fixes a (very small) typo in the docs for `cargo-yank`. Specifically,
since "unintentional SemVer breakages" is plural, the "an" that was
at the beginning of that sentence was incorrect.
2026-02-23 14:23:52 -05:00
Alejandra Gonzalez
4e786ef0e5 fix(job_queue): Handle Clippy CLI arguments in fix message
fixes #16637

Clippy lints can be enabled via the command line via `cargo clippy -- -Wclippy::lint`, and these need to be included in the `cargo fix` command for the emitting lints to actually be fixed.
Thus, add them to the "run `..` to apply .. suggestions" message.

Only suggest when running from clippy-driver
2026-02-23 20:14:38 +01:00
Ross Sullivan
31d3b42857
fix: Fix parallel locking when -Zfine-grain-locking is enabled
This commit replaces a `Mutex` with an `RwLock` lock to avoid holding a
mutex guard while waiting on a file lock. Instead we hold a read guard
which allows multiple threads to access the `HashMap` inside of
`LockManager`.
2026-02-21 13:27:27 +09:00
Ed Page
8cc0cb1367
docs(layout): Updated layout module docs to document new layout (#16502)
### What does this PR try to resolve?

This PR updates the layout module docs to reflect the update layout
structure changes made as part of
https://github.com/rust-lang/cargo/issues/15010

### How to test and review this PR?

no response

### Follow up needed

- [ ] Add a note in the tracking issue to updating these docs in the
stabilization PR
2026-02-17 12:16:26 +00:00
Ross Sullivan
6339e32703 doc: Added new build-dir layout to layout module doc 2026-02-17 09:57:42 +09:00
Ross Sullivan
df38999234 doc: Split layout into build/artifact dir in module doc 2026-02-17 09:57:32 +09:00
Ed Page
220007935d
fix(host-config): host.linker should not apply to non host unit (#16641)
### What does this PR try to resolve?

Similar to <https://github.com/rust-lang/cargo/pull/16638>,
this prevents `host.linker` from applying to non-host build targets.

### How to test and review this PR?

This behavior has been there since the integration of host-config, so it
_might_ break somebody's assumption.

I've checked the use of `target_linker`:

* doctest continues using `target_linker` as it is more a target builds:
312145c006/src/cargo/core/compiler/build_runner/mod.rs (L281-L289)
* `RUSTC_LINKER` set for build scripts is on the same boat. It indicates
the linker to use for the associated crate, which is always a target
build:
312145c006/src/cargo/core/compiler/custom_build.rs (L389-L391)

Other than the two above, the other usages of it (fingerprint, and rustc
invocation) should respect host.linker when building build script
exectuables.
2026-02-16 18:21:45 +00:00
Weihang Lo
592058c7ce
init: improve error message and add tests (#16643)
Improves the error message when Cargo.toml exists and adds tests for
reserved names
2026-02-15 14:24:02 +00:00
Raushan Kumar
8a68e34ded init: improve error message style 2026-02-15 13:48:36 +00:00
Ross Sullivan
129cdf1b4a
doc: Updated outdated profile layout documentation 2026-02-15 21:19:21 +09:00
Ross Sullivan
7213008423
doc: Corrected doc comment for build script root_output path 2026-02-14 21:26:00 +09:00
Ross Sullivan
f7bcfe40a6
feat: Changed build script run 'output' dir to 'stdout'
This commit changes the directory name of the `output` file to `stdout` in
order to match the naming of `stderr` and better represent the contents
it contains.
2026-02-14 18:03:12 +09:00
Ross Sullivan
84ce3bccb5
refactor: Move build script run files to a dedicated struct 2026-02-14 17:59:19 +09:00
Weihang Lo
b0f44730e7
refactor: extract linker/incremental codegen arg into functions
For readability
2026-02-14 09:42:29 +08:00
Weihang Lo
13525b7890
refactor: rename from target_linkers to linkers
as this collects both host and target build targets
2026-02-14 08:22:53 +08:00
Weihang Lo
7a1443577d
fix(host-config): host.linker should not apply to non host unit
`host.runner` was incorrectly applied to non host units like proc macros
and build scripts when `-Zhost-config` was enabled but no `--target` flag
was specified.

The root cause was that `target_linker()` used `target_config(kind)`
which routes through `host_config` for `CompileKind::Host`. But
`CompileKind::Host` is used for both build scripts and normal binaries
when no `--target` is specified.
2026-02-14 08:22:52 +08:00
Weihang Lo
c3ac327ec0
refactor: target_runners to runners
As it covers both host and target runners.
2026-02-13 17:46:51 +08:00
Weihang Lo
f5ae2fc7b2
fix(host-config): host.runner should not apply to cargo run
`host.runner` was incorrectly applied to `cargo run` and other target
processes when `-Zhost-config` was enabled but no `--target` flag was
specified.

The root cause was that `target_runner()` used `target_config(kind)`
which routes through `host_config` for `CompileKind::Host`. But
`CompileKind::Host` is used for both build scripts and normal binaries
when no `--target` is specified.
2026-02-13 17:46:47 +08:00
Weihang Lo
c00a07a8a8
refactor(help): simplify code structure (#16627)
### What does this PR try to resolve?

Simplify code structure in order to the future support of displaying
nested command man pages (broken out from
<https://github.com/rust-lang/cargo/pull/16432>).

### How to test and review this PR?
2026-02-12 23:35:07 +00:00
Ed Page
ce69df6f72
fix: apply host.runner only when host-config enabled (#16631)
### What does this PR try to resolve?

This is a regression found in rust-lang/compiler-builtins#1087
and introduced by rust-lang/cargo#16599

There are other regression that `host.runner` and `host.linker`
are accidentally applied to target builds which I plan to fix
both in a follow-up PR.
(rust-lang/cargo#12535 introduced the `host.linker` bug btw)
2026-02-12 12:39:45 +00:00
Weihang Lo
9b0fe7ba74
fix: apply host.runner only when host-config enabled
This is a regression found in rust-lang/miri#4855
and introduced by rust-lang/cargo#16599

There are other regression that `host.runner` and `host.linker`
are accidentally applied to target builds which I plan to fix
both in a follow-up PR.
(rust-lang/cargo#12535 introduced the `host.linker` bug btw)
2026-02-12 16:20:36 +08:00
Weihang Lo
4ac2278be2
refactor(help): use #[expect] rather than #[allow] 2026-02-12 10:24:57 +08:00
Weihang Lo
5288e8204b
refactor(help): avoid checking built-in commands twice 2026-02-12 10:17:24 +08:00
Weihang Lo
db87b6ce45
refactor(help): move alias expansion out from try_help 2026-02-12 10:13:29 +08:00
Weihang Lo
112ea913a5
refactor(help): inline check alias/builtin functions 2026-02-12 09:57:51 +08:00
Ed Page
0e8570b1ec fix(cli): Improve bad manifest error
Fixes #16612
2026-02-11 19:52:28 -06:00
Weihang Lo
fe49f1a3ea
refactor(help): early return rather than nested if-else 2026-02-12 08:17:17 +08:00
Weihang Lo
06b4f3eed3
fix: Adjust casing of error message (#16625)
### What does this PR try to resolve?

### How to test and review this PR?

Found while working on #16612 and realized I had a good regex for
identifying them: `rg 'ERROR..[A-Z]' tests/`

I also fixed the wording on some but more could likely use some wording
improvements.
2026-02-11 23:10:13 +00:00
Ed Page
efb7bebf7e
test(help): snapshot cargo help tests (#16626)
### What does this PR try to resolve?

This is extracted from <https://github.com/rust-lang/cargo/pull/16432>.
2026-02-11 15:54:09 +00:00
Weihang Lo
4d23857a06
test(help): snapshot cargo help tests 2026-02-11 23:15:40 +08:00
Ed Page
5bfb134fca
Suggest a workspace.members entry even from outside the workspace root (#16616)
### What does this PR try to resolve?

Fixes the FIXME in `workspace.rs` by switching to `pathdiff`. This
creates a relative path independent even when outside of the workspace
root.

### How to test and review this PR?

- Added regression tests in `tests/testsuite/workspace.rs`.
- Verified error message formatting for members outside the workspace.
2026-02-11 14:27:07 +00:00
Ed Page
b79b1d4627
Reorganize build unit directory layout for new build-dir layout (#16542)
### What does this PR try to resolve?

This PR makes more changes to the new `build-dir` layout as discussed in
https://github.com/rust-lang/cargo/pull/16502#discussion_r2686485984.

The goal here is to have more general (and thus reusable) directories in
the build unit structure.

#### Layout changes

1. Rename `{build-unit-dir}/deps` to `{build-unit-dir}/out`
2. Moved build-script `OUT_DIR` from `{build-unit-dir}/build-script/out`
to `{build-unit-dir}/out`
3. Renamed `{build-unit-dir}/build-script` to `{build-unit-dir}/run`
* This makes the dir more general to any build unit that can execute an
external process. (but currently only build-scripts use it)

The resulting structure looks like

```
build-dir/debug/build/<pkgname>/<HASH>
    fingerprint/
    out/
    run/
    .lock
```

Part of https://github.com/rust-lang/cargo/issues/15010

### How to test and review this PR?

See the test updates included in each commit
2026-02-11 14:16:48 +00:00
Jacob Adam
1b525a2483
Make the error messaging for cargo install aware of build.build-dir
```
error: could not compile `issue-16622` (bin "issue-16622") due to 1 previous error
error: failed to compile `issue-16622 v0.0.0 ([…]/issue_16622)`, intermediate artifacts can be found at `[…]/issue_16622/target`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
```

currently points to the target directory.

However, intermediate artifacts are stored in the directory configured by `build.build-dir`,
so the message should be updated to point to that path and corresponding environment variable instead.
2026-02-11 13:35:48 +00:00
Ross Sullivan
e4327a5071 feat: Renamed build script execution directory to run
This commit changes the build script execution dir from `{build-unit-dir}/build-script`
to `{build-unit-dir}/run`. The motivation behind this is to have a
general directory for units that execute some binary/external process
and output to stdout/err. Currently this is only used by build-scripts
but could be expanded in the future.
2026-02-11 21:34:22 +09:00
Ross Sullivan
b6df8c3f07 feat: Moved build-script OUT_DIR to out dir in new layout
This commit moves the build-script OUT_DIR location from `{build-unit-dir}/build-script-execution/out`
to `{build-unit-dir}/out` dir (that was previously `{build-unit-dir}/deps`)
2026-02-11 21:31:42 +09:00
Ross Sullivan
94c4e874ab fix: Always create build-script run dir
This was previously indirectly created by `OUT_DIR`, however in the
future `OUT_DIR` will not be nested in the build-script run dir so we
always want to create it.
2026-02-11 21:27:11 +09:00
Ross Sullivan
1689526ec1 feat: Renamed deps to out in new layout
Previously `deps` was only the compiler output. This commit renames it
to `out` to make it more general to any kind of build output.

The build script OUT_DIR will eventually be merged into this directory.
2026-02-11 21:26:12 +09:00
Ross Sullivan
2503102435 refactor: Rename CompilationFiles::out_dir to output_dir
Rename `fn out_dir` to `fn output_dir` to avoid naming collisions in
future layout changes.
2026-02-11 21:14:20 +09:00
Weihang Lo
3b7b41fcd6
docs(help): show missing options 2026-02-11 13:30:37 +08:00
Weihang Lo
1f2133738b
docs(cargo-rm): change example to wasm32-unknown-unknown
So that when snapshotting, windows target won't be redacted by snapbox
2026-02-11 13:30:37 +08:00
Weihang Lo
7de468c7e2
fix(script): Load config relative to the script (#16620)
### What does this PR try to resolve?

This was the original behavior.
There was some concern over this previously and we switched to only
loading config from CARGO_HOME in #14749.
After discussing this in today's cargo team meeting, we decided to
switch it back.

A concern brought up previously was if you previously downloaded a
config and now download and run a script, you could get surprising
behavior, maybe even dangerous.
This does require some extra hoops because you don't have a
`.cargo.toml` but a `.cargo/config.toml`.
You can't directly download that but must first download a zip file and
then decompress it without it having a parent directory.

Contrast that with users who have a script in their repo and config that
should apply to it.
This is an important use case but one we will get less feedback on
during calls for testing.

In discussing this, we felt there are different use cases:
- The repo with a config file
- People surprised at how config loading works

We settled on this change because it is consistent with the current
behavior, even if it can be confusing and undesirable. We can then work
to improve the overall config search path experience and both regular
cargo commands and running of cargo scripts would benefit.

### How to test and review this PR?

This reverts commit bd47da1ab129ac6c086f74892327f3896f9f847c.
2026-02-11 02:53:39 +00:00
Raushan Kumar
c5990126b5 chore: use pathdiff for workspace member resolution 2026-02-11 02:33:52 +00:00
Ed Page
c29e8d8774 fix(test): Adjust casing of error message 2026-02-10 16:44:44 -06:00