19280 Commits

Author SHA1 Message Date
Weihang Lo
562e83a443
test: track caller for .crate file publish verification
This was found during some recent works around `cargo package`.
The purpose of it is showing the caller's line number when panicking.
2024-12-30 09:50:04 -05:00
Weihang Lo
d0342d3fe4
test: relax bad_crate_type to only match error message prefix (#14990)
### What does this PR try to resolve?

This PR relaxes the `bad_crate_type` test to have it only match the
prefix of the unknown crate type error message emitted by rustc.

This is so that the cargo test isn't sensitive to (future) suggestions
for known crate types that rustc may emit to help the user.

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

This test should already be run as part of cargo CI. (This is definitely
run as part of rust-lang/rust CI, lol.)

### Additional information

rust-lang/rust side PR that's trying to add a suffix to the bad crate
type error message to list all valid `--crate-type` values:
https://github.com/rust-lang/rust/pull/134720.

Without relaxing this test, the rust-lang/rust side PR [fails
with](https://github.com/rust-lang/rust/pull/134720#issuecomment-2561993224):

<details>
<summary>rust-lang/rust CI fail message</summary>

(Ignore the missing colon after `unknown crate type`)

```
---- bad_config::bad_crate_type stdout ----
running `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/cargo build -v`
thread 'bad_config::bad_crate_type' panicked at src/tools/cargo/tests/testsuite/bad_config.rs:434:10:

---- expected: tests/testsuite/bad_config.rs:424:27
++++ actual:   stderr
   1    1 | [ERROR] failed to run `rustc` to learn about crate-type bad_type information
   2    2 |
   3    3 | Caused by:
   4    4 |   process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --crate-type bad_type` ([EXIT_STATUS]: 1)
   5    5 |   --- stderr
   6      -   [ERROR] unknown crate type: `bad_type`
Error:      6 +   [ERROR] unknown crate type `bad_type`, expected one of: `bin`, `cdylib`, `dylib`, `lib`, `proc-macro`, `rlib`
   7    7 |
```
</details>

Discussed at
https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/Reblessing.20a.20cargo.20test.
2024-12-29 21:00:28 +00:00
许杰友 Jieyou Xu (Joe)
17aaafd92f tests: relax bad_crate_type to only match error message prefix
So that the cargo test isn't sensitive to suggestions for known crate
types that a rustc PR <https://github.com/rust-lang/rust/pull/134720> is
trying to add.
2024-12-30 04:22:28 +08:00
Weihang Lo
0276088d44
refactor(package): split cargo_package to modules (#14982)
### What does this PR try to resolve?

Do nothing but move code around

* `cargo_package.rs` -> `cargo_package/mod.rs`
* Extract vcs info helpers to `cargo_package/vcs.rs`
* Extract verification helpers to `cargo_package/verify.rs`

Doing so because I realized how big `cargo_package.rs` has grown.
Like, the vcs helpers will continue growing with #14981 and potentially
other optimizations.

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

All tests pass.
2024-12-25 03:29:30 +00:00
Weihang Lo
dac06bfc88
chore: update autolabel 2024-12-24 21:57:47 -05:00
Weihang Lo
5b14e6e5d2
refactor(package): add comments 2024-12-24 21:48:23 -05:00
Weihang Lo
b033b977c6
refactor(package): extract verification code 2024-12-24 21:41:09 -05:00
Weihang Lo
2f5788ae2e
refactor(package): flatten nested functions in vcs check 2024-12-24 21:41:09 -05:00
Weihang Lo
3907e2d8b2
refactor(package): extract vcs check to a separate module 2024-12-24 21:41:09 -05:00
Weihang Lo
b018327fd4
refactor(package): move cargo_package to a mod 2024-12-24 17:47:24 -05:00
Weihang Lo
c86f4b3a1b
fix(package): check dirtiness of path fields in manifest (#14966)
### What does this PR try to resolve?

This adds a special case for `package.{readme,license-file}`
to Git VCS status check.
If they were specified with paths outside the current package root,
but still under git workdir, Cargo checks git status of those files
to determine if they were dirty.

We don't need to take care of other fields with path values because

* `PathSource` only list files under the package root.
  Things like `target.path` works for `cargo build`, but won't be
  included in `.crate` file from `cargo publish`.
* The only exceptions are `package.readme`/`package.license-file`.
  Cargo would copy files over if they are outside package root.

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

While this doesn't fix ever case listed in #14967,
it at least fixes one of them.
2024-12-24 17:49:48 +00:00
Weihang Lo
863e1f40de
fix(package): check dirtiness of path fields in manifest
This adds a special case for `package.{readme,license-file}`
to Git VCS status check.
If they were specified with paths outside the current package root,
but still under git workdir, Cargo checks git status of those files
to determine if they were dirty.

We don't need to take care of other fields with path values because

* `PathSource` only list files under the package root.
  Things like `target.path` works for `cargo build`, but won't be
  included in `.crate` file from `cargo publish`.
* The only exceptions are `package.readme`/`package.license-file`.
  Cargo would copy files over if they are outside package root.
2024-12-24 11:59:21 -05:00
Weihang Lo
a991a7dd98
test(package): show corner cases of vcs dirtiness check
This is a test showing corner cases that dirty files outside
the package being packaging actually made the `.crate` file dirty.
However, `cargo package` and `.cargo_vcs_info.json` didn't capture it.
2024-12-24 11:57:40 -05:00
Ed Page
4945803e53
test: make path arguments more generic and flexible (#14979)
### What does this PR try to resolve?

So we don't need to `p.to_str().unwrap()`
and are able to pass different types for each argument

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

No response.
2024-12-24 16:03:59 +00:00
Weihang Lo
0921264bc5
test: make path arguments more generic and flexible
So we don't need to `p.to_str().unwrap()`
and are able to pass different types for each argument
2024-12-24 10:33:21 -05:00
Weihang Lo
3447b1132f
Moved manifest metadata tracking from fingerprint to dep info (#14973)
<!--
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?

Fixes #14154

~~Added some of the missing package metadata to the fingerprint so that
rebuilds are triggered correctly.~~
~~Also updated the test to prevent a future regression.~~

Moved the manifest metadata tracking to use dep info in favor of
fingerprint so that rebuilds are only triggered if the metadata is
actually used.
2024-12-24 14:10:47 +00:00
Weihang Lo
8721d5218a
fix: assure possibly blocking non-files (like FIFOs) won't be picked up for publishing. (#14977)
Follow-up of #14975, related to
https://github.com/GitoxideLabs/gitoxide/pull/1629.

This would otherwise cause the publish to hang if it tries to read from
a fifo.
2024-12-24 13:53:52 +00:00
ranger-ross
3d7b154d15
Moved manifest metadata tracking from fingerprint to dep info
This change moves the manifest metadata track to dep-info files
with the goal of reduce unneeded rebuilds when metadata is changed as
well fixing issues where builds are not retrigged due to metadata
changes when they should (ie. #14154)
2024-12-24 16:52:51 +09:00
Sebastian Thiel
af92c4445b
Use snapshots instead of matching on parts of the output
Personally I liked that the test was only dependent on what really matters, the lack of presence of a particular filename. Now the test would fail if Cargo one day adds more (generated) files to the package.

Co-authored-by: Weihang Lo <weihanglo@users.noreply.github.com>
2024-12-24 08:03:16 +01:00
Weihang Lo
0c157e0c48
simplify SourceID Hash (#14800)
### What does this PR try to resolve?

Despite being interned `SourceId::Eq` is not a `ptr::eq`. Which in turn
is because `SourceId`s concept of identity is a complete mess. The code
relies on having to IDs that are `Eq` but do not have the same values
for their fields.

As one measure of this `SourceId` has an `impl Hash` which does
something different from `fn full_hash` and `fn stable_hash`. Separately
`SourceIdInner` has a different implementation. Similar levels of
complexity exist for `Eq`. Every one of these `impl`s was added due to a
real bug/issue we've had that needs to stay fixed. Not all of witch are
reproducible enough to have made it into our test suite.

I [have some
ideas](https://github.com/rust-lang/cargo/pull/14665#issuecomment-2412077472)
for how to reorganize the types so that this is easier to reason about
and faster. But given the history and the complexity I want to move
extremely carefully.

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

The test pass, and it's a one line change, but this still needs careful
review.

### Additional information

r? @ehuss I remember you and Alex working very hard to track down most
of these bugs.
2024-12-23 18:36:17 +00:00
Sebastian Thiel
2c3f8d87c4
fix: assure possibly blocking non-files (like FIFOs) won't be picked up for publishing.
This would otherwise cause the publish to hang.
2024-12-23 08:14:42 +01:00
Weihang Lo
cfa27f208f
upgrade gix to the latest release 0.69. (#14975)
The main benefit is that it won't facilitate hangs due to attempts to
read from untrackable directory entries, like names pipes or sockets.

Related to https://github.com/GitoxideLabs/gitoxide/pull/1629

### Tasks

* [x] upgrade
* [x] incorporate updated `gix` [once everything is
fixed](https://github.com/GitoxideLabs/gitoxide/pull/1740).
* [x] assure tests work

### Postponed

It turns out that the new `gix` version doesn't magically fix the FIFO
issue, so the following test still fails.

It's not super-trivial to fix apparently (I tried), so let's do it in a
separate PR.

Here is the patch I have so far in case anyone is interested to fix it
earlier or wants to share insights :).

```patch
commit dfef545eae215f0b9da9f3d4424b52cba7edaec3
Author: Sebastian Thiel <sebastian.thiel@icloud.com>
Date:   Sun Dec 22 19:05:40 2024 +0100

    fix: assure possibly blocking non-files (like FIFOs) won't be picked up for publishing.

    This would otherwise cause the publish to hang.

diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs
index 776590697..c78463a32 100644
--- a/src/cargo/sources/path.rs
+++ b/src/cargo/sources/path.rs
@@ -626,8 +626,11 @@ fn list_files_gix(
         .filter(|res| {
             // Don't include Cargo.lock if it is untracked. Packaging will
             // generate a new one as needed.
+            // Also don't include untrackable directory entries, like FIFOs.
             res.as_ref().map_or(true, |item| {
-                !(item.entry.status == Status::Untracked && item.entry.rela_path == "Cargo.lock")
+                item.entry.disk_kind != Some(gix::dir::entry::Kind::Untrackable)
+                    && !(item.entry.status == Status::Untracked
+                        && item.entry.rela_path == "Cargo.lock")
             })
         })
         .map(|res| res.map(|item| (item.entry.rela_path, item.entry.disk_kind)))
diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs
index 1740de4ac..1c6b3db89 100644
--- a/tests/testsuite/package.rs
+++ b/tests/testsuite/package.rs
@@ -6873,3 +6873,29 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
 "#]])
         .run();
 }
+
+#[cargo_test]
+#[cfg(unix)]
+fn simple_with_fifo() {
+    let p = project()
+        .file(
+            "Cargo.toml",
+            r#"
+                [package]
+                name = "foo"
+                version = "0.1.0"
+                edition = "2015"
+            "#,
+        )
+        .file("src/main.rs", "fn main() {}")
+        .build();
+
+    std::process::Command::new("mkfifo")
+        .current_dir(p.root())
+        .arg(p.root().join("blocks-when-read"))
+        .status()
+        .expect("a FIFO can be created");
+
+    // If this hangs, Cargo tried to package a FIFO and is reading it forever.
+    p.cargo("package").run();
+}
```
2024-12-22 22:23:29 +00:00
Sebastian Thiel
3a18044808
upgrade gix to the latest release 0.69.
The main benefit is that it won't facilitate hangs due to attempts
to read from untrackable directory entries, like names pipes or
sockets.

Related to https://github.com/GitoxideLabs/gitoxide/pull/1629
2024-12-22 19:15:00 +01:00
Jacob Finkelman
9c19032ca7 simplify SourceID Hash 2024-12-20 21:39:20 +00:00
Jacob Finkelman
c8a9119b84 make stable_hash not depend on hash 2024-12-20 21:38:08 +00:00
Weihang Lo
652623b779
fix(package): use relpath to cwd for vcs dirtiness report (#14970)
### What does this PR try to resolve?

Address
https://github.com/rust-lang/cargo/pull/14968#issuecomment-2555901072

> I think the ideal solution is to be relative to the current directory
but that takes more work and this incremental improvement is great!

Sorry I should have noticed your comment earlier.
2024-12-20 15:44:42 +00:00
Ed Page
081d7bac63
Enable triagebot merge conflict notifications (#14972)
This enables merge conflict notifications on GitHub. Homu was providing
this service for us, but it was shut down today. I find these
notifications useful, as they give an opportunity for the author to
proactively rebase and not require a round trip with the reviewer.
2024-12-20 15:12:22 +00:00
Eric Huss
90aaa059a2 Enable triagebot merge conflict notifications 2024-12-20 06:40:29 -08:00
Weihang Lo
d325acea1d
fix(package): use relpath to cwd for vcs dirtiness report
Address https://github.com/rust-lang/cargo/pull/14968#issuecomment-2555901072
2024-12-19 20:22:21 -05:00
Weihang Lo
9e2b373acb
test(package): relative path to cwd for dirtiness report 2024-12-19 20:18:05 -05:00
Ed Page
efaaa0ce33
fixed the error message for a user to open the crate (#14969)
### What does this PR try to resolve?

This PR is resolving an
[issue](https://github.com/rust-lang/cargo/issues/14776#issuecomment-2515017963)
where `cargo doc --open --examples` does not give a clear message when
the examples file is given to it.

I changed the message from `no crates with documentation` in the
[cargo_doc.rs](58b2d609ec/src/cargo/ops/cargo_doc.rs (L62))
and
[doc.rs](58b2d609ec/tests/testsuite/doc.rs (L1504))
to `requested crate documentation is not available to open`. Now it
becomes easy for the user to understand what they're missing.

 Fixes #14776

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

Here is the command through which you can test this change:

`cargo test SNAPSHOTS=overwrite -- doc::open_no_doc_crate`

<!--
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-19 23:17:12 +00:00
Ed Page
71678a4cf4
fix(package): show dirty filepaths relative to git workdir (#14968)
### What does this PR try to resolve?

Dirty file paths in the original message were stripped relative to
package root.
User is not able to know the full path to find dirty files.

This PR makes it relative to git workdir.

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

This was found during #14962
2024-12-19 23:09:08 +00:00
Bilal Khan
871e281cff fixed the error message for a user to open the crate 2024-12-20 03:46:16 +05:00
Weihang Lo
982eb2de3a
fix(package): show dirty filepaths relative to git workdir 2024-12-19 17:34:38 -05:00
Weihang Lo
ecc8e37f40
test(package): track vcs status on workspace member granularity 2024-12-19 17:31:25 -05:00
Weihang Lo
cc3b6cb5c5
fix(package): sort dirty file report
To make error message more deterministic
2024-12-19 15:57:29 -05:00
Ed Page
9c17646f8a
Add the test cfg as a well known cfg before of compiler change (#14963)
### What does this PR try to resolve?

This PR adds the `test` cfg as a well known Cargo cfg as
https://github.com/rust-lang/compiler-team/issues/785 is now in FCP and
before the compiler change.

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

Look at the new argument passed and the test changes.

### Additional information

Detailed motivation at
https://github.com/rust-lang/compiler-team/issues/785, but summary
`test` is a weird well known cfg for `rustc` as it's mostly a convention
and build system like Cargo may to set it conditionally (`lib.test =
false` for Cargo, not done in this PR).

Pre-require to https://github.com/rust-lang/rust/pull/131729.

r? @epage
2024-12-19 20:18:15 +00:00
Urgau
5720eb77db Add the test cfg as a well known cfg before of compiler change 2024-12-19 20:41:23 +01: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