20211 Commits

Author SHA1 Message Date
motorailgun
e68d951a12 add glob pattern support for known_hosts 2025-05-10 15:42:36 +00:00
Weihang Lo
056f5f4f3c
Revert "doc: Mention XDG_DATA_HOME" (#15512)
This reverts commit 15a7672dde9853a8b15b545a1e5da5bbee7244c9.

### What does this PR try to resolve?

There was a miscommunication about some outstanding concerns with #15480
and it got merged before we were ready.

Specifically
- How important is this for unstable docs?
- How universal is the use of `bash-completions` and what should we do
for people who don't have it?
- How likely is someone to catch that they don't have `XDG_DATA_HOME`
set and get tripped up over this documentation
- Should we be aligned with upstream clap?

### How should we test and review this PR?

### Additional information
2025-05-09 14:54:18 +00:00
Ed Page
05b18b42cc Revert "doc: Mention XDG_DATA_HOME"
This reverts commit 15a7672dde9853a8b15b545a1e5da5bbee7244c9.
2025-05-09 09:19:07 -05:00
Ed Page
c7a2aa3f8f
docs: update version notice for deprecation removal (#15511)
Thank you for always maintaining cargo.

### What does this PR try to resolve?
`std::env::home_dir` is still deprecated in
[v1.86.0](https://doc.rust-lang.org/1.86.0/src/std/env.rs.html#644-648).

However, it has been undeprecated in the current
[nightly](https://doc.rust-lang.org/nightly/src/std/env.rs.html#651).

Therefore, I propose updating the notice for avoiding confusion.
2025-05-09 14:10:33 +00:00
Weihang Lo
c566be4742
doc: Update instructions on using native-completions (#15480)
`~/.local/share/bash-completion/completions/cargo` is more sensible, and
[recommended by
rustup](e4f3ad6f89/src/cli/help.rs (L275)).

<!--
Thanks for submitting a pull request 🎉! Here are some tips for you:

* If this is your first contribution, read "Cargo Contribution Guide"
first:
  https://doc.crates.io/contrib/
* Run `cargo fmt --all` to format your code changes.
* Small commits and pull requests are always preferable and easy to
review.
* If your idea is large and needs feedback from the community, read how:
  https://doc.crates.io/contrib/process/#working-on-large-features
* Cargo takes care of compatibility. Read our design principles:
  https://doc.crates.io/contrib/design.html
* When changing help text of cargo commands, follow the steps to
generate docs:

https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages
* If your PR is not finished, set it as "draft" PR or add "WIP" in its
title.
* It's ok to use the CI resources to test your PR, but please don't
abuse them.

### What does this PR try to resolve?

Explain the motivation behind this change.
A clear overview along with an in-depth explanation are helpful.

You can use `Fixes #<issue number>` to associate this PR to an existing
issue.

### How should we test and review this PR?

Demonstrate how you test this change and guide reviewers through your
PR.
With a smooth review process, a pull request usually gets reviewed
quicker.

If you don't know how to write and run your tests, please read the
guide:
https://doc.crates.io/contrib/tests

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
-->
2025-05-09 13:15:26 +00:00
kyu08
ded3f36068 docs: update version notice for deprecation removal 2025-05-09 22:10:46 +09:00
PRO
15a7672dde
doc: Mention XDG_DATA_HOME
Ref: [bash-completion](89aa18b154/README.md (L153-L161))
2025-05-09 13:50:50 +08:00
Eric Huss
a154422cec
feat(network): use Retry-After header for HTTP 429 responses (#15463)
### What does this PR try to resolve?

Cargo registries that return HTTP 429 when the service is overloaded
expect the client to retry the request automatically after a delay.
Cargo currently does not retry for HTTP 429.

### What changed?
* Adds HTTP 429 (too many requests) as a spurious HTTP error to enable
retries.
* Parse the
[Retry-After](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Retry-After)
HTTP header to determine how long to wait before a retry.

In this implementation, the maximum delay is limited to Cargo's existing
limit of 10 seconds. We could consider increasing that limit for this
case, since the server is explicitly requesting the delay.
2025-05-07 21:22:52 +00:00
Arlo Siemsen
b72d6476ae feat(network): use Retry-After header for HTTP 429 responses 2025-05-07 15:44:35 -05:00
Ed Page
b1bb014cdb
CI: Require schema job to pass (#15504)
I'm not certain, but I do not believe it was intentional in
https://github.com/rust-lang/cargo/pull/15000 to allow the `schema` job
to fail. This adds it to the required passing list.
2025-05-07 20:15:03 +00:00
Eric Huss
1c3197babc
chore(config): migrate renovate config (#15501)
The Renovate config in this repository needs migrating. Typically this
is because one or more configuration options you are using have been
renamed.

You don't need to merge this PR right away, because Renovate will
continue to migrate these fields internally each time it runs. But later
some of these fields may be fully deprecated and the migrations removed.
So it's a good idea to merge this migration PR soon.

#### [PLEASE
NOTE](https://docs.renovatebot.com/configuration-options#configmigration):
JSON5 config file migrated! All comments & trailing commas were removed.

🔕 **Ignore**: Close this PR and you won't be reminded about config
migration again, but one day your current config may no longer be valid.

 Got questions? Does something look wrong to you? Please don't hesitate
to [request help
here](https://redirect.github.com/renovatebot/renovate/discussions).

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/rust-lang/cargo).
2025-05-07 19:40:32 +00:00
Eric Huss
c9261238cf
CI: Require schema job to pass
I'm not certain, but I do not believe it was intentional in https://github.com/rust-lang/cargo/pull/15000 to allow the `schema` job to fail. This adds it to the required passing list.
2025-05-07 12:39:52 -07:00
renovate[bot]
19704b9496 chore(config): migrate config .github/renovate.json5 2025-05-07 12:01:16 -07:00
Ed Page
cf7b053c0f
Make cargo script ignore workspaces (#15496)
### What does this PR try to resolve?

Cargo script considers itself part of the workspace if the script is
located in a sub-directory of a workspace (presumably since
https://github.com/rust-lang/cargo/pull/15168). This becomes an issue
when using a custom registry that is defined in the `.cargo/config.toml`
within the workspace. Cargo script does not take that file into account
and fails with ``registry index was not found in any configuration:
`test-reg` ``.

### How should we test and review this PR?

This PR adds a regression test and makes cargo script ignore the
surrounding workspace.
The test ~~will fail without the fix in the second commit and~~ can be
used to reproduce the issue.

### Additional information

The issue started occurring with `nightly-2025-02-16`.
Related to https://github.com/rust-lang/cargo/issues/12207.

<!--
Thanks for submitting a pull request 🎉! Here are some tips for you:

* If this is your first contribution, read "Cargo Contribution Guide"
first:
  https://doc.crates.io/contrib/
* Run `cargo fmt --all` to format your code changes.
* Small commits and pull requests are always preferable and easy to
review.
* If your idea is large and needs feedback from the community, read how:
  https://doc.crates.io/contrib/process/#working-on-large-features
* Cargo takes care of compatibility. Read our design principles:
  https://doc.crates.io/contrib/design.html
* When changing help text of cargo commands, follow the steps to
generate docs:

https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages
* If your PR is not finished, set it as "draft" PR or add "WIP" in its
title.
* It's ok to use the CI resources to test your PR, but please don't
abuse them.

Explain the motivation behind this change.
A clear overview along with an in-depth explanation are helpful.

You can use `Fixes #<issue number>` to associate this PR to an existing
issue.

### How should we test and review this PR?

Demonstrate how you test this change and guide reviewers through your
PR.
With a smooth review process, a pull request usually gets reviewed
quicker.

If you don't know how to write and run your tests, please read the
guide:
https://doc.crates.io/contrib/tests

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
-->
2025-05-07 14:23:29 +00:00
arctic-alpaca
2b247ffd4e
make cargo script ignore surrounding workspace 2025-05-07 07:48:08 +02:00
arctic-alpaca
03a2a29aed
add test for cargo script workspace handling 2025-05-07 07:43:44 +02:00
Weihang Lo
74c051fd83
fix(rustc): Don't panic on unknown bins (#15497)
### What does this PR try to resolve?

Fixes #15493

### How should we test and review this PR?
This takes the most surgical, direct route to addressing the problem.
Alternatively, we could look into why `cargo rustc` and `cargo check`
are different.

### Additional information
2025-05-06 20:03:07 +00:00
Weihang Lo
33d7b0aa92
test: Remove unused nightly requirements (#15498)
### What does this PR try to resolve?

### How should we test and review this PR?

### Additional information
2025-05-06 18:26:39 +00:00
Ed Page
b81c676ebc test: Remove unused nightly requirements 2025-05-06 12:52:20 -05:00
Ed Page
f83e11acfe fix(rustc): Don't panic on unknown bins
This takes the most surgical, direct route to addressing the problem.
Alternatively, we could look into why `cargo rustc` and `cargo check`
are different.

Fixes #15493
2025-05-06 11:13:30 -05:00
Ed Page
981ea84bdc refactor(compile): Make unmatched_packages optional 2025-05-06 11:10:12 -05:00
Ed Page
02ec8d48e5 test(rustc): Show the bug 2025-05-06 11:05:10 -05:00
Eric Huss
7bdd872cec
Add support for -Zembed-metadata (#15378)
### What does this PR try to resolve?

This PR adds Cargo integration for the new unstable `-Zembed-metadata`
rustc flag, which was implemented in
https://github.com/rust-lang/rust/pull/137535 ([tracking
issue](https://github.com/rust-lang/rust/issues/139165)). The new
behavior has to be enabled explicitly using a new unstable CLI flag
`-Zno-embed-metadata`.

The `-Zembed-metadata=no` rustc flag can reduce disk usage of compiled
artifacts, and also the size of Rust dynamic library artifacts shipped
to users. However, it is not enough to just pass this flag through
`RUSTFLAGS`; it needs to be integrated within Cargo, because it
interacts with how the `--emit` flag is passed to rustc, and also how
`--extern` args are passed to the final linked artifact build by Cargo.
Furthermore, using the flag for all crates in a crate graph compiled by
Cargo would be suboptimal (this will all be described below).

When you pass `-Zembed-metadata=no` to rustc, it will not store Rust
metadata into the compiled artifact. This is important when compiling
libs/rlibs/dylibs, since it reduces their size on disk. However, this
also means that everytime we use this flag, we have to make sure that we
also:
- Include `metadata` in the `--emit` flag to generate a `.rmeta` file,
otherwise no metadata would be generated whatsoever, which would mean
that the artifact wouldn't be usable as a dependency.
- Pass also `--extern <dep>=<path>.rmeta` when compiling the final
linkable artifact. Before, Cargo would only pass `--extern
<dep>=<path>.[rlib|so|dll]`. Since with `-Zembed-metadata=no`, the
metadata is only in the `.rmeta` file and not in the rlib/dylib, this is
needed to help rustc find out where the metadata lies.
- Note: this essentially doubles the cmdline length when compiling the
final linked artifact. Not sure if that is a concern.

The two points above is what this PR implements, and why this rustc flag
needs Cargo integration.

The `-Zembed-metadata` flag is only passed to libs, rlibs and dylibs. It
does not seem to make sense for other crate types. The one situation
where it might make sense are proc macros, but according to @bjorn3 (who
initially came up with the idea for `-Zembed-metadata`, it isn't really
worth it).

Here is a table that summarizes the changes in passed flags and
generated files on disk for rlibs and dylibs:

| **Crate type** | **Flags** | **Generated files** | **Disk usage** |
|--|--|--|--|
| Rlib/Lib (before) | `--emit=dep-info,metadata,link` | `.rlib` (with
metadata), `.rmeta` (for pipelining) | - |
| Rlib/Lib (after) | `--emit=dep-info,metadata,link -Zembed-metadata=no`
| `.rlib` (without metadata), `.rmeta` (for metadata/pipelining) |
Reduced (metadata no longer duplicated) |
| Dylib (before) | `--emit=dep-info,link` | `[.so\|.dll]` (with
metadata) | - |
| Dylib (after) | `--emit=dep-info,metadata,link -Zembed-metadata=no` |
`[.so\|.dll]` (without metadata), `.rmeta` | Unchanged, but split
between two files |

Behavior for other target kinds/crate types should be unchanged.

From the table above, we can see two benefits of using
`-Zembed-metadata=no`:
- For rlibs/dylibs, we no longer store their metadata twice in the
target directory, thus reducing target directory size.
- For dylibs, we store esssentially the same amount of data on disk, but
the benefit is that the metadata is now in a separate .rmeta file. This
means that you can ship the dylib (`.so`/`.dll`) to users without also
shipping the metadata. This would slightly reduce e.g. the
[size](https://github.com/rust-lang/rust/pull/120855#issuecomment-1937018169)
of the shipped rustc toolchains (note that the size reduction here is
after the toolchain has been already heavily compressed).

Note that if this behavior ever becomes the default, it should be
possible to simplify the code quite a bit, and essentially merge the
`requires_upstream_objects` and `benefits_from_split_metadata`
functions.

I did a very simple initial benchmark to evaluate the space savings on
cargo itself and
[hyperqueue](https://github.com/It4innovations/hyperqueue) (a mid-size
crate from my work) using `cargo build` and `cargo build --release` with
and without `-Zembed-metadata=no`:

![image](https://github.com/user-attachments/assets/a26994a2-156f-4863-a823-1042ebe03bf0)

For debug/incremental builds, the effect is smaller, as the artifact
disk usage is dwarfed by incremental artifacts and debuginfo. But for
(non-incremental) release builds, the disk savings (and also performed
I/O operations) are significantly reduced.

### How should we test and review this PR?

I wrote two basic tests. The second one tests a situation where a crate
depends on a dylib dependency, which is quite rare, but the behavior of
this has actually changed in this PR (see comparison table above).
Testing this on various real-world projects (or even trying to enable it
by default across the whole Cargo suite?) might be beneficial.

## Unresolved questions

### Is this a breaking change?
With this new behavior, dylibs and rlibs will no longer contain
metadata. If they are compiled with Cargo, that shouldn't matter, but
other build systems might have to adapt.

### Should this become the default?
I think that in terms of disk size usage and performed I/O operations,
it is a pure win. It should either generate less disk data (for rlibs)
or the ~same amount of data for dylibs (the data will be a bit larger,
because the dylib will still contain a metadata stub header, but that's
like 50 bytes and doesn't scale with the size of the dylib, so it's
negligible).

So I think that eventually, we should just do this by default in Cargo,
unless some concerns are found. I suppose that before stabilizing we
should also benchmark the effect on compilation performance.
2025-05-06 15:53:21 +00:00
Ed Page
79dfdd3ef6
Fix tracking issue template link (#15494)
Found while trying to create a tracking issue for
https://github.com/rust-lang/cargo/pull/15378.
2025-05-06 11:45:30 +00:00
Jakub Beránek
329fa50e69
Add entry to unstable.md 2025-05-06 13:24:38 +02:00
Jakub Beránek
33cdfb7c7a
Fix tracking issue link 2025-05-06 13:14:59 +02:00
Ed Page
bfe41282be
Refactor artifact deps in FeatureResolver::deps (#15492)
This moves the closure used for computing artifact dependency
information out into a separate function. The large line lengths were
causing rustfmt to fail to format the entire parent closure. Also, the
rightwards drift was getting quite extreme.

This also simplifies the code a little by avoiding all the transpose
stuff and needing the separate match at the end.
2025-05-05 20:48:11 +00:00
Eric Huss
e637d7c5c7 Refactor artifact deps in FeatureResolver::deps
This moves the closure used for computing artifact dependency
information out into a separate function. The large line lengths were
causing rustfmt to fail to format the entire parent closure. Also,
the rightwards drift was getting quite extreme.

This also simplifies the code a little by avoiding all the transpose
stuff and needing the separate match at the end.
2025-05-05 13:17:45 -07:00
Jakub Beránek
8250a90878
Add -Zno-embed-metadata unstable flag 2025-05-05 12:07:34 +02:00
Weihang Lo
6cba807e2c
Improved error message for versions prefixed with v (#15484)
### What does this PR try to resolve?

- Added an error message when version in `CRATE[@<VER>]` or `--version
<VER>` starts with 'v' for `install`, `add`, `yank` and `update
--precise <VER>`
- Check if version is valid in `cargo yank`

Fixes #12331

### How should we test and review this PR?

Added tests for each subcommand
2025-05-04 13:44:15 +00:00
Pyrode
2ba61b9dfc update: Added error message for when v is prefixed with version 2025-05-03 22:35:44 +05:30
Pyrode
ef3e28d371 test(update): Added test for prefixed v in version 2025-05-03 22:33:00 +05:30
Pyrode
d07439b7fd yank: Check for bad version & added error message for prefixed v in version 2025-05-03 22:31:08 +05:30
Pyrode
cd27a11da6 test(yank): Added test cases for bad version & prefixed v in version 2025-05-03 22:26:15 +05:30
Pyrode
9ae361a8fe add: Added error message for when v is prefixed with version 2025-05-03 22:25:12 +05:30
Pyrode
ac86dea366 test(add): Added test case for prefixed v in version 2025-05-03 22:24:52 +05:30
Pyrode
7e09951039 install: Added error message for when v is prefixed with version 2025-05-03 22:20:38 +05:30
Pyrode
681597f866 test(install): Added test case for prefixed v in version 2025-05-03 22:19:22 +05:30
Weihang Lo
4b96b302c0
chore: fix some typos in comment (#15485)
<!--
Thanks for submitting a pull request 🎉! Here are some tips for you:

* If this is your first contribution, read "Cargo Contribution Guide"
first:
  https://doc.crates.io/contrib/
* Run `cargo fmt --all` to format your code changes.
* Small commits and pull requests are always preferable and easy to
review.
* If your idea is large and needs feedback from the community, read how:
  https://doc.crates.io/contrib/process/#working-on-large-features
* Cargo takes care of compatibility. Read our design principles:
  https://doc.crates.io/contrib/design.html
* When changing help text of cargo commands, follow the steps to
generate docs:

https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages
* If your PR is not finished, set it as "draft" PR or add "WIP" in its
title.
* It's ok to use the CI resources to test your PR, but please don't
abuse them.

### What does this PR try to resolve?

 fix some typos in comment

### How should we test and review this PR?

Demonstrate how you test this change and guide reviewers through your
PR.
With a smooth review process, a pull request usually gets reviewed
quicker.

If you don't know how to write and run your tests, please read the
guide:
https://doc.crates.io/contrib/tests

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
-->
2025-05-03 15:50:31 +00:00
whosehang
0e282f77ce chore: fix some typos in comment
Signed-off-by: whosehang <whosehang@outlook.com>
2025-05-03 23:20:53 +08:00
Ed Page
8b5c351550
fix: default to all targets when using --edition and --edition-idioms in cargo fix (#15192)
### What does this PR try to resolve?

Close https://github.com/rust-lang/cargo/issues/13527

As we discussed, `cargo fix` should use the default target selection
with `cargo check`.

In this PR, I modified `cargo fix` to no longer use all targets by
default. For `cargo fix --edition` and `cargo fix --edition-idioms`, it
will retain the old behavior and select all targets.

### How should we test and review this PR?

Unit tests

### Additional information
2025-05-02 14:53:33 +00:00
PRO
fbd7d9b938
doc: Update instructions on using native-completions
`~/.local/share/bash-completion/completions/cargo` is more sensible, and [recommended by rustup](e4f3ad6f89/src/cli/help.rs (L275)).
2025-05-02 22:52:49 +08:00
Weihang Lo
8bf154cfa2
Update fingerprint footnote (#15478)
This was noted in
https://github.com/rust-lang/cargo/issues/8140#issuecomment-2845741150
that it appeared outdated, and indeed this was changed in
https://github.com/rust-lang/cargo/pull/6832.
2025-05-01 22:38:48 +00:00
Eric Huss
f08a7e49e8
Update fingerprint footnote
This was noted in https://github.com/rust-lang/cargo/issues/8140#issuecomment-2845741150 that it appeared outdated, and indeed this was changed in https://github.com/rust-lang/cargo/pull/6832.
2025-05-01 15:04:44 -07:00
Ed Page
64e3cd1ac5
feat(add): suggest similarly named features (#15438)
### What does this PR try to resolve?
Fixes #15436

### How should we test and review this PR?
There are 3 tests for each test case:
- there are no feature suggestions
- there's only one feature suggestion (most common)
- there are several feature suggestions
2025-05-01 14:56:49 +00:00
Ed Page
39b492cc94
In package-workspace, keep dev-dependencies if they have a version (#15470)
Fixes #15412
2025-05-01 14:49:46 +00:00
Ed Page
6ee6027127
docs: fix a typo in DependencyUI (#15472)
<!--
Thanks for submitting a pull request 🎉! Here are some tips for you:

* If this is your first contribution, read "Cargo Contribution Guide"
first:
  https://doc.crates.io/contrib/
* Run `cargo fmt --all` to format your code changes.
* Small commits and pull requests are always preferable and easy to
review.
* If your idea is large and needs feedback from the community, read how:
  https://doc.crates.io/contrib/process/#working-on-large-features
* Cargo takes care of compatibility. Read our design principles:
  https://doc.crates.io/contrib/design.html
* When changing help text of cargo commands, follow the steps to
generate docs:

https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages
* If your PR is not finished, set it as "draft" PR or add "WIP" in its
title.
* It's ok to use the CI resources to test your PR, but please don't
abuse them.

### What does this PR try to resolve?

Explain the motivation behind this change.
A clear overview along with an in-depth explanation are helpful.

You can use `Fixes #<issue number>` to associate this PR to an existing
issue.

### How should we test and review this PR?

Demonstrate how you test this change and guide reviewers through your
PR.
With a smooth review process, a pull request usually gets reviewed
quicker.

If you don't know how to write and run your tests, please read the
guide:
https://doc.crates.io/contrib/tests

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
-->
2025-05-01 14:29:07 +00:00
Farid Huliiev
ba494bce13
feat: suggest similarly named features 2025-05-01 16:12:36 +02:00
Farid Huliiev
e29810c327
feat: add tests for similarly named features 2025-05-01 16:02:15 +02:00
ELginas
ef4807a439
docs: fix a typo in DependencyUI
Signed-off-by: ELginas <gintaras.z123@yahoo.com>
2025-05-01 14:48:25 +03:00