7252 Commits

Author SHA1 Message Date
Ed Page
90b68c87f4 fix(manifest): Show error source to users
Several parts of this are not ideal yet
- Frontmatter close should show the open and show the EOF, instead of
  pointing at the open
- Trailing content on close will usually have a newline
- Multiple frontmatters should show the original frontmatter
- Some content, like supported infostrings, should go in a help
- Ideally we try to recover on no closing and instead point out a
  mismatched open/close

But this is still an improvement over nothing!
2025-09-08 16:06:29 -05:00
Ed Page
da2eafe024 test(help): Ensure consistent behavior regardless of rustup use 2025-09-10 15:25:35 -05:00
Ed Page
2e231072f4 test(manifest): Fix test output order
As this is an unordered test, sometimes snapshot updating can mess up
the line order.
2025-09-08 21:04:05 -05:00
Ed Page
4909d78973 fix(frontmatter): Report script manifest errors for the right line number 2025-09-04 16:15:04 -05:00
Ed Page
578ab7cc45 test(script): Show line numbers are off 2025-09-04 14:56:33 -05:00
Weihang Lo
3ceb2cb250
fix(cli): Adjust messages to match rustc (#15928)
### What does this PR try to resolve?

Fixes #12740

This is also prep for #15917, #15922

Changes:
- `note` changes from Cyan to Bright Green
- `cargo info` had to be changed because the header and context colors
became the same
- Switch to Bright colors which is usually redundant with Bold but that
is theme dependent
- `warning` only changes to Bright on Windows which is to work around a
shell issue on some Windows versions
  - except for `PLACEHOLDER` to tell it apart from `LITERAL`
- the `:` in `note:` is no longer bolded to match rustc

### How to test and review this PR?

### Notes

While annotate-snippets does not have a style for every one of our
styles, I updated our manual styles to be similar to annotate snippets.

For annotate snippets color definitions, see
d38b08b81d/src/renderer/mod.rs (L41-L78)
2025-09-08 04:10:39 +00:00
Ed Page
19f1d1561c fix: Switch from --nocapture to --no-capture
`--no-capture` was added in 1.88, with `--nocapture` being
soft-deprecated.
2025-09-05 10:33:00 -05:00
Ed Page
eac1ad1cd3 fix(shell): Don't bold the colon after error/warn/note 2025-09-05 09:40:24 -05:00
Ed Page
883cbb22e5 test(credential): Switch more expected results to snapshots
Had to deal with manually updating these when changing notes
2025-09-05 09:24:38 -05:00
Ed Page
7d6d673e23 fix(cli): Adjust terminal styles to match rustc
Fixes #12740
2025-09-04 16:35:40 -05:00
Ed Page
c8a15f324f fix(publish): Don't generate final artifacts 2025-09-02 15:29:04 -05:00
Ed Page
3f857e9dd4 test(publish): Show the build-dir behavior 2025-09-02 13:21:35 -05:00
Scott Schafer
022dc5b381
chore: Address most typos 2025-09-02 18:15:50 -06:00
Scott Schafer
d36c326926
chore(deps): update rust crate annotate-snippets to 0.12.1 2025-09-02 15:43:38 -06:00
Scott Schafer
2ef151bdc9
fix: Emit inline help after first snippet 2025-09-02 15:43:37 -06:00
Ed Page
57c97cc190 test(script): Switch frontmatter tests to end-to-end
This will make it easier to validate error improvements I'm working on
as well as make it easier to update from rust-lang/rust
2025-08-29 16:11:59 -05:00
Ed Page
79b6548c13 test(script): Pull out test mod 2025-08-29 16:11:59 -05:00
Ed Page
db6891f244 fix(cli): Show the bad manifest path
In most cases, this will just be what you passed on the command line.
Even when its not, that likely represents a programmer error.

I mostly did this to help see what was the cause of a test failure.
2025-08-29 15:42:44 -05:00
Weihang Lo
a6c58d4305
test: avoid hardcoded target spec json (#15880)
Read a real target spec JSON so we no longer need to hardcode
a target spec JSON here.
Cargo itself should not care about the spec schema.

Let's stop bothering compiler contributors.

* https://github.com/rust-lang/rust/pull/144443
* https://github.com/rust-lang/rust/pull/145764#issuecomment-3216104449
* [#t-compiler > Is it possible to add a commit to a submodule? @
💬](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Is.20it.20possible.20to.20add.20a.20commit.20to.20a.20submodule.3F/near/535865215)
2025-08-26 23:05:12 +00:00
Ed Page
b54b92cc5f test(add): Ensure an empty frontmatter is handled properly
There are corner cases with empty frontmatters, so I wanted to ensure
this case works now and going forward
2025-08-26 15:12:19 -05:00
Ed Page
865dfe26d1 test(add): Ensure escaping is preserved
I cannot think of a programmatic way to require escaping when going from no frontmatter to a frontmatter
or to require more escaping than is already present.
2025-08-26 15:09:44 -05:00
Ojus Chugh
d2a6dcb43e fix(publish): Show remaining packages to be published 2025-08-25 14:45:02 -05:00
Ojus Chugh
f36cb83e98 fix(publish): Report which package failed to publish 2025-08-25 14:44:29 -05:00
Ojus Chugh
688ec9e9ef test(publish): Add test demonstrating error messages during workspace publish rate limiting 2025-08-25 14:38:07 -05:00
Weihang Lo
56f44bb212
test: avoid hardcoded target spec json
Read a real target spec JSON so we no longer need to hardcode
a target spec JSON here.
Cargo itself should not care about the spec schema.

Let's stop bothering compiler contributors.
2025-08-23 22:26:08 -04:00
Weihang Lo
4434ed8a2a
suggest workspace hints for boolean dependencies (#15507)
### What does this PR try to resolve?
via issue #15505, Cargo currently errors on
```toml
[dependencies]
crc32fast = true
```
with a message about `expected a version string or a detailed
dependency` It doesn’t hint that you can depend on a workspace member.
This PR updates `cargo` so that when you write dep = true, the error
also suggests:
```toml
dep = { workspace = true }
dep.workspace = true
```

### How should we test and review this PR?
In a workspace crate’s Cargo.toml, add
```toml
[dependencies]
crc32fast = true
```
Run `cargo build` and you should see the enhanced error with the two
workspace hints.

### Additional information

Regarding support for int/float, we only need a special case for boolean
because they’re the only values that get the `workspace hint`.
Everything else just uses the normal detailed dependency error
2025-08-21 14:31:55 +00:00
Scott Schafer
069723ebff
fix(unknown_lints): Make emitted_source come before other groups 2025-08-19 16:19:40 -06:00
Samuel Onoja
5dd597b621
impl workspace hint for boolean dependencies
hint for only bad dependency true literal and rename unit test to match
2025-08-19 18:15:32 +01:00
Samuel Onoja
7e78c54630
initial test commit 2025-08-19 18:15:32 +01:00
Weihang Lo
33cb1c2654
feat(unstable): Added -Zbuild-dir-new-layout unstable feature (#15848)
### What does this PR try to resolve?

Added `-Zbuild-dir-new-layout` unstable feature as part of #15010

I will open a follow up PR with an initial implementation as mentioned
[here](https://github.com/rust-lang/cargo/issues/15010#issuecomment-3193725891)

r? @weihanglo
2025-08-18 05:04:24 +00:00
Weihang Lo
206e3fe6b3
Implement host-target substitution (#15838)
### What does this PR try to resolve?

This PR resolves: https://github.com/rust-lang/cargo/issues/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:

```toml
# .cargo/config.toml

[build]
target = "host"
```
2025-08-18 00:01:34 +00:00
zdivelbiss
d5509ebacc
amend documentation style for host target specifier
We also rebuilt the manual pages, to ensure they're up-to-date with the changes made in the `host` target specifier PR.
2025-08-17 14:39:35 -05:00
zdivelbiss
8f66af7194
simplify tests for host target specifier 2025-08-17 12:54:22 -05:00
zdivelbiss
b23e0a99b2
documentation for host target specifier 2025-08-17 12:52:11 -05:00
zdivelbiss
b3f5e052f6
tests for host target specifier 2025-08-17 12:51:34 -05:00
Karol Zwolak
fb046a1354 update tests to match lint message changes from rust-lang/rust#140794 2025-08-17 18:50:55 +02:00
Ross Sullivan
8e53ef3bbf
feat(unstable): Added -Zbuild-dir-new-layout unstable feature 2025-08-17 14:17:27 +09:00
Ed Page
e04e0b65c0
feat(unstable): add -Zbuild-analysis unstable feature (#15845)
### What does this PR try to resolve?

Part of #15844

Set up `-Zbuild-analysis` flag and `build.analysis` configuration table
to lay the ground work.
when `build.analysis.enabled = true`, enables HTML timing output to
pretend we are persisting timing data for now. This will change when the
storage part is implemented.

### How to test and review this PR?
2025-08-16 14:18:21 +00:00
Weihang Lo
b43404de7e
feat(build-analysis): build.analysis configuration
When enabled, set timing output format to HTML to pretend
we are persisting timing data for now.
2025-08-16 08:28:38 -04:00
Weihang Lo
973f7410a8
test(build-analysis): feature gate tests 2025-08-16 08:28:37 -04:00
Weihang Lo
57fd10126c
feat(unstable): add -Zbuild-analysis unstable feature 2025-08-15 23:32:31 -04:00
Ojus Chugh
0e540b2bea Fixes error while running the cargo clippy --all-targets -- -D warnings commad 2025-08-16 01:18:59 +05:30
Ross Sullivan
a24ae6fd58
feat(build-dir): Stabilize build-dir 2025-08-15 11:00:01 +09:00
Eric Huss
e647065d5d
chore: remove x86_64-apple-darwin from CI and tests (#15831)
### What does this PR try to resolve?

RFC 3841 has merged, and x86_64-apple-darwin will be demoted to tier-2
in 1.90.0. In Cargo we usually run test against tier-1 platforms, so
x86_64-apple-darwin should be removed.
Also, that target platform is often the slowest one in CI, we are happy
to remove it to save us a couple of minutes.

https://rust-lang.github.io/rfcs/3841-demote-x86_64-apple-darwin.html

### How to test and review this PR?

Run `cargo test` locally with cross-compile tests enabled, and no
regression.
2025-08-12 20:48:04 +00:00
Weihang Lo
9614bc251b
chore: remove x86_64-apple-darwin from CI and tests
RFC 3841 has merged, and x86_64-apple-darwin will be demoted to tier-2
in 1.90.0. In Cargo we usually run test against tier-1 platforms, so
x86_64-apple-darwin should be removed.
Also, that target platform is often the slowest one in CI,
we are happy to remove it to save us a couple of minutes.

https://rust-lang.github.io/rfcs/3841-demote-x86_64-apple-darwin.html
2025-08-12 16:02:16 -04:00
Ed Page
2dc9c20034
perf(package): Always reuse the workspace's target-dir (#15783)
### What does this PR try to resolve?

While preparing to stabilize `build-dir`, [it was
discovered](https://github.com/rust-lang/cargo/issues/14125#issuecomment-3127467689)
that `cargo package` will sometimes use the build cache for dependency
crates if `CARGO_TARGET_DIR` is explicitly set.

If target-dir is not set, the build will be preformed in an "inner
target dir" at `target/package/{name}-{version}/target` and rebuild
everything.

This PR changes the default behavior to always use the build cache,
matching the behavior of having `target-dir` set.

### How to test and review this PR?

Added a dedicated test to verify the previous behavior (cargo recompiled
non-workspace crates) in the first commit.
Then updated it to verify the new behavior.

### Related links/notes

* I did some Git archaeology and I _think_ this behavior was introduced
in #2912
* While searching through the commit/pr history was never able to find
any explicit reason why the behavior is the way it is.
* Even if it was intentional, it has been 9 years since and Cargo's
fingerprinting/rebuild detection is much more mature now so I believe
its worth revisiting if this is still the desired behavior.
* Would help mitigate https://github.com/rust-lang/cargo/issues/14941
2025-08-12 19:27:53 +00:00
Ed Page
ece031c338
More helpful error for invalid cargo-features = [] (#15781)
The error message for unknown values of `cargo-features` was unhelpful:

```text
Caused by:
  unknown cargo feature `build-dir`
```

I've made it more explanatory, and matching the style of the other
errors:

```text
Caused by:
  feature `build-dir` is not a valid unstable feature for Cargo.toml

  This feature can be enabled via -Zbuild-dir or the `[unstable]` section in config.toml.
  See https://doc.rust-lang.org/cargo/reference/unstable.html for more information.
```
2025-08-12 18:29:21 +00:00
Ed Page
1e52a8c49a
Add initial integration for --json=timings behing -Zsection-timings (#15780)
### What does this PR try to resolve?

This PR adds initial support into Cargo for JSON timing sections,
implemented in rustc in https://github.com/rust-lang/rust/pull/142123.
This allows Cargo to read frontend/codegen/linking time from rustc, and
thus reporting slightly more detailed data in the `cargo build
--timings` output.

The PR modifies Cargo to tell rustc to emit the section messages
(`--json=...,timings`), and it adds the section timings data to the HTML
table output and the JSON output. It does not yet integration different
sections in the HTML unit chart (I want to do that as a follow-up).

Note that the JSON timings are currently only supported on the nightly
compiler (they are not stabilized). The new behavior is thus gated
behing an unstable Cargo flag (`-Zsection-timings`). When the flag is
unused, the HTML table should look more or less the same as before, just
that the code now supports both options.

### How to test and review this PR?

You can run e.g. this to generate the timing report with a nightly
compiler:
```bash
export RUSTC=`rustup +nightly which rustc`
target/debug/cargo build -Zsection-timings --timings
```
on some crate, e.g. [ripgrep](https://github.com/BurntSushi/ripgrep).

Tracking issue: https://github.com/rust-lang/cargo/issues/15817
2025-08-12 17:55:54 +00:00
Jakub Beránek
399dff887b
Add unstable -Zsection-timings flag 2025-08-12 17:42:28 +02:00
Kornel
45b4faa04a More helpful error for invalid cargo-features = [] 2025-08-12 13:44:44 +01:00