7177 Commits

Author SHA1 Message Date
Ed Page
d29a7cb5d7 fix(run): Say what the multiple executables are 2025-03-11 13:15:54 -05:00
Ed Page
b06e29c72a fix(compile): Specify packages ambiguous targets come from 2025-03-11 13:02:55 -05:00
Ed Page
b20edd4226 fix(compile): Consistently use help prefix in errors 2025-03-11 11:54:00 -05:00
Ed Page
7bf7b2f684 fix(compile): Match rustc style guide for help message casing 2025-03-11 11:51:38 -05:00
Ed Page
fde91dde66 fix(compile): Remove trailing newlines on errors 2025-03-11 11:41:18 -05:00
Ed Page
c2764576ac fix(compile): Be consistent in not using period in error
Whether a period was used was dependent on whether a `help:` block is
present.
That shouldn't make a difference and the rustc dev guide says not to use
periods unless multiple sentences are used.
2025-03-11 11:41:08 -05:00
Eric Huss
2158fe1357 Add context for which workspace failed when resolving cargo vendor 2025-03-11 09:37:02 -07:00
Eric Huss
bf3885e0c6 Add tests for cargo vendor error cases resolving 2025-03-11 09:16:48 -07:00
Ed Page
da833c55be test(run): Show ambiguous package name errors 2025-03-11 11:11:44 -05:00
Ed Page
92a5d5e56a test(run): Move run-focused test with rest 2025-03-11 11:07:39 -05:00
Alexander Sergeev
59b11a78e4 feat: use default value for term.progress 2025-03-09 23:20:11 +03:00
Weihang Lo
21af60a6a8
test: redact host target when comparing CARGO_ENV path
This was found when updating git submodule in rust-lang/rust

