19766 Commits

Author SHA1 Message Date
Ed Page
c13453ffda fix(toml): Report '<target>.edition' deprecation to users
In hindsight, the use of this is rare enough that we can go ahead and
warn without user controllable lints.
2025-03-15 03:04:18 -05:00
Ed Page
083dc92b0e
feat: Add custom completer for cargo +<TAB> to complete toolchain name (#15301)
<!--
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.
-->

### What does this PR try to resolve?

Related to https://github.com/rust-lang/cargo/issues/14520

This PR introduces auto-completion for the `cargo +<TAB>` option. When a
user types `cargo +<TAB>` and presses the TAB key, the system will
automatically suggest toolchain in current device

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

To verify this feature, follow these steps:
1. In the terminal, type `cargo +<TAB>`
2. Press the TAB key.
3. You should see toolchain suggestions

https://github.com/user-attachments/assets/c8bd8a5e-e97d-4d0a-b284-1ed52734c4a2
2025-03-17 16:31:36 +00:00
Weihang Lo
26a87d6b09
chore: fix some typos (#15316)
<!--
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?

### 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.
-->

 fix some typos
2025-03-16 13:26:59 +00:00
jimmycathy
20a05ba9e1 chore: fix some typos
Signed-off-by: jimmycathy <clonecode@outlook.com>
2025-03-16 12:26:08 +08:00
Weihang Lo
437ff042f4
fix: deduplicate crate types in cargo rustc command (#15314)
### What does this PR try to resolve?

close: #15312

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

deduplicate `crate-type` in cargo `rustc` command
2025-03-16 00:21:21 +00:00
Frank Wang
36de02f4a6 fix: deduplicate and update snapshot 2025-03-15 17:55:15 -05:00
Frank Wang
b8849dcb74 add test for duplicate crate-type arg 2025-03-15 17:51:18 -05:00
NOOMA-42
1cea458703
feat: Add custom completer for cargo +<TAB> to complete toolchain name 2025-03-15 16:02:09 +08:00
Weihang Lo
3e96f1a28e
docs: mention wrong URLs as a cause of git authentication errors (#15304)
I was seeing an error like the following in my `rust-analyzer` output.

```
error: failed to load source for dependency `fontdue`

Caused by:
  Unable to update https://github.com/xiphseer/fontdue.git?rev=67b963af0d5ca9e09bfeb0b5a9adf85c302d0a67

Caused by:
  failed to fetch into: /home/daniel/.local/share/cargo/git/db/fontdue-4d0b06b88bb2e092

Caused by:
  revision 67b963af0d5ca9e09bfeb0b5a9adf85c302d0a67 not found

Caused by:
  failed to authenticate when downloading repository

  * attempted to find username/password via git's `credential.helper` support, but failed

  if the git CLI succeeds then `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  failed to acquire username/password from local configuration
```

I spent about 10 minutes reading the docs on *git authentication*,
before realizing I had just typo'ed my own GitHub username. This PR adds
a note to the reference that explicitly mentions wrong (not malformed)
URLs as a cause of authentication errors.

It's not directly on the linked
<https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli>
mainly because *Git Authentication* is already linked there, so it may
catch more people and that's meant as the more detailed explanation
anyway.
2025-03-15 03:07:33 +00:00
Ed Page
6cf8267012
feat(package): add --exclude-lockfile flag (#15234)
### What does this PR try to resolve?

Fixes #15059
Fixes #15159

This provides an escape hatch `--exclude-lockfile`for uncommon workflows
that don't verify (`--no-verify` is passed) the build with their
unpublished packages
In effect, this takes the heuristic removed in #14815 and replaces it
with a flag

When `--exclude-lockfile` is enabled,
`cargo package` will not verify the lock file if present,
nor will it generate a new one if absent.
Cargo.lock will not be included in the resulting tarball.

Together with `--no-verify`,
this flag decouples packaging from checking the registry index.
While this is useful for some non-normal workflows that requires
to assemble packages having unpublished dependencies.
It is recommended to use `-Zpackage-workspace` to package the entire
workspace, instead of opting out lockfile.

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

The first commit was stolen from
<1a104b5444>
(credit to @NoisyCoil!)

The second added two failing cases we observed in #15059.

### Additional information
2025-03-14 15:25:36 +00:00
Weihang Lo
ca694a8b89
Redox OS is part of the unix family (#15307) 2025-03-14 05:02:38 +00:00
Weihang Lo
44277a48be
docs(ref): Mention x.y.* as a kind of version requirement to avoid. (#15310)
This expands the text introduced by #12323.

`x.y.*` is equivalent to `>=x.y.0, <x.(y+1).0`, so it can create an
unresolvable conflict in the same way as already discussed.

I also added a little punctuation to improve the structure of some
nearby sentences.

@rustbot label A-documenting-cargo-itself
2025-03-14 05:00:37 +00:00
Kevin Reid
c0cc00390b
Also mention tilde requirements. 2025-03-13 21:18:29 -07:00
Kevin Reid
50fd163e93
Mention x.y.* as a kind of version requirement to avoid.
`x.y.*` is equivalent to `>=x.y.0, <x.y+1.0`, so it can create an unresolvable conflict in the same way as already discussed.
2025-03-13 19:03:45 -07:00
bjorn3
c340cd902d Bump home version to 0.5.12 2025-03-13 21:37:39 +01:00
bjorn3
9e74cce829 Redox OS is part of the unix family 2025-03-13 21:19:46 +01:00
Weihang Lo
bc577dc6c4
fix(run): Disambiguate bins from different packages that share a name (#15298)
### What does this PR try to resolve?

This builds on the work done in #15199 to improve target selection
errors to also disambiguate when the same binary name is used in
multiple packages.

This also makes the errors from #15199 more consistent with the rustc
style guide and reduces code duplication.

Fixes #13312

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

This is a first pass and does not do the full `--package foo --bin bar`
syntax. I wanted to focus on the basic functionality before we iterated
on it, e.g. investigating how well we can predict the CLI flags, how
much noise they might add, etc.

### Additional information
2025-03-13 14:56:45 +00:00
Daniel Seiler
82f4b1e127
docs: mention wrong URLs as a cause of git authentication errors 2025-03-12 22:32:05 +01:00
Ed Page
d29a7cb5d7 fix(run): Say what the multiple executables are 2025-03-11 13:15:54 -05:00
Ed Page
b06e29c72a fix(compile): Specify packages ambiguous targets come from 2025-03-11 13:02:55 -05:00
Ed Page
611b7c4ee4
cargo vendor: Add context which workspace failed to resolve (#15297)
This adds some context to the `cargo vendor` command when it fails to
resolve or load a workspace. This can be helpful when syncing a large
number of workspaces, and it isn't clear which one is causing the
problem.
2025-03-11 17:07:32 +00:00
Ed Page
b20edd4226 fix(compile): Consistently use help prefix in errors 2025-03-11 11:54:00 -05:00
Ed Page
7bf7b2f684 fix(compile): Match rustc style guide for help message casing 2025-03-11 11:51:38 -05:00
Ed Page
86dcd23f8e refactor(compile): De-duplicate error generation 2025-03-11 11:48:14 -05:00
Ed Page
05775e5169 refactor(compile): Remove layer of abstraction 2025-03-11 11:41:22 -05:00
Ed Page
fde91dde66 fix(compile): Remove trailing newlines on errors 2025-03-11 11:41:18 -05:00
Ed Page
c2764576ac fix(compile): Be consistent in not using period in error
Whether a period was used was dependent on whether a `help:` block is
present.
That shouldn't make a difference and the rustc dev guide says not to use
periods unless multiple sentences are used.
2025-03-11 11:41:08 -05:00
Eric Huss
2158fe1357 Add context for which workspace failed when resolving cargo vendor 2025-03-11 09:37:02 -07:00
Eric Huss
bf3885e0c6 Add tests for cargo vendor error cases resolving 2025-03-11 09:16:48 -07:00
Ed Page
54dd94b49b refactor(compile): Use string interpolation 2025-03-11 11:15:00 -05:00
Ed Page
5375c3f60d refactor(compile): Pull out common variables 2025-03-11 11:14:15 -05:00
Ed Page
da833c55be test(run): Show ambiguous package name errors 2025-03-11 11:11:44 -05:00
Ed Page
92a5d5e56a test(run): Move run-focused test with rest 2025-03-11 11:07:39 -05:00
Weihang Lo
11df198412
docs(ref): Note that target-edition is deprecated (#15292)
### What does this PR try to resolve?

This is the first step in implementing rust-lang/rfcs#3772 (tracking
issue #15283)

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

Leaving off any talk of it being removed until we know the edition.

### Additional information
2025-03-11 15:51:27 +00:00
Ed Page
5ff2960960 docs(ref): Note that target-edition is deprecated
Leaving off any talk of it being removed until we know the edition.

This is the first step in implementing rust-lang/rfcs#3772 (tracking issue #15283)
2025-03-11 10:23:32 -05:00
Ed Page
58c46b12ff docs(ref): Move target-edition to last 2025-03-11 10:22:45 -05:00
Weihang Lo
21f4080079
refactor(toml): Centralize target descriptions (#15291)
I was going to add another duplicate and was wondering what was the
right value and figured it'd be better if I just did this.

<!--
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-03-11 01:27:22 +00:00
Ed Page
3897c7cb0f
docs(refs): Add unsafe to extern while using build scripts in Cargo Book (#15294)
### What does this PR try to resolve?

Since `rust 1.85.0`, It is no longer sufficient to use the `unsafe`
keyword only at the call site. It must also be applied to the `extern`
statement, hence, Cargo Book must be updated

- closes https://github.com/rust-lang/cargo/issues/15289

and also update some more related content

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

Run `mdbook build`. The `unsafe extern` should be seen at
`cargo/reference/build-script-examples.html#linking-to-system-libraries`
, `cargo/reference/build-script-examples.html#building-a-native-library`
, `cargo/reference/semver.html#repr-c-shuffle` ,
`cargo/reference/semver.html#repr-c-remove` and
`cargo/reference/semver.html#repr-transparent-remove`

### Additional information
2025-03-11 01:17:36 +00:00
Naman Garg
a255e30248
Add unsafe to extern build scripts in Cargo Book 2025-03-11 03:21:01 +05:30
Ed Page
35cf085d81
Replace unmaintained humantime crate with jiff (#15290)
<!--
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.
-->

The crate [`humantime`](https://crates.io/crates/humantime) appears to
be unmaintained. There's open PR in RustSec's advisory-db about this:
https://github.com/rustsec/advisory-db/pull/2249

The crates [`clap`](https://crates.io/crates/clap) and
[`env_logger`](https://crates.io/crates/env_logger) have already made
the switch from `humantime` to [`jiff`](https://crates.io/crates/jiff):

 * https://github.com/clap-rs/clap/pull/5944
 * https://github.com/rust-cli/env_logger/pull/352

The `jiff` crate is already dependency on `cargo` via `gix` (albeit old
0.1 version, but that's probably fixed in [next gix
release](3ae99a42f5)):

```
jiff v0.1.29
└── gix-date v0.9.3
    ├── gix v0.70.0
    │   └── cargo v0.88.0 (/Users/oherrala/rust/cargo)
```

This PR shouldn't have any functional change to cargo itself.
2025-03-10 21:01:50 +00:00
Ed Page
cb28b36b9b refactor(toml): Centralize target descriptions
I was going to add another duplicate and was wondering what was the
right value and figured it'd be better if I just did this.
2025-03-10 15:38:25 -05:00
Ossi Herrala
514057ffb4
Replace unmaintained humantime crate with jiff 2025-03-10 22:34:17 +02:00
Ed Page
340d1239a8
Add terminal integration via ANSI OSC 9;4 sequences (#14615)
### What does this PR try to resolve?

A few terminal emulators support progress output to Windows taskbar.
`winget` uses this to show install progress.

Notably, Windows Terminal [recently (2020) added
support](https://github.com/microsoft/terminal/pull/8055) for ANSI codes
[specified](https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC)
in ConEmu (another terminal emulator for Windows) documentation. Also,
in "[Learn
Windows](https://learn.microsoft.com/en-us/windows/terminal/tutorials/progress-bar-sequences)".

I've found the previous attempt to add this feature:
https://github.com/rust-lang/cargo/pull/11436

As per @weihanglo's request, I've added the config option to
enable/disable this feature. **It's enabled on supported terminal
emulators.**

Fixes #11432

FCP:
https://github.com/rust-lang/cargo/pull/14615#issuecomment-2546346489

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

Run `cargo build` in Windows Terminal with configuration option
`term.progress.taskbar` set to `true`.

### Not sure

- [x] Should all the code be `#[cfg(windows)]`? Probably no, because the
feature is also usable in WSL.
> Solved by introducing heuristic based on environment variable set by
terminal

- [ ] If Ctrl+C is pressed, a progressbar will stay in a last state
forever (shown in the ConEmu video). `winget` is also behaves like
alike. I've experimented with `ctrl_c handler` and it's totally fixable.
- [x] `Enabled` is a sensible default for WSL because it works on linux
builds in Windows Terminal too
> Solved by introducing heuristic based on environment variable set by
terminal

- [x] Downloading stage may produce unpleasant blinking due to a rapid
0-100 changes
> Solved by not displaying bar when downloading and using indeterminate
state in other cases so amination don't reset

### TLDR

* An `term.progress.taskbar` option with bool type is added
* On Windows Terminal and ConEmu is enabled by default
* If enabled reports build progress to taskbar icon and/or tab header

### Videos

https://github.com/user-attachments/assets/48bb648a-e819-490e-b3ac-3502bc5f2f3a

https://github.com/user-attachments/assets/1d7ddf7a-34dd-4db1-b654-e64d7170798e
2025-03-10 14:46:19 +00:00
Weihang Lo
42b6ae87b1
feat: add completions for add --path (#15288)
<!--
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.
-->

### What does this PR try to resolve?

Related to https://github.com/rust-lang/cargo/issues/14520

This PR introduces auto-completion for the `cargo add --path` option.
When a user types `cargo add --path` and presses the TAB key, the system
will automatically detect directories in the current path and suggestion
prioritizes directory containing a Cargo.toml file.

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

To verify this feature, follow these steps:

In the terminal, type `cargo add --path`
Press the TAB key.
You should see suggestions only for directories in the current path that
contain a Cargo.toml file being prioritized, such as ./src/ (if
./src/Cargo.toml exists).

https://github.com/user-attachments/assets/0620ae5e-abca-425c-ad9a-7004929bb98d
2025-03-10 04:22:11 +00:00
NOOMA-42
e06e0184bc
feat: add completions for add --path 2025-03-10 11:48:04 +08:00
Weihang Lo
0dea3cd3b8
Allow term.progress.when to default (#15287)
### What does this PR try to resolve?

The config section `term.progress` contains a collection of options
(currently only `when` and `width`). If only `width` is set, Cargo fails
with the error: "missing field `when`." This behavior may be surprising
and inconvenient for users who want to set the
`CARGO_TERM_PROGRESS_WIDTH` environment variable.

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

The relevant test, `bad_progress_config_missing_when`, has been replaced
with `default_progress_is_auto`.

https://github.com/rust-lang/cargo/pull/14615

From
https://github.com/rust-lang/cargo/pull/14615#discussion_r1889426752

> I don't recall any particular decisions made regarding
bad_progress_config_missing_when. I personally would not object to
changing that to allow it to pass. I can't think of a reason it would be
required to specify when with width.
2025-03-10 01:13:26 +00:00
Alexander Sergeev
59b11a78e4 feat: use default value for term.progress 2025-03-09 23:20:11 +03:00
Alexander Sergeev
a0624eaf53 feat: add taskbar progress reporting 2025-03-09 21:45:10 +03:00
Weihang Lo
4a8fd9b5df
docs: spelling and grammar fixes (#15284)
<!--
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-03-09 12:07:11 +00:00
Ville Skyttä
3af2f12702 docs: spelling and grammar fixes 2025-03-09 10:29:48 +02:00