7252 Commits

Author SHA1 Message Date
dawe
0df8d68cf9
feat(add): check if given crate argument would be valid with inserted @ symbol, suggest fixed argument 2025-04-27 01:23:51 +02:00
dawe
98326ac0f5
feat(install): check if given crate argument would be valid with inserted @ symbol, suggest fixed argument 2025-04-27 01:23:48 +02:00
dawe
ab0d6a7bd2
test(add): add test to show current behaviour of cargo add when @ symbol is missing for the version 2025-04-27 01:23:26 +02:00
dawe
77f54cc658
test(add): add test to show current behaviour of cargo install when @ symbol is missing for the version 2025-04-26 22:01:38 +02:00
Weihang Lo
ee85adae45
Update doctest xcompile flags (#15455)
This updates the flags used for doctest xcompile to match the upstream
changes in https://github.com/rust-lang/rust/pull/137096 which renamed
and stabilized the flags.

This cannot be merged until after nightly is published tonight.
2025-04-26 13:35:28 +00:00
Eric Huss
f10630f2bf Update doctest xcompile flags
This updates the flags used for doctest xcompile to match the upstream
changes in https://github.com/rust-lang/rust/pull/137096 which renamed
and stabilized the flags.
2025-04-26 06:07:27 -07:00
Ed Page
fb3906d3ab
fix: Suggest similar looking feature names when feature is missing (#15454)
### What does this PR try to resolve?

I recently depended on a package with `preserve-order` rather than
`preserve_order` and the error message didn't help me with the problem
so I figure I'd fix that. I also found other improvements along the way

- Suggest an alternative feature when a feature includes a missing
feature
- Suggest an alternative feature when a dependency includes a missing
feature
- Lower case error messages
- Re-frame prescriptive information as help
- Change plural "features" error messages to singular "feature" as they
can only ever have one (knowing an the `MissingFeature` string only has
one feature in it was important for doing a `closest` match on the
feature).

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

### Additional information
2025-04-25 19:45:13 +00:00
Ed Page
08ed8de4d1 fix(resolver): Suggest similar looking features 2025-04-25 09:21:09 -05:00
Ed Page
f616aaf21a fix(resolver): Make features singular; we only track one 2025-04-24 20:47:03 -05:00
Ed Page
3fd3656479 fix(resolver): Have errors follow rustc's casing convention 2025-04-24 20:40:54 -05:00
Ed Page
93c734b395 fix(features): When feature activates a typo, suggest alt 2025-04-24 16:36:30 -05:00
Ed Page
a38d44c2b0 test(features): Show typoed feature behavior 2025-04-24 16:33:15 -05:00
Ed Page
a1c464457b test(features): Clarify test names 2025-04-24 16:23:54 -05:00
Axel PASCON
55952a3c61 fully fixes #15445
changes summary :
	- change the `pkg_id` field of `struct SerializedUnit<'a>` to be `PackageIdSpec` instead of `PackageId`
	- change the unit-graph testcases to match the changes

(cleaning previous commits so every commit passes CI checks, as required)
2025-04-23 13:19:45 +02:00
Ed Page
69eeb6ad94
Implement RFC3695: Allow boolean literals as cfg predicates (#14649)
### What does this PR try to resolve?

This PR implements https://github.com/rust-lang/rfcs/pull/3695: allow
boolean literals as cfg predicates, i.e. `cfg(true)` and `cfg(false)`.

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

The PR should be reviewed commit by commit and tested by looking at the
tests and using `[target.'cfg(<true/false>)']` in
`Cargo.toml`/`.cargo/config.toml`.

### Additional information

I had to bump `cargo-platform` to `0.3.0` has we are changing `CfgExpr`
enum in a semver incompatible change.

We currently have (thks to
https://github.com/rust-lang/cargo/pull/14671) a forward compatibility
warning against `cfg(true/false)` as identifiers instead of keywords.

~~I choose a use a `Cargo.toml` feature (for the manifest) as well as a
unstable CLI flag for the `.cargo/config.toml` part.~~

~~Given the very small (two occurrences on Github Search) for
[`cfg(true)`](https://github.com/search?q=lang%3Atoml+%2F%28%3F-i%29%5C%5Btarget%5C.%5B%27%22%5Dcfg.*true%2F&type=code)
and
[`cfg(false)`](https://github.com/search?q=lang%3Atoml+%2F%28%3F-i%29%5C%5Btarget%5C.%5B%27%22%5Dcfg.*false%2F&type=code),
I choose to gate the feature under a error and not a warning.~~
2025-04-22 17:54:52 +00:00
Urgau
9563738dff Add support for boolean literals in target cfgs 2025-04-22 19:23:03 +02:00
Urgau
9a7a8cfb3b Add tests in preparation of boolean literal support in cfgs 2025-04-22 19:22:38 +02:00
Rustin170506
75a8cdd5a9 fix: default to all targets when using --edition and --edition-idioms in cargo fix
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-04-16 17:21:51 +08:00
Weihang Lo
ef7d315894
Make sure search paths inside OUT_DIR precede external paths (#15221)
If a library exists both in an added folder inside OUT_DIR and in the
OS, prefer to use the one within OUT_DIR. Folders within OUT_DIR and
folders outside OUT_DIR do not change their relative order between
themselves.

This is accomplished by sorting by whether we think the path is inside
the search path or outside.

### What does this PR try to resolve?

Fixes #15220. If a Rust crates builds a dynamic library & that same
dynamic library is installed in the host OS, the result of the build's
success & consistent behavior of executed tools depends on whether or
not the user has the conflicting dynamic library in the external search
path. If they do, then the host OS library will always be used which is
unexpected - updates to your Rust dependency will still have you linking
& running against an old host OS library (i.e. someone who doesn't have
that library has a different silent behavior).

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

This is what I did to verify my issue got resolved but I'm sure there's
a simpler example one could construct.

* Make sure Alsa and libllama.so are installed (on Arch I installed
alsa-lib and llama.cpp-cuda).
* Clone llama-cpp-2 & init llama.cpp submodule & update the submodule to
point to https://github.com/ggml-org/llama.cpp/pull/11997 instead.
* Add plumbing to expose the new method within llama-cpp-2 as a public
facing function on the LlamaModel struct (it's basically the same code
as for n_head, just calling n_head_kv from llama.cpp).
* Add cpal as a dependency in crate "foo"
* Add llama-cpp-2 via path as a dependency in crate "foo" and enable the
`dynamic-link` feature.
* Add code using the newly expose n_head_kv method in crate "foo" in
main.rs. NOTE: Code just needs to compile & be exported, doesn't have to
be correct (fn main is probably easiest.
* Add some basic code that tries to initialize cpal in crate "foo" in fn
main.
* Try to build / run crate "foo"

Before my change, it fails with a linker error saying it can't find
`llama_model_n_head_kv` because /usr/lib appears in the search path
before the directory that contains the libllama.so that was built
internally by the crate. This is because cpal depends on alsa-sys which
uses pkg-config which adds /usr/lib to the search path before the
llama-cpp-sys-2 build.rs is run.

### Additional information

I'm not sure how to add tests so open to some help on that. I wanted to
make sure that this approach is even correct. I coded this to change
Cargo minimally and defensively since I don't know the internals of
Cargo very well (e.g. I don't know if I have to compare against both
`script_out_dir` / `script_out_dir_when_generated` since I don't know
the difference & there's not really any explanation on what they are).

It's possible this over-complicates the implementation so open to any
feedback. Additionally, the sort that happens prior to each build up of
the rustc environment is not where I'd ideally place it. I think it
would be more efficient to have the list of search paths be
free-floating and not tied to a BuildOutput so that they could be kept
updated live & resorted only on insertion (since it's changed less
frequently than rustc is invoked). Additionally, the generalized sort is
correct but pessimistic - maintaining the list sorted could be done
efficiently with some minor book keeping (i.e. you'd only need to sort
the new paths & then could quickly inject into the middle of a
VecDeque).

And of course in terms of correctness, I didn't do a thorough job
testing across all possible platforms. From first principles this seems
directionally correct but it's always possible this breaks someone
else's workflow. I'm also uneasy that the relative position of `-L` /
`-l` arguments changes in this PR & I'm not sure if that's observable
behavior or not (i.e. it used to be -L for a crate followed by `-l` for
a crate), but now it's `-L` for all crates, still grouped by crated
internally, followed by `-l` by crate).
2025-04-12 14:04:50 +00:00
Ed Page
a7e0e44994
Revert "fix(package): detect dirtiness for symlinks to submodule" (#15419)
### What does this PR try to resolve?

This reverts commit 71ea2e5c5fa285e8e0336d51fd03ba4a427154bf.

`Repository::discover` and `Repository::status_file` are too expenstive
to run inside a loop. And `cargo package` are doing a lot of duplicate
works for checking submodule VCS status.

Alternative fixes might look like

* Let `status_submodules` function returns a path entry set, so
  Cargo can check whether a source file is dirty based on that.
* When listing files in `PathSource`, attach the VCS status of a
  path entry assoicated with. Then subsequent operations can skip
  status check entirely.

However, the above solutions are not trivial, and the dirtiness check is
informational only based on T-cargo conclusion, so we should be
good just reverting the change now.

Again, the caveat of this is that we can't really detect
dirty symlinks that link into a Git submodule.

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

Should be good to merge. We still got #15384 fixed via
d760263afb02c747a246bb0471a4f51e09075246

### Additional information

See
<https://github.com/rust-lang/cargo/issues/15384#issuecomment-2797064033>.
2025-04-11 18:41:15 +00:00
Weihang Lo
314df11c74
Revert "fix(package): detect dirtiness for symlinks to submodule"
This reverts commit 71ea2e5c5fa285e8e0336d51fd03ba4a427154bf.

`Repository::discover` and `Repository::status_file` are too expenstive
to run inside a loop. And `cargo package` are doing a lot of duplicate
works for checking submodule VCS status.

The possible fix might look like

* Let `status_submodules` function returns a path entry set, so
  Cargo can check whether a source file is dirty based on that.
* When listing files in `PathSource`, attach the VCS status of a
  path entry assoicated with. Then subsequent operations can skip
  status check entirely.

The above solutions are not trivial, and the dirtiness check is
informational only based on T-cargo conclusion, so we should be
good just reverting the change now.

Again, the caveat of this is that we can't really detect
dirty symlinks that links into a Git submodule.
2025-04-11 14:04:38 -04:00
Ross Sullivan
fac2aafa11
feat(build-dir): Added improved error message when template is invalid 2025-04-12 02:20:15 +09:00
Vitali Lovich
6c6b34ea27 Search cargo build directories before system for libraries
Regardless of crate search paths emitted, always prefer searching search
paths pointing into the artifacts directory to those pointing outside.
This way libraries built by Cargo are preferred even if the same library
name exists in the system & a crate earlier in the build process emitted
a system library path for searching.
2025-04-11 09:42:11 -07:00
Vitali Lovich
f94b75aeb6 Add test case for current behavior. 2025-04-11 09:42:11 -07:00
Ross Sullivan
389f263a79
test(build-dir): Add test for build-dir template nearest suggestion 2025-04-12 01:20:05 +09:00
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