```
---- cargo_command::overwrite_cargo_environment_variable stdout ----
running `/projects/rust/build/aarch64-apple-darwin/stage1-tools/aarch64-apple-darwin/release/cargo run`

thread 'cargo_command::overwrite_cargo_environment_variable' panicked at src/tools/cargo/tests/testsuite/cargo_command.rs:636:58:

test failed running `/projects/rust/build/aarch64-apple-darwin/stage1-tools/aarch64-apple-darwin/release/cargo run`
error: expected to find:
/projects/rust/build/aarch64-apple-darwin/stage1-tools/aarch64-apple-darwin/release/cargo

did not find in output:
[COMPILING] foo v1.0.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo`
```
2025-03-07 19:34:41 -05:00
Weihang Lo
f0907fca16
fix(package): report if the lockfile is dirty
Lockfile might not be under the package root, but its entries
may be outdated and get packaged into the `.crate` tarball.
We take a conservative action that if the lockfile is dirty,
then all workspace members are considered dirty.
2025-03-07 08:45:49 -05:00
Weihang Lo
d9908b14f7
test(package): dirty lockfile isn't considered dirty but should 2025-03-06 23:42:49 -05:00
Weihang Lo
1b94e1b27c
fix(package): report if workspace manifest is dirty
Workspace manifest might not be under the package root, but
workspace inheritance may still affect what is packaged into
the `.crate.` tarball. We take a conservative action that if
the workspace manifest is dirty, then all workspace members
are considered dirty.
2025-03-06 23:42:49 -05:00
Weihang Lo
73b3092fd5
feat(tree): Add --depth public behind -Zunstable-options (#15243)
### What does this PR try to resolve?

I was investigating some issues around public dependency lints and
wanted to see the structure of the public dependencies and had the idea
to add this with us having added `--depth workspace`.

See
https://github.com/rust-lang/rust/issues/119428#issuecomment-2686384070
for some example output (comparing `cargo tree` with `cargo tree --depth
public`)

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

### Additional information
2025-03-06 21:52:54 +00:00
Alex Crichton
70dc4d8331 Don't use $CARGO_BUILD_TARGET in cargo metadata
This commit fixes a (five year old!) regression in `cargo metadata`
where if `--filter-platform` isn't explicitly specified it will
accidentally read `$CARGO_BUILD_TARGET` (or `build.target`
configuration) and use that as the default `--filter-platform`. The
reason for this is that the calculation for targets changed in #8167
and while the shared function makes sense for other commands such as
`cargo build` the targets have a different meaning in `cargo metadata`
so a slightly different set of functionality is desired.

This commit fixes the issue by introducing a new constructor for the
list of `CompileKind` variants where the fallback of "if nothing is
specified" is explicitly chosen.
2025-03-06 09:00:00 -08:00
Alex Crichton
2da492b8e5 Add a test showing that cargo metadata differs with CARGO_BUILD_TARGET
This'll change in the next commit.
2025-03-06 09:00:00 -08:00
Alex Crichton
895892e0a8 Strip trailing whitespace in tests/testsuite/metadata.rs 2025-03-06 09:00:00 -08:00
Rustin170506
69f398f647 test: add tests for fixing edition and edition idioms
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-03-06 21:57:36 +08:00
Ed Page
2f35b633d8 fix(registry): Respect --frozen like --offline 2025-03-04 11:03:27 -06:00
Ed Page
e115c3c913 fix(resolver): Consider --frozen, like --offline, in errors 2025-03-04 11:03:27 -06:00
Weihang Lo
615a6f87c3
feat(tree): Color the output (#15242)
### What does this PR try to resolve?

This is an experiment to find ways to make `cargo tree` output easier to
grok. I find too many details are hard to spot because everything looks
the same.

![image](https://github.com/user-attachments/assets/92055027-c7a0-4357-9870-400ba6c2de9c)

The goal is to make it easier to scan the output for relevant details.
So far, this approach seems the most viable. Knowing what type of edges
led to where you are provides useful context for scrolling through large
lists of dependencies.

Fixes #10558

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

I had considered styling normal dependency edges but there isn't a
header to clarify what they mean, so I decided to match the package name
as that is the header. So this didn't buy as much as I had hoped,
especially since dimmed lines aren't obvious with my terminal. Maybe if
we used different unicode graph characters.

Instead of coloring the "this is elided" `(*)`, I had considered using a
unicode character that looks like its pointing from that item up. I only
found one that looked close to that but the origin for the arrow was
bottom aligned, rather than center aligned and it looked off.

Alternatives considered
- Once an edge is marked with dev or build dependencies, all future
edges inherit it
- While this makes it clear what section you are in, so does the outer
most line
- Feature edges are the color of the edges that led to them
  - Unsure of value either way
  - This might get weird with `--invert`
- Style local nodes different than non-local
- With the format string being user customizable, I'm concerned with
styling over or within user styling
- Rainbow packages: For every package in the same namespace
(`.split_once("::").0`) or prefix (`.split_once(['-','_']).0`), assign a
color (maybe only for the top N packages to reduce duplicate colors)
  - Would help a lot with `gix-*` and similar other cases
- If we cap the number of participating packages, would need care to
work with `--depth`

(of course,. these could be mixed)

### Additional information
2025-03-04 18:47:52 +00:00
Weihang Lo
9e18e48f8c
fix(vendor): dont remove non-cached source
cargo-vendor has a workaround that to mitigate rust-lang/cargo#5956,
it removes all cached sources in order to trigger a re-unpack.
It was meant for dealing with registry sources only, but accidentally
applied to directory source kind.

While directory source kind was invented for vendoring,
and vendoring from one vendored directory to the other seems unusual,
Cargo IMO should not delete any real sources.

It does not mean that registry sources are okay to delete,
In long term, we should explore a way that unpacks `.crate` files
directly, without any removal. See
https://github.com/rust-lang/cargo/pull/12509#issuecomment-1732415990
2025-03-03 20:47:44 -05:00
Weihang Lo
48f147cd0f
test: show problematic behavior that delete non-cached sources
Sources like directory sources (which usually are vendored source)
likely contains real sources not cached sources.
Cargo shouldn't delete them.
2025-03-03 20:16:53 -05: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
Ed Page
e293cd6cd2 test(tree): Add more UI tests 2025-02-28 09:45:57 -06:00
Ed Page
e2a991caf3 test(tree): Group all cargo-tree tests 2025-02-28 09:18:07 -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
425858c742
refactor: control byte display precision with std::fmt options 2025-02-28 08:56:28 -05:00
Yihai Lin
fa7712da82 feat: Make no target found hint more clear. 2025-02-28 10:03:59 +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
Ed Page
45da135dba test(package): Show cargo script mistaken identity 2025-02-27 14:46:05 -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
0e73eb55f5 test(tree): Show exiting public/priv behavior 2025-02-26 14:50:31 -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
Weihang Lo
b7002ffd5e
test(package): fail with unpublished cyclic/transitive deps
After dd698ff0483bda065d1f78968e70ee86fb116a72,
`cargo package --no-verify` at least fails in three different cases:

* An unpublished package depending on itself as a dev-dependency (cyclic self-referential dev-dependencies).
  * Can be resolved by removing the `version` field from the affected dev-dependency.
  * `-Zpackage-workspace` doesn't help with it.
* Existing `cargo package` has `--package <pkg>` specifying certain unpublished packages.
  * Can be resolved by specifying all unpublished packages in one `cargo` call.
  * `-Zpackage-workspace` also requires all dependency versions available in the target registry when calling, so doesn't help.
* `cargo package --no-verify` has been used as a kind of “plumbing commands” to create tarballs without considering dependency orders. The use cases include:
  * Preparing tarballs for other package managers.
  * Integrating into custom develop workflows for unpublished/internal crates.
  * Constructing custom/private registries.

This commit shows the former two cases.
2025-02-26 12:45:45 -05: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
Yihai Lin
8b9dc21a24 test(workspace): Add test about workspace 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
Ross Sullivan
1b82e1b0bf
Added build-dir unstable feature flag 2025-02-24 18:19:50 +09:00
Ross Sullivan
4ce639da9f
Added target-dir tests
These ares are in preparation to split target-dir into artifact-dir and build-dir
2025-02-24 18:19:49 +09:00
Samuel Moelius
a6fdc01cea Move test to cargo_command.rs 2025-02-23 17:37:39 -05:00