11938 Commits

Author SHA1 Message Date
Jon Heinritz
4d38888900 feat(cli): forward bash completions of third party subcommands 2025-02-28 18:36:00 +01:00
Ed Page
9b6e11e9b0 feat(tree): Color lines by dependency type 2025-02-28 09:46:50 -06:00
Ed Page
fb5407db7a feat(tree): Warn through colors for elided content 2025-02-28 09:46:08 -06:00
Weihang Lo
58cfd96b59
fix: reset $CARGO if the running program is real cargo[.exe] (#15208)
Overwrite `$CARGO` when the current exe is detected to be a cargo
binary.

From
https://github.com/rust-lang/cargo/issues/15099#issuecomment-2666737150:
> opt-in behavior (set by cargo-the-bin):
>
> 1. `from_current_exe` if its `cargo[EXE_SUFFIX]`
> 2. `from_argv` if its `cargo[EXE_SUFFIX]`
> 3. `from_env`
> 4. `from_current_exe`
> 5. `from_argv`

r? @epage
2025-02-28 15:04:52 +00:00
Ed Page
726e2a70ea
Get all members as available targets even though default-members was specified. (#15199)
### What does this PR try to resolve?

The old behavior gets members from `default-members` if specified in a
virtual workspace, this PR gets all workspace members for `Available`
target hints.

Fixes https://github.com/rust-lang/cargo/issues/14544

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

The first commit added the test, the second commit addressed the issue.

### Additional information
2025-02-28 14:48:42 +00:00
Ed Page
8686e24c72
refactor: control byte display precision with std::fmt options (#15246)
### What does this PR try to resolve?

Just found we can simplify `human_readable_bytes` a bit.
This also remove the `bytesize` dependency,
since we already have a hand-rolled function.
(It is a good crate, though)

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

Should have no real functional difference.
`cargo package` starts reporting IEC (KiB) instead of SI (KB).
So do some thresholds of `cargo package`.

Could also switch entirely to `bytesize` if that is preferred.

### Additional information
2025-02-28 14:32:42 +00:00
Weihang Lo
8f1122defb
refactor: use HumanBytes instead
This removes one dependency bytesize as it hasn't yet support
controlling precision throught format options.
2025-02-28 08:56:28 -05:00
Weihang Lo
425858c742
refactor: control byte display precision with std::fmt options 2025-02-28 08:56:28 -05:00
Weihang Lo
d5b25b824a
fix(package): Ensure we can package directories ending with '.rs' (#15240)
### What does this PR try to resolve?

This likely only affects `-Zpackage-workspace` but it might have also
broken dependencies whose path ends with `.rs` as
well

This broke in https://github.com/rust-lang/cargo/pull/14961

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

### Additional information
2025-02-28 13:17:40 +00:00
utnim2
ad2b1ee7d6 feat: add completions for --lockfile-path 2025-02-28 14:13:22 +05:30
Yihai Lin
fa7712da82 feat: Make no target found hint more clear. 2025-02-28 10:03:59 +08:00
Yihai Lin
bac98aaa9f refactor: clean some duplicate code. 2025-02-28 10:01:17 +08:00
Yihai Lin
5ad084c3b0 feat(workspace): Search other crates if the default-members doesn't have the Target 2025-02-28 10:00:28 +08:00
Ed Page
730348ada9 fix(package): Ensure we can package directories ending with '.rs'
This might have also broken dependencies whose path ends with `.rs` as
well

This broke in #14961
2025-02-27 14:50:56 -06:00
Arlo Siemsen
5f833db69b feat: Add SBOM pre-cursor files
Adds a new option `build.sbom` that adds generation of a JSON file
containing dependency information alongside compiled artifacts.
2025-02-26 14:57:14 -06:00
Ed Page
3952e2dd28 feat(tree): Add --depth public impl 2025-02-26 14:51:54 -06:00
Ed Page
224222ee34 feat(tree): Add '--depth public' feature-gated value 2025-02-26 14:51:11 -06:00
Ed Page
038bd06a84 refactor(tree): Allow failing during printing 2025-02-26 14:51:09 -06:00
Ed Page
128604fe74 refactor(tree): Make debugging node ids easier
I found when debugging some issues with edges,
having to track indices was making things much more difficult.
My hope is this will help with little negative impact.

We could put this behind a `#[cfg(debug_asserts)]` but I'm assuming it
doesn't make enough of a performance difference to matter.
2025-02-26 14:24:17 -06:00
Ed Page
822135d22e refactor(tree): Manually implement comparison traits 2025-02-26 14:16:04 -06:00
Ed Page
2e007b5584 refactor(tree): Use a newtype to track node indexes
The primary goal is to make the code more type safe / easier to follow.

This also can allow tracking debug information.
2025-02-26 13:53:35 -06:00
Ed Page
0659425f38 refactor(tree): Don't look up edges directly 2025-02-26 13:46:29 -06:00
Ed Page
9700a89040 refactor(tree): Be more specific edges is filtered 2025-02-26 13:45:05 -06:00
Ed Page
606cd71c38 refactor(tree): Don't look up nodes directly 2025-02-26 13:43:05 -06:00
NoisyCoil
4e8b337eb3
feat(package): add --exclude-lockfile 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.
2025-02-26 12:48:48 -05:00
Ed Page
05e5d6e354 refactor(tree): Abstact edges for feature 2025-02-25 11:40:10 -06:00
Ed Page
0fd5de00c8 refactor(tree): Abstract Edges 2025-02-25 11:13:24 -06:00
Ed Page
712f98467c refactor(tree): Abstract the concept of an Edge 2025-02-25 11:13:24 -06:00
Ed Page
6bfa8c7cad refactor(tree): Make variable names consistent 2025-02-25 11:13:24 -06:00
Ed Page
7290e2e3a0 refactor(tree): Destructure tuple for clarity 2025-02-25 11:13:24 -06:00
Ed Page
ffafda8fd4
fix(package): Register workspace member renames in overlay (#15228)
### What does this PR try to resolve?

This was reported at
https://github.com/rust-lang/cargo/issues/10948#issuecomment-2674289330

For the exact mapping between the publish payload and the index,
see

https://doc.rust-lang.org/cargo/reference/registry-index.html#json-schema,
particularly the note about differences.

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

### Additional information

I suspect there is a second bug here because my debugging only showed us
hitting this scenario for `val-json` and not `concepts` and only when
building `utils`. That difference in behavior between a transitive and
direct dependency is odd.
2025-02-25 15:19:55 +00:00
Ed Page
ef12f10bfc
Implemented build.build-dir config option (#15104)
## What does this PR try to resolve?

This PR adds a new `build.build-dir` configuration option that was
proposed in
https://github.com/rust-lang/cargo/issues/14125#issuecomment-2258708917

This new config option allows the user to specify a directory where
intermediate build artifacts should be stored.
I have shortened it to just `build-dir` from `target-build-dir`,
although naming is still subject to change.

### What is a final artifact vs an intermediate build artifact

#### Final artifacts
These are the files that end users will typically want to access
directly or indirectly via a third party tool.

* binary executable for bin crates
* binary executable for examples
* `.crate` files output from `cargo package`
* [depinfo
files](https://doc.rust-lang.org/cargo/reference/build-cache.html#dep-info-files)
(`.d` files) for third party build-system integrations (see
https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/fingerprint/mod.rs#L194)
* `cargo doc` output (html/css/js/etc)
* Cargo's
[`--timings`](https://doc.rust-lang.org/cargo/reference/timings.html)
HTML report

#### Intermediate build artifact, caches, and state
These are files that are used internally by Cargo/Rustc during the build
process

* other depinfo files (generated by rustc, fingerprint, etc. See
https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/fingerprint/mod.rs#L164)
* rlibs and debug info from dependencies
* build script `OUT_DIR`
* output from proc macros (previously stored in `target/build`)
* [incremental
build](https://doc.rust-lang.org/rustc/codegen-options/index.html#incremental)
output from rustc
* fingerprint files used by Cargo for rebuild detection
* scratchpad used for `cargo package` verify step
* Cache of rustc invocations (`.rustc_info.json`)
* "pre and non uplifted" binary executables. (ie. bins for `examples`
that contain the hash in the name, bins for `benches`, proc macros,
build scripts)
* `CARGO_TARGET_TMPDIR` files (see rational for this
[here](https://github.com/rust-lang/cargo/issues/14125#issuecomment-2258708917))
*
[future-incompat-report](https://doc.rust-lang.org/cargo/reference/future-incompat-report.html)'s
`.future-incompat-report.json` file

## Feature Gating Strategy

We are following the "Ignore the feature that is used without a gate"
approach as described
[here](https://doc.rust-lang.org/nightly/nightly-rustc/cargo/core/features/index.html).

The rational for this is:
The `build.build-dir` is likely going to be set by by users "globally"
(ie. `$CARGO_HOME/config.toml`) to set a shared build directory to
reduce rebuilding dependencies. For users that multiple cargo versions
having having an error would be disrupted.
The fallback behavior is to revert to the behavior of the current stable
release (building in `$CARGO_TARGET_DIR`)

## Testing Strategy

* We have the existing Cargo testsuite to be sure we do not introduce
regressions.
* I have also run the testsuite locally with the cli flag remove to
verify all tests pass with the default build dir (which falls back to
the target dir)
* For testing thus far, I have been using small hello world project with
a few dependencies like `rand` to verify files are being output to the
correct directory.
* When this PR is closer to merging, I plan to test with some larger
projects with more dependencies, build scripts, ect.
* Other testing recommendations are welcome 🙇

## How should we test and review this PR?

This is probably best reviewed commit by commit. I documented each
commit.
I tied to follow the atomic commits recommendation in the Cargo
contributors guide, but I split out some commits for ease of review.
(Otherwise I think this would have ended up being 1 or 2 large commits
😅)

## Questions

- [x] What is the expected behavior of `cargo clean`?
* At the time of writing it only cleans `target` and does not impact the
build-dir but this is easily changable.
* Answer: See
https://github.com/rust-lang/cargo/pull/15104#issuecomment-2616369862
- [x] When using `cargo package` are was expecting just the `.crate`
file to be in `target` while all other output be stored in
`build.build-dir`? Not sure if we consider things like `Cargo.toml`, `
Cargo.toml.orig`, `.cargo_vcs_info.json` part of the user facing
interface.
* Current consensus is that only `.crate` is considered a final artifact
- [x] Where should `cargo doc` output go? HTML/JS for many crates can be
pretty large. Moving to the build-dir would help reduce duplication if
we find the that acceptable. For `cargo doc --open` this is not a
problem but may be problematic for other use cases?
* Answer:
https://github.com/rust-lang/cargo/pull/15104#issuecomment-2619760470
- [x] Are bins generated from `benches` considered final artifacts?
* Since bins from `examples` are considered final artifacts, it seems
natural that `benches` should also be considered final artifacts.
However, unlike `examples` the `benches` bins are stored in
`target/{profile}/deps` instead of a dedicated directory (like
`target/{profile}/examples`). We could move them into a dedicated
directory (`target/{profile}/benches`) but that mean would also be
changing the structure of the `target` directory which feels out of
scope for this change. If we decide that `benches` are final artifacts,
it would probably be better to consider that changes as part of
https://github.com/rust-lang/cargo/issues/6790
* Answer:
https://github.com/rust-lang/cargo/pull/15104#issuecomment-2636519011
- [ ] [Do we want to include a `CARGO_BUILD_DIR` shortcut env
var?](https://github.com/rust-lang/cargo/pull/15104#discussion_r1943404348)
* The current commit (2af0c918d415b4de03e627459c3594826ae03cfb) has
included the `CARGO_BUILD_DIR` shortcut. This can be removed before
merging if there a good reason to.

## TODO

- Implementation
  - [x] Add support in `cargo clean`
  - [ ] ~~Implement templating for `build.build-dir`~~
* Will implement in a follow up PR [as
suggested](https://github.com/rust-lang/cargo/pull/15104#issuecomment-2636514628)
- [x] Fix issue with `target/examples` still containing "pre-uplifted"
binaries
  - [x] Verify `build-dir` with non-bin crate types
- Prepare for review
  - [x] Clean up/improve docs
  - [x] Review tests and add more as needed
  - [x] Fix tests in CI (Windows is currently failing)
  - [x] Clean up commits
  - [ ] Resolve remaining questions
- [x] Request review
2025-02-25 14:44:24 +00:00
Yihai Lin
3824d8388c refactor: Pull out the filter logic. 2025-02-25 20:06:19 +08:00
Ross Sullivan
5874b6f347
Seperated build directory from target directory
This commits implements the seperation of the intermidate artifact
directory (called "build directory") from the target directory. (see #14125)
2025-02-25 21:05:23 +09:00
Ed Page
e1d61b8080 fix(package): Register workspace member renames in overlay
This was reported at https://github.com/rust-lang/cargo/issues/10948#issuecomment-2674289330

I suspect there is a second bug here because my debugging only showed us
doing this for `val-json` and not `concepts` and only when building `utils`.

For the exact mapping between the publish payload and the index,
see
https://doc.rust-lang.org/cargo/reference/registry-index.html#json-schema,
particularly the note about differences.
2025-02-24 11:27:37 -06:00
Ed Page
ca9bf214d0 refactor(package): Pull out field initialization 2025-02-24 11:27:13 -06:00
utnim2
c3c2ea297f removed is_file check as it was not needed 2025-02-24 22:08:50 +05:30
Ross Sullivan
aab7b90818
Added build.build_dir configuration option
This commit adds a `build_dir` option to the `build` table in
`config.toml` and adds the equivalent field to `Workspace` and `GlobalContext`.
2025-02-24 18:19:50 +09:00
Ross Sullivan
f6f2622395
Derive PartialEq and Eq for Filesystem
This is in preparation for splitting the intermediate build artifacts
from the `target` directory.
2025-02-24 18:19:50 +09:00
Ross Sullivan
1b82e1b0bf
Added build-dir unstable feature flag 2025-02-24 18:19:50 +09:00
utnim2
7f94b33b84 feat: add completions for --manifest-path 2025-02-23 16:13:23 +05:30
Samuel Moelius
44970a825d Fix #15099
Overwrite `$CARGO` when the current exe is detected to be a cargo
binary.

See: https://github.com/rust-lang/cargo/issues/15099#issuecomment-2666737150
2025-02-21 15:33:20 -05:00
Ed Page
19d307170f fix(package): Fix lookups to capitalized workspace member's index entry 2025-02-21 08:25:23 -06:00
Ed Page
f5ec77b18e docs(utils): Clarify expected state of name for make_dep_path
For index entries, the caller must lowercase the name.
2025-02-21 08:25:23 -06:00
Weihang Lo
597e8d717d
docs(ref): Shift focus to resolver v3 (#15213)
### What does this PR try to resolve?

We have the `resolver` field in their as subtle nod to encourage people
to explicitly set it in workspaces. With `resolver = "3"` being out for
a couple releases (at the time this hits stable), it seems appropriate
for us to bump this value.

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

### Additional information
2025-02-21 14:27:22 +00:00
Maurice Wangleng Tan
dbd64ec81f fix: mention "3" as a valid value for "resolver" field in error message 2025-02-21 21:46:22 +08:00
Ed Page
007a620d64 docs(ref): Shift focus to resolver v3
We have the `resolver` field in their as subtle nod to encourage people
to explicitly set it in workspaces.  With `resolver = "3"` being out for
a couple releases (at the time this hits stable), it seems appropriate
for us to bump this value.
2025-02-20 16:45:15 -06:00
Weihang Lo
9244ff6586
docs: update changelog for 1.87.0 2025-02-19 00:03:37 -05:00
Weihang Lo
5cfe7fbed8
docs: update changelog for 1.86.0 2025-02-19 00:02:17 -05:00
Ed Page
524d123332 fix(add): Focus on error, rather than large feature lists
Inspired by #11100 and previous work to collapse feature lists down.
2025-02-18 12:44:13 -06:00