7177 Commits

Author SHA1 Message Date
Ed Page
27366fdea4
Added validation for unmatched brackets in build-dir template (#15414)
### What does this PR try to resolve?

This PR adds validation for unmatched brackets (which are used for
template variables) in `build.build-dir` paths.

See
https://github.com/rust-lang/cargo/issues/14125#issuecomment-2790803287
in #14125
2025-04-11 15:29:28 +00:00
Ross Sullivan
ad3e593e53
feat(build-dir): Added validation for unmatched brackets in template 2025-04-11 20:50:54 +09:00
Ross Sullivan
2a11c26af2
test(build-dir): Added test for unmatched brackets in build-dir path 2025-04-11 20:50:06 +09:00
Ed Page
f2c4849792
fix(package): detect dirtiness for symlinks to submodule (#15416)
### What does this PR try to resolve?

If a there is a symlink into a git repository/submodule,
when checking its git status with the wrong outer repo,
we'll get an NotFound error,
as the object doesn't belong to the outer repository.
This kind of error blocked the entire `cargo package` operation.

This fix additionally discovers the nearest Git repository,
and then checks status with that,
assuming the repo is the parent of the source file of the symlink.
This is a best effort solution, so if the check fails we ignore.

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

If we don't want the complication,
we could drop the last commit, ignore the error, and forget about
handling submodules

fixes #15384
fixes #15413
2025-04-10 17:25:19 +00:00
Weihang Lo
71ea2e5c5f
fix(package): detect dirtiness for symlinks to submodule
If a there is a symlink into a git repository/submodule,
when checking its git status with the wrong outer repo,
we'll get an NotFound error,
as the object doesn't belong to the outer repository.
This kind of error blocked the entire `cargo package` operation.

This fix additionally discovers the nearest Git repository,
and then checks status with that,
assuming the repo is the parent of the source file of the symlink.
This is a best effort solution, so if the check fails we ignore.
2025-04-10 12:43:10 -04:00
Weihang Lo
d760263afb
fix(package): ignore status check failure
Dirtiness check for symlinks is mostly informational.
And changes in submodule would fail git-status as well (see #15384).
To avoid adding complicated logic to handle that,
for now we ignore the status check failure.
2025-04-10 11:11:51 -04:00
Weihang Lo
79473988e5
test(package): show symlink to submodule failed the check 2025-04-10 11:11:44 -04:00
Ross Sullivan
50533934d0
feat(build-dir): Resolve symlinks before hashing workspace-path-hash
This commit resolves symlinks in the manifest path before hashing it.
2025-04-08 22:48:13 +09:00
Ross Sullivan
dc0d1133f9
test(build-dir): Added test for workspace-path-hash symlink handling 2025-04-08 22:48:07 +09:00
Ross Sullivan
54e5369584
feat(build-dir): Added build-directory to cargo metadata output 2025-04-02 21:38:35 +09:00
Ross Sullivan
155aaae22e
test(build-dir): Added build_directory field to cargo metadata output 2025-04-02 21:36:05 +09:00
Sebastian Poeplau
aa1b353d64 Prevent undeclared public network access
Stop a few tests which aren't marked with `public_network_test` from
trying to access crates.io. While doing so, also make sure that other
`cargo_add` and `cargo_info` tests initialize the registry.
2025-04-01 11:41:30 +02:00
Eric Huss
659e27413c Stabilize automatic garbage collection. 2025-03-31 09:28:44 -07:00
Ed Page
7220445a9d
feat: rustdoc depinfo rebuild detection via -Zrustdoc-depinfo (#15359)
### What does this PR try to resolve?

This leverages the unstable `--emit=depinfo` option from rustdoc,
so that rustdoc invocation rebuild can be better tracked
without traversing the entire directory.

Some design decisions made in the current implementation:

* Rustdoc's depinfo doesn't and shouldn't emit to `target/doc`,
  as the directory is considered part of the final artifact directory.
  In regard to that, we specify the dep-info output path to
  the fingerprint directory of rustdoc invocation.
  It looks like this
  `target/debug/.fingerprint/serde-12d29d32b3b8b38f/doc-lib-serde.d`.
* We also start supporting `-Zchecksum-freshness` as a side effect.
  Could make it a separate PR if desired.
* `-Zbinary-dep-depinfo` is not enabled along with this,
  since doc generations don't really require any binary dependencies.

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

The tests added has covered these cases:

* target src outside package root, e.g., `lib.path = "../lib.rs"`
* `#[doc = include_str!("../outside/pkgroot")]`
* `#[path = "../outside/pkgroot"]`
* `env!`

### Additional information

Fixes #12266
Closes #15205
2025-03-31 14:12:26 +00:00
Eric Huss
efb3419d47 Rename the gc config table
This renames the gc config table to `[cache]` to help avoid some
confusion, and to set up a namespace for possible expansion in the
future for different kind of cache controls.

Low-level settings are stuffed into the `[cache.global-clean]` table,
but we do not expect to stabilize these at this time. Only the top-level
`cache.auto-clean-frequency` setting is expected to be stabilized.

Closes https://github.com/rust-lang/cargo/issues/14292
2025-03-30 04:45:07 -07:00
Weihang Lo
a18e60462e
feat(fingerprint): integrate rustdoc dep-info files
This leverages the unstable `--emit=depinfo` option from rustdoc,
so that rustdoc invocation rebuild can be better tracked
without traversing the entire directory.

Some design decisions:

* Rustdoc's depinfo doesn't and shouldn't emit to `target/doc`,
  as the directory is considered part of the final artifact directory.
  In regard to that, we specify the dep-info output path to
  the fingerprint directory of rustdoc invocation.
  It looks like this
  `target/debug/.fingerprint/serde-12d29d32b3b8b38f/doc-lib-serde.d`.
* We also start supporting `-Zchecksum-freshness` as a side effect.
  Could make it a separate PR if desired.
* `-Zbinary-dep-depinfo` is not enabled along with this,
  since doc generations don't really require any binary dependencies.
2025-03-28 22:07:30 -07:00
Weihang Lo
1f6d4be081
test(doc): show scenarios cargo doc not rebuild 2025-03-27 22:45:49 -07:00
Eric Huss
bbce504bf3
Revert "Temporarily ignore cargo_test_doctest_xcompile_ignores" 2025-03-27 18:28:09 -07:00
Weihang Lo
95dafab660
feat(unstable): add -Zrustdoc-depinfo flag 2025-03-27 11:55:55 -04:00
Chris Denton
d82b596962
Don't canonicalize in cargo_exe 2025-03-26 23:47:08 +00:00
Weihang Lo
a24066a79c
fix(package): update tracking issue for --message-format 2025-03-26 13:37:01 -04:00
Weihang Lo
e354769b1f
feat(package): JSON message format for --list 2025-03-25 23:02:37 -04:00
Weihang Lo
781c7ed515
feat(package): add unstable --message-format flag
The behavior is not implemented yet
2025-03-25 23:02:37 -04:00
Eric Huss
6a70640c91
do not pass cdylib link args to test (#15317)
<!--
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.
-->

fixes #12663
2025-03-25 18:57:24 +00:00
Weihang Lo
259128d270
fix: revert the behavior checking lockfile's VCS
Lockfile might be gitignore'd,
So it never shows up in `git status`.

However, `cargo packag` vcs checks actually performs
`git status --untracked --ignored`.
It is a bit confusing that lockfile is ignored but still counts as dirty
from the report of `cargo package`.

There are some more nuances:
We check lockfile's VCS status if the lockfile is ouside the current
package root. That means a non-workspace Cargo package will not have
this VCS check. I don't think it is good that we have diverged behaviors
Hence this revert.

We can always re-evaluate later,
as we've reserved rooms for doing more dirty checks.

https://github.com/rust-lang/cargo/issues/14967#issuecomment-2651329783
2025-03-25 13:15:34 -04:00
Eric Huss
98a273f770 Temporarily ignore cargo_test_doctest_xcompile_ignores
This was broken due to a change in
https://github.com/rust-lang/rust/pull/138535. There is an approved PR
in https://github.com/rust-lang/rust/pull/138877 to fix it, but it may
take a day or two for it to make its way to nightly. This should be
reverted after it hits nightly.
2025-03-25 08:02:22 -07:00
Eric Huss
0b2299e889 Remove an excess newline
The udpate_message already has a newline when it is there. When it is an
empty string, it ends up adding an unnecessary blank line.
2025-03-21 16:32:28 -07:00
Eric Huss
b17b9a4b90 Elaborate the full output when there are newer versions available
This output was never tested.
2025-03-21 16:32:28 -07:00
Eric Huss
4d961ed19c Don't show a suggestion to update dependencies
This removes the suggestion to update dependencies when the future
incompat error comes from the local crate. It doesn't make sense to
suggest that.
2025-03-21 16:32:28 -07:00
Eric Huss
497cfe5e48 Remove excess trailing space 2025-03-21 16:32:28 -07:00
Eric Huss
3fb97ecf28 Fix off-by-one error when future-incompat report is cached
This fixes a problem introduced by
https://github.com/rust-lang/cargo/pull/11648 where the future-incompat
report will tell you to run with an `--id` flag with the wrong value
if the report is already cached.

The solution is to add a method to determine which ID to use for the
suggestions *before* attempting to save the report.
2025-03-21 16:32:26 -07:00
Eric Huss
afdfd9263e Add some more explicit future-incompat tests
This updates some tests to include the full output for both a local
crate and a dependency.
2025-03-21 16:26:45 -07:00
Eric Huss
941c414a90 Add test for cached report id 2025-03-21 16:04:43 -07:00
Ed Page
7440762a78
fix(build-dir): Renamed workspace-manifest-path-hash to workspace-path-hash (#15334)
<!--
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?

Small PR to rename `workspace-manifest-path-hash` to
`workspace-path-hash` in the build-dir template as mentioned
[here](https://github.com/rust-lang/cargo/issues/14125#issuecomment-2733611870)
(cc: #14125)

r? @epage
2025-03-20 19:51:15 +00:00
NOOMA-42
3ea0e6b751
feat: vcs, color, and message format native completion 2025-03-20 22:16:27 +08:00
Ross Sullivan
5b077cb489
chore(build-dir): Renamed workspace-manifest-path-hash to workspace-path-hash 2025-03-20 12:16:40 +09:00
usamoi
9dbf5b0b67 do not pass cdylib link args to test 2025-03-19 20:20:45 +08:00
Eric Huss
5516ffa1c3 Add a test for rustc-cdylib-link-arg
We didn't have any tests that included the old `rustc-cdylib-link-arg`
form.
2025-03-18 16:28:09 -07:00
Eric Huss
01c529349b
fix(toml): Report '<target>.edition' deprecation to users (#15321)
### What does this PR try to resolve?

This is a part of rust-lang/cargo#15283

In the RFC, I mentioned this might be blocked on #12235.
In hindsight, the use of this is [rare
enough](https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/Deprecate.20build-target.20.60edition.60.20field.3F/near/499047806)
that I suspect we can go ahead and warn without user controllable lints.

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

### Additional information
2025-03-18 19:13:03 +00:00
Weihang Lo
b65e1dde25
test(build-std): address overly-matched snapshot
Still trying to bisect what went wrong,
but this should be fairly safe to merge.

Failed on nightly-2025-03-18 but not nightly-2025-03-17 btw.
2025-03-18 13:55:52 -04:00
Ed Page
68c26f6c3f
Added build.build_dir templating support (#15236)
### What does this PR try to resolve?

This PR is a follow up on #15104 and and adds support for the path
templating in `build.build-dir` as defined in #14125.

Supported templates:
* `{workspace-root}`
* `{cargo-cache}` (pointing to `CARGO_HOME` for now)
* `{workspace-manifest-path-hash}`

#### Unresolved questions

What should we name `{workspace-manifest-path-hash}` and what should it
include? Should we shorten to `{workspace-hash}` or even just `{hash}`?
Should we include the Cargo version so we get unique whole-target
directories for easier cleanup (#13136)

How should this handle unknown variables (error) or unclosed `{` / `}`
(ignored), see
https://github.com/rust-lang/cargo/pull/15236#discussion_r1977898973

When using `{workspace-manifest-path-hash}` this hash will change based
on the project path. In the event of a cargo being executed in a
symlinked project, the hash will change.

For example, given the following directory
```
/Users/
└─ user1/
    └─ projects/
        ├─ actual-crate/
        │  └─ Cargo.toml
        └─ symlink-to-crate/ -> actual-crate/
```

the hash will be unique when running cargo from each of the following
directories.
* `/Users/user1/actual-crate`
* `/Users/user1/symlink-to-crate`

Figuring out whether to handle this is deferred out, see
- https://github.com/rust-lang/cargo/pull/15236#discussion_r1971938021
-
https://github.com/poliorcetics/rfcs/blob/cargo-target-directories/text/3371-cargo-target-dir-templates.md#symbolic-links
-
https://github.com/rust-lang/cargo/issues/12207#issuecomment-2711402159

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

This PR is fairly small. I included tests for each template variable.

You can also clone my branch and test it locally with
```console
CARGO_BUILD_BUILD_DIR='{workspace-root}/foo' cargo -Z build-dir build
```

### Additional information

While searching Cargo for any prior art for path templating, I found
[`sources/registry/download.rs`](https://github.com/rust-lang/cargo/blob/master/src/cargo/sources/registry/download.rs#L84)
doing a simple string replace. Thus I followed the same behavior.

r? @epage
2025-03-17 18:29:17 +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
Ross Sullivan
229489e9b3
Added invalid variable validation for build.buil-dir path templating.
This commit adds logic to check for unexpected variables in templated
paths like `build.build-dir`. Cargo will error if it finds a variable
that it does not know how to expand.
2025-03-15 17:24:45 +09:00
Ross Sullivan
76e54339f7
Added test for unknown templating variables 2025-03-15 17:24:40 +09:00
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
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
Ross Sullivan
ba4df9f86b
Implemented templating support for build.build-dir 2025-03-14 20:11:51 +09:00
Ross Sullivan
d0a3ec7366
Added build_dir templating tests.
This is in preparation for adding templating suppport to
the `build.build-dir` configuration option.
2025-03-14 20:11:51 +09: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