11938 Commits

Author SHA1 Message Date
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
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
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
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
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
Ville Skyttä
3af2f12702 docs: spelling and grammar fixes 2025-03-09 10:29:48 +02:00
Max Gilmour
448ab4d43e
Typo fixes 2025-03-07 21:59:14 -08:00
Ed Page
aecb765fd6
feat: add completions for install --path (#15266)
<!--
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.

### 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 install --path option.
When a user types cargo install --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:
1. In the terminal, type `cargo install --path`
2. Press the TAB key.
3. 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/281706c0-7956-4551-a22b-125dadccd12e

### Additional information

There's a [discussion in
Zulip](https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/PR15266.3A.20completions.20for.20install.20--path)
and here're some relevant information from it
1. directories are always shown so that a completer doesn't have to
recurse through a directory tree to determine what directories may be
relevant. The difference marking a directory as accepted does it sorts
it first.
2. A user / config setting might override a sort order over native
completion. Try disable it manually if native completion is not there.
2025-03-07 18:23:34 +00:00
NOOMA-42
cb278bc0bd
feat: add completions for install --path 2025-03-08 01:53:26 +08:00
Weihang Lo
f0907fca16
fix(package): report if the lockfile is dirty
Lockfile might not be under the package root, but its entries
may be outdated and get packaged into the `.crate` tarball.
We take a conservative action that if the lockfile is dirty,
then all workspace members are considered dirty.
2025-03-07 08:45:49 -05:00
Weihang Lo
1b94e1b27c
fix(package): report if workspace manifest is dirty
Workspace manifest might not be under the package root, but
workspace inheritance may still affect what is packaged into
the `.crate.` tarball. We take a conservative action that if
the workspace manifest is dirty, then all workspace members
are considered dirty.
2025-03-06 23:42:49 -05:00
Weihang Lo
2375b1924e
refactor(package): use format_arg! to avoid allocations 2025-03-06 23:18:18 -05:00
Weihang Lo
4244b64112
refactor(package): move path_in_vcs closer to where it is used 2025-03-06 23:18:18 -05:00
Weihang Lo
af1e77cd62
refactor(package): rename variable 2025-03-06 23:18:18 -05:00
Weihang Lo
73b3092fd5
feat(tree): Add --depth public behind -Zunstable-options (#15243)
### What does this PR try to resolve?

I was investigating some issues around public dependency lints and
wanted to see the structure of the public dependencies and had the idea
to add this with us having added `--depth workspace`.

See
https://github.com/rust-lang/rust/issues/119428#issuecomment-2686384070
for some example output (comparing `cargo tree` with `cargo tree --depth
public`)

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

### Additional information
2025-03-06 21:52:54 +00:00
Alex Crichton
70dc4d8331 Don't use $CARGO_BUILD_TARGET in cargo metadata
This commit fixes a (five year old!) regression in `cargo metadata`
where if `--filter-platform` isn't explicitly specified it will
accidentally read `$CARGO_BUILD_TARGET` (or `build.target`
configuration) and use that as the default `--filter-platform`. The
reason for this is that the calculation for targets changed in #8167
and while the shared function makes sense for other commands such as
`cargo build` the targets have a different meaning in `cargo metadata`
so a slightly different set of functionality is desired.

This commit fixes the issue by introducing a new constructor for the
list of `CompileKind` variants where the fallback of "if nothing is
specified" is explicitly chosen.
2025-03-06 09:00:00 -08:00
Weihang Lo
7c0b2bdb11
feat: show extra build description from bootstrap
`CFG_VER_DESCRIPTION` is descriptive string to be
appended to version output.

This is usually set by the bootstrap in rust-lang/rust.
Useful for showing vendor build information.

See <https://github.com/rust-lang/rust/pull/137723>.
2025-03-05 15:11:37 -05:00
Ed Page
5a1a22310f refactor(context): Remove unused functions 2025-03-04 11:03:27 -06:00
Ed Page
2f35b633d8 fix(registry): Respect --frozen like --offline 2025-03-04 11:03:27 -06:00
Ed Page
e115c3c913 fix(resolver): Consider --frozen, like --offline, in errors 2025-03-04 11:03:27 -06:00
Ed Page
55cf9806c5 fix(git): Respect --frozen like --offline 2025-03-04 10:56:55 -06:00
Ed Page
52a271f217 refactor(context): Remove unused locked lookup 2025-03-04 10:50:30 -06:00
Ed Page
7fdeda41bd fix(install): Also require a lockfile for --frozen 2025-03-04 10:50:30 -06:00
Ed Page
108b05a488 fix(add): Also respect --frozen for preventing edits 2025-03-04 10:50:30 -06:00
Ed Page
40d6ac63c9 refactor(context): Abstract lookup for locked flag 2025-03-04 10:50:30 -06:00
Ed Page
c576f68f10 refactor(context): Abstract lookup for offline flag 2025-03-04 10:39:26 -06:00
Weihang Lo
615a6f87c3
feat(tree): Color the output (#15242)
### What does this PR try to resolve?

This is an experiment to find ways to make `cargo tree` output easier to
grok. I find too many details are hard to spot because everything looks
the same.

![image](https://github.com/user-attachments/assets/92055027-c7a0-4357-9870-400ba6c2de9c)

The goal is to make it easier to scan the output for relevant details.
So far, this approach seems the most viable. Knowing what type of edges
led to where you are provides useful context for scrolling through large
lists of dependencies.

Fixes #10558

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

I had considered styling normal dependency edges but there isn't a
header to clarify what they mean, so I decided to match the package name
as that is the header. So this didn't buy as much as I had hoped,
especially since dimmed lines aren't obvious with my terminal. Maybe if
we used different unicode graph characters.

Instead of coloring the "this is elided" `(*)`, I had considered using a
unicode character that looks like its pointing from that item up. I only
found one that looked close to that but the origin for the arrow was
bottom aligned, rather than center aligned and it looked off.

Alternatives considered
- Once an edge is marked with dev or build dependencies, all future
edges inherit it
- While this makes it clear what section you are in, so does the outer
most line
- Feature edges are the color of the edges that led to them
  - Unsure of value either way
  - This might get weird with `--invert`
- Style local nodes different than non-local
- With the format string being user customizable, I'm concerned with
styling over or within user styling
- Rainbow packages: For every package in the same namespace
(`.split_once("::").0`) or prefix (`.split_once(['-','_']).0`), assign a
color (maybe only for the top N packages to reduce duplicate colors)
  - Would help a lot with `gix-*` and similar other cases
- If we cap the number of participating packages, would need care to
work with `--depth`

(of course,. these could be mixed)

### Additional information
2025-03-04 18:47:52 +00:00
Weihang Lo
9e18e48f8c
fix(vendor): dont remove non-cached source
cargo-vendor has a workaround that to mitigate rust-lang/cargo#5956,
it removes all cached sources in order to trigger a re-unpack.
It was meant for dealing with registry sources only, but accidentally
applied to directory source kind.

While directory source kind was invented for vendoring,
and vendoring from one vendored directory to the other seems unusual,
Cargo IMO should not delete any real sources.

It does not mean that registry sources are okay to delete,
In long term, we should explore a way that unpacks `.crate` files
directly, without any removal. See
https://github.com/rust-lang/cargo/pull/12509#issuecomment-1732415990
2025-03-03 20:47:44 -05:00
Ed Page
abe461c48d
docs: lockfile is always included since 1.84 (#15257)
### What does this PR try to resolve?

This was changed in <https://github.com/rust-lang/cargo/pull/14815>
since 1.84 but we missed some doc updates.
2025-03-03 15:11:46 +00:00
Weihang Lo
d67810fb6d
Remove Cargo.toml from package.include in example (#15253)
https://doc.rust-lang.org/cargo/reference/manifest.html#the-exclude-and-include-fields

>The following files are always included:
>
>* The `Cargo.toml` file of the package itself is always included, it
does not need to be listed in `include`.
2025-03-03 02:53:41 +00:00
Zane
a8d1beb8ec
Add link to "The exclude and include fields" in example 2025-03-02 20:47:26 -05:00
Weihang Lo
74544f176a
docs: lockfile is always included since 1.84 2025-03-02 20:00:02 -05:00
Orion Gonzalez
08b3944af4 fn needs not be failable. 2025-03-02 16:59:29 +01:00
joshua you
eaca29dfa3
Fix typo in build-scripts.md
vaue -> value
2025-03-02 01:11:25 -08:00
Zane
7f6ea1a06d
Remove Cargo.toml from package.include in example 2025-03-02 00:55:52 -05:00
Weihang Lo
48a54c9d42
feat(cli): forward bash completions of third party subcommands (#15247)
# What does this PR try to resolve?

Currently third party subcommands like `cargo asm` from
[`cargo-show-asm`] don't
support shell completions, even when the corresponding `cargo-<cmd>`
command *does*.
(I'm using `cargo asm` as example because it was the first subcommand
that came
into mind that provides completions)

This PR fixes this for `bash` by using [`bash-completion`]'s
[`_comp_command_offset`] function to generate these completions.
(Assuming these completions are available to [`bash-completion`])

[`bash-completion`] is the package that is used by all major unix-like
operating
systems to provide bash completions.

If the subcommand has no completion, that falls back to the default
bash.
(That might not be *exactly* the same as `_filedir`, but should be
correct anyway)

**Note** that [`_comp_command_offset`] is only supported since
[`bash-completion`] >= `2.12.0`,
which requires `bash` >= `4.2.0`, which means that the default
`bash` version shipped with MacOs is **not** supported. \
In that case we fall back to the previous behavior with `_filedir`.

# How should we test and review this PR?

I'm not sure if there is any testing setup for shell completions for
`cargo`.
I have just tested it manually by running these commands:
(In the working directory of this PR)

```bash
#!/usr/bin/env bash

# Install the subcommand
cargo install cargo-show-asm
# Load the completions for `cargo-asm`
eval "$(cargo-asm --bpaf-complete-style-bash)"
# (Re)source the new cargo completions
source src/etc/cargo.bashcomp.sh
```

and then tab-completing from `cargo asm <TAB>`.

# Additional information

## Further Possibilities

The same trick with [`_comp_command_offset`] could be used to get
completions
for the command run with `cargo run -- `, assuming there is an easy way
to get
the name of the binary that would be run. (And maybe something to
dynamically (re)-load the completions.)

## Prior Art

The `zsh`-completions already support the `zsh`-equivalent of this with
<58cfd96b59/src/etc/_cargo (L368-L372)>

[`cargo-show-asm`]: https://docs.rs/cargo-show-asm
[`bash-completion`]: https://github.com/scop/bash-completion/
[`_comp_command_offset`]:
92f558d582/bash_completion (L2816-L2821)
2025-03-01 15:02:19 +00:00
Ed Page
e79bac1951
feat: add completions for --lockfile-path (#15238)
### What does this PR try to resolve?

Add auto completion for `cargo build --lockfile-path <TAB>`

Related to #14520

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

![Screenshot from 2025-02-27
18-38-21](https://github.com/user-attachments/assets/36ae3584-8e1a-4e9e-bab8-fe239c03bb82)
2025-02-28 18:49:13 +00:00
utnim2
4afa6d70ab fix: remove reduntant is_dir() check 2025-02-28 23:22:37 +05:30