7210 Commits

Author SHA1 Message Date
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
Kornel
5fff1e0e76 Duplicates of unknown_feature test 2025-08-12 13:28:00 +01:00
Weihang Lo
58ff5efe61
test(build-std): relax the thread name assertion
rust-lang/rust#115746 changed to print thread ID,
so we update accordingly.
2025-08-08 17:34:48 -04:00
Naman Garg
aca513a24b
Preserve order of build scripts 2025-08-07 00:56:14 +05:30
Naman Garg
8be51ef2d6
Add test for multiple build scripts in different order 2025-08-05 23:33:54 +05:30
houpo-bob
cbef1d150a chore: fix some minor issues in comments
Signed-off-by: houpo-bob <houpocun@outlook.com>
2025-07-30 15:53:03 +08:00
Ross Sullivan
81f119d45a
fix(package): Fixed inconsistent build cache behavior during package verify
When running `cargo package` the verify the build cache
(target-dir/build-dir) will not be used and all dependencies will be
recompiled.

This is inconsistent as setting target dir (via `CARGO_TARGET_DIR` for
example) will cause `cargo package` to reuse the build cache.

This commit changes the default behavior to always use the build cache,
matching the behavior of having target-dir set.
2025-07-29 21:59:18 +09:00
Ross Sullivan
84e4277dc4
test(package): Add test to verify package build cache behavior 2025-07-29 21:46:25 +09:00
Weihang Lo
dfcf4c2cbd
fix: no-proc-macro is overridden by subsequent edges (#15764)
### What does this PR try to resolve?
To close #15763.

### How to test and review this PR?
See steps in #15763.
2025-07-23 16:56:18 +00:00
ChenRuiwei
2654f29ddb fix: no-proc-macro is overridden by subsequent edges 2025-07-24 00:06:54 +08:00
ChenRuiwei
4fdd6ecbab test: add test for no-proc-macro order issue 2025-07-24 00:06:54 +08:00
Weihang Lo
9b5231f892
Use gix for cargo package (#15534)
This should also help fixing these spurious "cannot package because some
excluded file is untracked" issues.

### Tasks

* [x] step-by-step conversion of `vcs.rs`
* [x] use proper feature toggle
* [x] ~~cleanup~~ final check by myself
* [ ] ~~move split & rename into its own commit. Probably squash all
changes except for the gix upgrade.~~
     - I like to have the major stages of this PR conserved.
* [x] upgrade to a gix release including
https://github.com/GitoxideLabs/gitoxide/pull/2016
     - This was done in `master` already.
* [x] fix tests by fixing `gix` - `submodules()` call isn't bare-repo
safe.
* [x] fix failure on Windows
- `gix status` seems to go through a symlink, arriving at the wrong
conclusion, on Windows.
* [x] fix performance regression on `aws-sdk-rust`.

### Notes for the Reviewer

* This implementation is both faster and more correct, thus affects
#15416 and #14955.

Related to https://github.com/GitoxideLabs/gitoxide/issues/106.
2025-07-23 03:13:49 +00:00
Sebastian Thiel
d3b85cd96a
Provide a package implementation with gix-status.
This should also help fixing these spurious "cannot package because
some excluded file is untracked" issues.

Remove the respective `git2` implementation at the same time
as there seems to be no need for it.
2025-07-23 04:36:07 +02:00
Noratrieb
a6e1f11d4e Remove unnecessary target-c-int-width from target specs
This is not necessary, as 32 is the default, and actually of the wrong
type now since it's a number now.
When planning to make these type mismatches error, cargo would fail
here, so I just removed it.

This custom target test very much shows how Cargo should be a subtree,
in this case it was fine because there's a compatible fix that I can
push now, otherwise it would have been very annoying.
2025-07-20 15:04:25 +02:00
Josh Triplett
e44bde554d Respect capped lints for dependencies 2025-07-12 14:55:10 -07:00
Josh Triplett
78b4afb4f3 Expand test to produce warnings for deps, which will subsequently get capped 2025-07-12 14:54:56 -07:00
Josh Triplett
9949fa8a66 Include package ID in warnings to identify affected crate 2025-07-12 14:47:27 -07:00
Josh Triplett
fe86023863 Parse hints permissively to allow for future expansion
Make it only a warning, not an error, to have a hint value of the wrong
type.
2025-07-11 16:54:36 -07:00
Josh Triplett
1921d097ca Add [hints] table in Cargo.toml, and a hints.mostly-unused hint
The `[hints]` table in a `Cargo.toml` manifest provides optional
information that Cargo can use for building the package, and will use
even when using the package as a dependency. All hints can be safely
ignored, and Cargo only warns about unknown hints, but does not error.
This allows packages to use hints without depending on new Cargo.

Add a `mostly-unused` hint, which allows a package to hint that most
users of the package will not use most of its items. This is useful for
improving the build performance of crates with large dependencies.

Crates can override this hint using `hint-mostly-unused = false` in
their profile for a dependency.
2025-07-11 16:54:36 -07:00
Josh Triplett
f415c112f9 Add additional tests for hints.mostly-unused (showing existing behavior)
These tests demonstrate the behavior of current Cargo, and will be
changed when adding `hints.mostly-unused` to reflect the new behavior.
2025-07-11 16:54:36 -07:00
Josh Triplett
a206766e43 Add initial version of hints tests, to show pre-[hints] Cargo behavior
These tests show what prior versions of Cargo will do with hints.
The subsequent addition of support for hints will modify these tests to
reflect the corresponding changes to Cargo.
2025-07-11 16:54:30 -07:00
Ed Page
eabb4cd923
feat: Implementation and tests for multiple-build-scripts (#15704)
Hi Everyone!

This is PR for the implementation of the first milestone of [GSoC
Project : Build Script
Delegation](https://summerofcode.withgoogle.com/programs/2025/projects/nUt4PdAA)

This will provide actual implementation for #15630

### What does this PR try to resolve?

Now, multiple build scripts are parsed, this PR aims to implement the
functioning the feature. This PR will allow users to use multiple build
scripts, and is backward compatible with single script as well as
boolean values.

**Motivation :** This will help users to maintain separate smaller and
cleaner build scripts instead of one large build script. This is also
necessary for build script delegation.

Deferred
- Accessing each build script's `OUT_DIR`: This will be handled in a
follow up PR. For now, each build script writes to its own `OUT_DIR` and
`OUT_DIR` for the regular build targets is set to the build script with
the **lexicographically largest** name..
- User control over which build script wins in a conflict. This will be
handled in a follow up PR. If two build scripts write to the same env
variable, which gets applied to the binary? Currently, its the build
script with the **lexicographically largest** name. This makes it
deterministic. With some futzing, users can control this for now.
However, with build script delegation, users won't be able to control
this. We likely want it based off of the order the user assigns into the
build script array.
- Something about linking a C library is actually preferring
**lexicographically smallest** name. We should handle conflicts
consistently. We need to dig into what parts are doing it based on
smallest and make sure that whatever priority scheme we use for env
variables applies here as well.

### How to test and review this PR?

There is a feature gate `multiple-build-scripts` that can be passed via
`cargo-features` in `Cargo.toml`. So, you have to add
```toml
cargo-features = ["multiple-build-scripts"]
```
Preferably on the top of the `Cargo.toml` and use nightly toolchain to
use the feature
2025-07-09 22:07:55 +00:00
Naman Garg
bfb869748c
Use Vector for build script Units and UnitHash 2025-07-10 03:02:58 +05:30
Naman Garg
a24abd6fc2
Add multiple build scripts to unit deps 2025-07-10 03:02:34 +05:30
Naman Garg
72290ad03a
Replace build with check in test rerun_untracks_other_files 2025-07-09 02:38:52 +05:30
Naman Garg
e9df793c47
Add tests for multiple build scripts execution 2025-07-09 02:38:50 +05:30
Ed Page
539a48452a perf: Update toml 2025-07-08 11:55:41 -05:00
Uyiosa Iyekekpolor
bc43610058 mark cachelock tests that rely on interprocess blocking behaviour as unsuported on AIX 2025-07-08 10:09:25 -04:00
Ed Page
c8bf4096de feat(publish): Stabilize multi-package publishing
A user will now be able to use flags like `--workspace` with `cargo
publish`.
`cargo package` will now also work with those flags without having to
pass `--no-verify --exclude-lockfile`.

Many release tools have come out that solve this problem.
They will still need a lot of the logic that went into that for other
parts of the release process.
However, a cargo-native solution allows for:
- Verification during dry-run
- Better strategies for waiting for the publish timeout

`cargo publish` is non-atomic at this time.
If there is a server side error, network error, or rate limit during the publish,
the workspace will be left in a partially published state.
Verification is done before any publishing so that won't affect things.
There are multiple strategies we can employ for improving this over time,
including
- atomic publish
- `--idempotent` (#13397)
- leave this to release tools to manage

This includes support for `--dry-run` verification.
As release tools didn't have a way to do this before,
users may be surprised at how slow this is because a `cargo build` is
done instead of a `cargo check`.  This is being tracked in #14941.

This adds to `cargo package` the `--registry` and `--index` flags to
help with resolving dependencies when depending on a package being
packaged at that moment.
These flags are only needed when a `cargo package --workspace` operation
would have failed before due to inability to find a locally created
dependency.

Regarding the publish timeout, `cargo publish --workspace` publishes
packages in batches and we only timeout if nothing in the batch has
finished being published within the timeout, deferring the rest to the
next wait-for-publish. So for example, if you have packages `a`, `b`, `c` then
we'll wait up to 60 seconds and if only `a` and `b` were ready in that time,
we'll then wait another 60 seconds for `c`.

During testing, users ran into issues with `.crate` checksums that we've
not been able to reproduce since:
- https://github.com/rust-lang/cargo/issues/1169#issuecomment-2567995987
- #14396

By stabilizing this, Cargo's behavior becomes dependent on an overlay
registry.
When generating a lockfile or verifying a package, we overlay the
locally generated `.crate` files on top of the registry so the registry
appears as it would and everything works.
If there is a conflict with a version, the local version wins which is
important for the dry-run mode of release tools as they won't have
bumped the version yet.
Our concern for the overlay registry is dependency confusion attacks.
Considering this is not accessible for general user operations, this
should be fine.

Fixes #1169
Fixes #10948
2025-06-30 09:27:59 -05:00
Eric Huss
1ce8023626 Rustfmt 2024 2025-07-05 19:50:36 -07:00
Eric Huss
1213fc652b Apply rust_2024_incompatible_pat 2025-07-05 19:27:01 -07:00
Tom Fay
c74fadc0e5 Enforce pkgid and sbom consistency
clarify fully qualified package ID usage in docs
2025-07-05 20:59:07 +01:00
Weihang Lo
848e5a23c0
test: Switch config tests to use snapshots (#15729)
### What does this PR try to resolve?

This is prep for updating `toml` which will change some of these error
messages

### How to test and review this PR?
2025-07-05 15:38:48 +00:00
Ed Page
3488e267ee test: Switch config tests to use snapshots 2025-07-05 10:04:44 -05:00
David Mládek
70f16f448b feat: add the package feature unification option 2025-07-02 00:01:52 +02:00
David Mládek
403f1e12f6 tests: add future package feature unification tests 2025-07-02 00:01:51 +02:00
Ed Page
714157308b
Report valid file name when we can't find a build target for name = "foo.rs" (#15707)
fixes #15703
2025-07-01 20:49:34 +00:00
Marijn Schouten
6eb5adcc50 bad_config: replace cargo build with cargo check 2025-07-01 19:55:58 +00:00
Marijn Schouten
e2987afda7 move config tests from build.rs to bad_config.rs 2025-07-01 18:58:41 +00:00
Marijn Schouten
87a24aa734 better msg for bug #15703 2025-07-01 18:53:33 +00:00
Marijn Schouten
56602aacd1 fix bug #15703 2025-07-01 08:06:47 +00:00
Marijn Schouten
01850417d7 add test for bug #15703 2025-07-01 07:35:27 +00:00
Ed Page
f013ef54bb
Override Cargo.lock checksums when doing a dry-run publish (#15711)
Fixes #15647.

When dry-run publishing workspace without bumping versions first, the
package-verification step would fail because it would see checksum
mismatches between the old lock file (that saw index deps) and the new
lock file where those index deps got replaced by local packages with the
same version.

In this PR, the packaging step modifies the old lock file's checksums
before re-resolving, but only in dry-run mode.
2025-06-30 20:20:41 +00:00