19249 Commits

Author SHA1 Message Date
Rustin170506
91da8dba0d fix: better error message for using the script as a dep
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-02-04 22:57:06 +08:00
Rustin170506
1514c7e630 test: add test for script as a dependency
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-01-20 21:53:15 +08:00
Rustin170506
95f6d0b2da feat: use full URL for embedded script paths
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-01-20 21:53:15 +08:00
Rustin170506
d4c1eeeaa0 refactor: use manifest path as the key
Signed-off-by: Rustin170506 <techregister@pm.me>

fix
2025-01-20 21:53:13 +08:00
Rustin170506
0c2bb4e5a8 test: add the dep case
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-01-02 23:17:15 +08:00
Rustin170506
feda97d9f2 test: add the no lock file case
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-01-02 23:17:15 +08:00
Rustin170506
5465e6a451 fix: remove unsupported embedded workspace check from cargo pkgid command
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-01-02 23:17:11 +08:00
Ed Page
59b2ddd448
refactor(cargo-package): let-else to flatten code (#14959)
### What does this PR try to resolve?

Flatten code with let-else for easier reasoning of exit of
`check_repo_state` function.

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

This also adds some more debug logs.
Shouldn't affect any real production behavior.
2024-12-19 14:06:47 +00:00
Ed Page
12965666ff
fix(cargo-package): add more traces (#14960)
### What does this PR try to resolve?

This helps debug <https://github.com/rust-lang/cargo/issues/14955>.

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

While `check_repo_state` is the culprit, let's add some traces for
future.

### Additional information
2024-12-19 14:03:39 +00:00
Weihang Lo
3c75c1532e
refactor(cargo-package): let-else to flatten code
This also adds some more debug logs
2024-12-19 08:37:24 -05:00
Weihang Lo
6d6b6089fc
fix(cargo-package): add more traces 2024-12-18 23:12:43 -05:00
Weihang Lo
252ad98bc9
refactor(cargo-package): rename unclear argument p 2024-12-18 23:12:43 -05:00
Weihang Lo
58b2d609ec
Do not hash absolute sysroot path into stdlib crates metadata. (#14951)
stdlib crates get a SourceId which has an absolute path pointing into
the sysroot. This makes the metadata hash change depending on where
you've installed Rust. This is causing problems because the different
hashes snowball into the optimizer making different decisions which ends
up changing the binary size.

(Some context: at work we're working with embedded devices with little
flash storage so it often happens that a binary builds locally and then
fails to fit in flash in CI, just because CI has installed rustc to a
different path. Improving binary size is *not* a goal of this PR, after
the fix the size will be whatever, but at least it won't change based on
the rustc path anymore)

Overview of the fix:
- For libstd crates, the metadata hash now contains the path relative to
the sysroot, instead of the absolute path.
- The absolute path is still hashed into the fingerprint (not the
metadata) so moving the rustc installation triggers a rebuild. This
ensures stdlib crates are rebuilt when upgrading nightly versions.
- The rustc version is still hashed into the metadata as usual, so
upgrading Rust releases (not nightly versions) does cause a metadata
change.

Repro of the bug:

```
$ git clone https://github.com/embassy-rs/embassy --branch cargo-nondet-repro
$ cd embassy/
$ cd examples/nrf52840
$ RUSTUP_HOME=~/.rustup1 cargo build --release --bin wifi_esp_hosted
....
    Finished `release` profile [optimized + debuginfo] target(s) in 13.33s
$ llvm-size target/thumbv7em-none-eabi/release/wifi_esp_hosted
   text	   data	    bss	    dec	    hex	filename
 114500	     80	  48116	 162696	  27b88	target/thumbv7em-none-eabi/release/wifi_esp_hosted
$ RUSTUP_HOME=~/.rustup2 cargo build --release --bin wifi_esp_hosted
....
    Finished `release` profile [optimized + debuginfo] target(s) in 9.64s
$ llvm-size target/humbv7em-none-eabi/release/wifi_esp_hosted
   text	   data	    bss	    dec	    hex	filename
 114272	     80	  48116	 162468	  27aa4	target/thumbv7em-none-eabi/release/wifi_esp_hosted
```
2024-12-18 16:45:36 +00:00
Weihang Lo
bd1db93c97
docs: add missing argument to Rustup Cargo workaround (#14954)
### What does this PR try to resolve?

Just added the missing argument to execute this command.
2024-12-18 16:43:42 +00:00
Ed Page
72ffd28eb9
fix(cargo-rustc): stabilize higher precedence trailing flags (#14900)
### What does this PR try to resolve?

This was always enabled on nightly since 1.83-nightly (2024-09).
We have no feedback since then, so assume it is a low-impact change.

This stabilization is targeted at 1.85 (2025-02-20)

Fixes #14346

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

Let's do an FCP.
2024-12-18 14:59:09 +00:00
Rustin170506
43e1527e2f docs: add missing argument to Rustup Cargo workaround
Signed-off-by: Rustin170506 <techregister@pm.me>
2024-12-18 22:50:17 +08:00
Weihang Lo
1d74d955a7
fix(cargo-rustc): stabilize higher precedence trailing flags
This was always enabled on nightly since 1.83-nightly (2024-09).
We have no feedback since then, so assume it is a low-impact change.

This stabilization is targeted at 1.85 (2025-02-20)
2024-12-18 09:30:17 -05:00
Dario Nieuwenhuis
a2e63e6799 Do not hash absolute sysroot path into stdlib crates metadata.
stdlib crates get a SourceId which has an absolute path pointing into the sysroot. This
makes the metadata hash change depending on where you've installed Rust. This is causing
problems because the different hashes snowball into the optimizer making different
decisions which ends up changing the binary size.

(Some context: at work we're working with embedded devices with little flash storage
so it often happens that a binary builds locally and then fails to fit in flash in CI,
just because CI has installed rustc to a different path. Improving binary size is
*not* a goal of this PR, after the fix the size will be whatever, but at least it
won't change based on the rustc path anymore)

Overview of the fix:
- For libstd crates, the metadata hash now contains the path relative to the sysroot, instead of the absolute path.
- The absolute path is still hashed into the fingerprint (not the metadata) so moving the rustc installation triggers a rebuild. This ensures stdlib crates are rebuilt when upgrading nightly versions.
- The rustc version is still hashed into the metadata as usual, so upgrading Rust releases (not nightly versions) does cause a metadata change.

Repro of the bug:

```
$ git clone https://github.com/embassy-rs/embassy --branch cargo-nondet-repro
$ cd embassy/
$ cd examples/nrf52840
$ RUSTUP_HOME=~/.rustup1 cargo build --release --bin wifi_esp_hosted
....
    Finished `release` profile [optimized + debuginfo] target(s) in 13.33s
$ llvm-size target/thumbv7em-none-eabi/release/wifi_esp_hosted
   text	   data	    bss	    dec	    hex	filename
 114500	     80	  48116	 162696	  27b88	target/thumbv7em-none-eabi/release/wifi_esp_hosted
$ RUSTUP_HOME=~/.rustup2 cargo build --release --bin wifi_esp_hosted
....
    Finished `release` profile [optimized + debuginfo] target(s) in 9.64s
$ llvm-size target/humbv7em-none-eabi/release/wifi_esp_hosted
   text	   data	    bss	    dec	    hex	filename
 114272	     80	  48116	 162468	  27aa4	target/thumbv7em-none-eabi/release/wifi_esp_hosted
```
2024-12-18 11:50:06 +01:00
Ed Page
99dff6d77d
fix(build-std): make Resolve align to what to build (#14938)
### What does this PR try to resolve?

Blocked on <https://github.com/rust-lang/cargo/pull/14943> (or can just
merge this one).

Fixes #14935

#14935 failed because since 125e873dffc4b68b263c5decd88750ec10fd441e
[`std_resolve`][1] only includes `sysroot` as primary package.
When any custom Cargo feature is provided via `-Zbuild-std-feature`,
the default feature set `panic-unwind` would be gone, so no
`panic_unwind` crate presents in `std_resolve`.

When then calling [`std_resolve.query`][2] with the default set of
crates from [`std_crates`][3], which automatically includes
`panic_unwind` when `std` presents, it'll result in spec not found
because `panic_unwind` was not in `std_resolve` anyway.

[1]:
addcc8ca71/src/cargo/core/compiler/standard_lib.rs (L96)
[2]:
addcc8ca71/src/cargo/core/compiler/standard_lib.rs (L158)
[3]:
addcc8ca71/src/cargo/core/compiler/standard_lib.rs (L156)

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

This patch is kinda a revert of 125e873dffc4b68b263c5decd88750ec10fd441e
in terms of the behavior.

With this, now `std_resolve` is always resolved to the same set of
packages that Cargo will use to generate the unit graph, (technically
the same set of crates + `sysroot`), by sharing the same set of primary
packages via `std_crates` functions.

Note that when multiple `--target`s provided, if std is specified or
there
is one might support std, Cargo will always resolve std dep graph.

To test it manually, run

```
RUSTFLAGS="-C panic=abort" cargo +nightly-2024-12-15 b -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort
```

change to this PR's cargo with the same nightly rustc, it would succeed.

I am a bit reluctant to add an new end-2end build-std test, but I still
did it.
A bit scared when mock-std gets out-of-sync of features in std in
rust-lang/rust.
2024-12-18 00:55:17 +00:00
Ed Page
8682bb4859
test(build-std): Isolate output test to avoid spurious [BLOCKING] messages from concurrent runs (#14943)
### What does this PR try to resolve?

47c2095b1dd580a91e42cb6197b58a318526b8c4 didn't really fix the
flakiness.

Spun off from <https://github.com/rust-lang/cargo/pull/14938>
2a54190c9c789756d2281eefc856704e98c9941e

build-std tests use the users `CARGO_HOME` for downloading registry
dependencies of the standard library.
This reduces disk needs of the tests, speeds up the tests, and reduces
the number of network requests that could fail.

However, this means all of the tests access the same locks for the
package cache. In one test, we assert on the output and a `[BLOCKING]`
message can show up, depending on test execution time from concurrent
test runs.

We are going to hack around this by having the one test that asserts on
test output to use the standard `cargo-test-support` `CARGO_HOME`,
rather than the users `CARGO_HOME`. There will then only be one process
accessing the lock and no `[BLOCKING]` messages.

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

No more assertion errors like this:

```
---- test_proc_macro stdout ----
running `/home/runner/work/cargo/cargo/target/debug/cargo fetch -Zbuild-std -Zpublic-dependency`
running `/home/runner/work/cargo/cargo/target/debug/cargo test --lib -Zbuild-std -Zpublic-dependency`
thread 'test_proc_macro' panicked at tests/build-std/main.rs:394:10:

---- expected: tests/build-std/main.rs:388:27
++++ actual:   stderr
        1 + [BLOCKING] waiting for file lock on package cache
error: test failed, to rerun pass `-p cargo --test build-std`
        2 + [BLOCKING] waiting for file lock on package cache
   1    3 | [COMPILING] foo v0.0.0 ([ROOT]/foo)
   2    4 | [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
   3    5 | [RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH])
```
2024-12-18 00:13:00 +00:00
Weihang Lo
0149bca5cc
fix(build-std): behavior revert of 125e873dffc4b68b
This is kinda a revert of 125e873dffc4b68b263c5decd88750ec10fd441e
in terms of the behavior.

After this, now `std_resolve` is always resolved by the same set of
packages that Cargo will use to generate the unit graph, (technically
the same set of crates + `sysroot`), by sharing the same set of primary
packages via `std_crates` functions.
2024-12-17 19:02:35 -05:00
Weihang Lo
f004691aa4
test(build-std): resolve too less deps
This failed because since 125e873dffc4b68b263c5decd88750ec10fd441e
[`std_resolve`][1] only includes `sysroot` as primary package.
When any custom Cargo feature is provided via `-Zbuild-std-feature`,
the default feature set `panic-unwind` would be gone, so no
`panic_unwind` crate presents in `std_resolve`.

When then calling [`std_resolve.query`][2] with the default set of
crates from [`std_crates`][3], which automatically includes
`panic_unwind` when `std` presents, it'll result in spec not found
because `panic_unwind` was not in `std_resolve` anyway.

[1]: addcc8ca71/src/cargo/core/compiler/standard_lib.rs (L96)
[2]: addcc8ca71/src/cargo/core/compiler/standard_lib.rs (L158)
[3]: addcc8ca71/src/cargo/core/compiler/standard_lib.rs (L156)

See rust-lang/cargo#14935
2024-12-17 19:02:35 -05:00
Weihang Lo
cbdbfe4ecd
refactor(build-std): extract support core only detection
This is a preparation of reuse for subsequent fix.
2024-12-17 19:02:14 -05:00
Weihang Lo
ca59614620
test(build-std): Isolate output test to avoid spurious [BLOCKING] messages from concurrent runs
47c2095b1dd580a91e42cb6197b58a318526b8c4 didn't really fix the flakiness.

build-std tests use the users `CARGO_HOME` for downloading registry
dependencies of the standard library. This reduces disk needs of the
tests, speeds up the tests, and reduces the number of network requests
that could fail.

However, this means all of the tests access the same locks for the
package cache.  In one test, we assert on the output and a `[BLOCKING]`
message can show up, depending on test execution time from concurrent
test runs.

We are going to hack around this by having the one test that asserts
on test output to use the standard `cargo-test-support` `CARGO_HOME`,
rather than the users `CARGO_HOME`. There will then only be one process
accessing the lock and no `[BLOCKING]` messages.
2024-12-17 18:43:17 -05:00
Eric Huss
b9026bf654
docs: fix wrong changelog PR link (#14947) 2024-12-17 18:05:07 +00:00
Weihang Lo
9ca1485f51
docs: fix wrong changelog PR link 2024-12-17 12:35:29 -05:00
Weihang Lo
edb2c1347d
docs(unstable): Correct stabilization version for MSRV-resolver (#14945)
<!--
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.
-->
2024-12-17 15:36:45 +00:00
Ed Page
3d066ac1ea docs(unstable): Fix a typo 2024-12-17 08:46:13 -06:00
Ed Page
a9e442a979 docs(unstable): Correct stabilization version for MSRV-resolver 2024-12-17 08:35:45 -06:00
Weihang Lo
addcc8ca71
Update release information for home 0.5.11 (#14939)
This is in preparation to publish a new release of the home crate (from
the current master branch).
home-0.5.11
2024-12-16 00:19:55 +00:00
Weihang Lo
e5c4dc65c9
Limit release trigger to 0.* tags (#14940)
This changes the release trigger to only run when a tag matching the
pattern `0.*` is created. The intent is to allow us to create tags for
other crates that we may release out-of-band of the normal releases (and
maybe consider creating tags for all crates to make them easier to
find). For example, I would like to create `home-0.5.11` tags (and
earlier versions that were missed due to this trigger).

cc #14538
2024-12-15 23:01:32 +00:00
Eric Huss
f18cbda5ab Limit release trigger to 0.* tags 2024-12-15 14:27:45 -08:00
Eric Huss
20ec18a3ff Update home changelog 2024-12-15 14:22:53 -08:00
Eric Huss
014378f8c0 Clarify status of home_dir
Users should be using the standard library `home_dir` instead of this
crate.
2024-12-15 14:20:56 -08:00
Eric Huss
769f622e12
test(build-std): dont require rustup (#14933)
### What does this PR try to resolve?

It checks rustup existence even when test is skipped for other reasons.

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

See
<https://github.com/rust-lang/rust/pull/134278#issuecomment-2542665291>.

### Additional information
2024-12-14 04:27:35 +00:00
Weihang Lo
80409f7016
test(build-std): dont require rustup
It checks rustup existence even when test is skipped for other reasons
2024-12-13 22:36:09 -05:00
Weihang Lo
7847c03965
fix(base): Support bases in patches in virtual manifests (#14931)
### What does this PR try to resolve?

This bug has been there since #14360

Found this when looking to change the normalization code for cargo
script. As a result, I also changed `cargo-util-schemas` in the hope
that grouping the fields would make the intent clearer. Since I was
already changing field order, I also re-ordered for my personal taste
(user facing features first)

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

### Additional information
2024-12-13 18:06:39 +00:00
Ed Page
5b8b2ac248 fix(base): Support bases in patches in virtual manifests
This bug has been there since #14360
2024-12-13 11:00:57 -06:00
Ed Page
2d23b94a7f test(base): Verify bases in patches in virtual manifests 2024-12-13 11:00:04 -06:00
Ed Page
e83dc0405b test(patch): Speed up path-bases test 2024-12-13 10:55:20 -06:00
Ed Page
cb30ab61d1 refactor(toml): Initialize fields before everything else 2024-12-13 10:50:55 -06:00
Ed Page
aef2f6d1ae test(patch): Ensure the patch actuall gets built 2024-12-13 10:48:31 -06:00
Ed Page
4e5af28150 refactor(schema): Group TomlManifest fields to clarify requires_package
I found a bug in the manifest parser and figured this would help make it
more obvious.

Since I was already changing the order, I figure I'm make things a
little more logical (user-facing first, implementtion details later)
2024-12-13 10:31:53 -06:00
Weihang Lo
876ea2cea8
fix(resolver): Report invalid index entries (#14927)
### What does this PR try to resolve?

While #14897 reported packages with an unsupported index schema version,
that only worked if the changes in the schema version did not cause
errors in deserializing `IndexPackage` or in generating a `Summary`.

This extends that change by recoverying on error with a more lax,
incomplete parse of `IndexPackage` which should always generate a valid
`Summary`.

To help with a buggy Index, we also will report as many as we can.
This does not provide a way to report to users or log on cache reads if
the index entry is not at least `{"name": "<string>", "vers":
"<semver>"}`.

Fixes #10623
Fixes #14894

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

My biggest paranoia is some bad interaction with the index cache
including more "invalid" index entries.
That should be ok as we will ignore the invalid entry in the cache when
loading it.
Ignoring of invalid entries dates back to #6880 when the index cache was
introduced.

### Additional information
2024-12-13 02:29:23 +00:00
Ed Page
63ecc8dbde
feat: Implement --depth workspace for cargo tree command (#14928)
Resolves #14420
2024-12-12 22:48:03 +00:00
Shoyu Vanilla
f7442319e7 feat(tree): implement filtering logic for --depth workspace flag 2024-12-13 05:58:31 +09:00
Shoyu Vanilla
65931bcbf6 refactor(tree): change signatures of tree printing functions to receive &Workspace 2024-12-13 05:56:20 +09:00
Shoyu Vanilla
b729060b14 feat(workspace): new function is_member_id to check whether given package_id belongs to ws 2024-12-13 05:51:17 +09:00
Shoyu Vanilla
fc00223fca refactor(tree): replace previous depth: u32 opts with new type DisplayDepth
refactor(tree): replace previous `depth: u32` opts with new type `DisplayDepth`
2024-12-13 05:51:13 +09:00
Shoyu Vanilla
1c0f6cfdcc test(tree): new incomplete test for cargo tree --depth workspace 2024-12-13 04:50:54 +09:00