Build-std: panic strategies - #17185
Conversation
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @ehuss (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
|
@rustbot author (I have to fix CI) |
|
Reminder, once the PR becomes ready for a review, use |
I think it probably is... The RFC also describes what happens when panic isn't set in the profile, which I don't think is possible. |
4f5fb5a to
6020f3d
Compare
This comment has been minimized.
This comment has been minimized.
6020f3d to
6204c2b
Compare
| crates.insert("alloc"); | ||
| crates.insert("proc_macro"); | ||
| crates.insert("panic_unwind"); | ||
| crates.insert("panic_abort"); |
There was a problem hiding this comment.
This should be built by default. The reason the strategies are roots is that rustc won't pick them up unless they're passed in via --extern. We have a section in the build-std=always RFC for this, but it's not next to the other section on panic strategies (sorry!)
rustc loads panic runtimes in a different way to most dependencies, and without looking in the sysroot they will fail to load correctly unless passed in with --extern. rustc will need to be patched to be able to load panic runtimes from -L dependency= paths in line with other transitive dependencies.
This doesn't need to block this PR though as the change to this patch to support that will be quite small, and this function will change a lot in the future anyway when the UI changes.
There was a problem hiding this comment.
rust-lang/rust#160007 has landed, so this is now fixed
| // overridden. See `validate_profile_override`. | ||
| let profile = profiles.base_profile(); | ||
| if profile.panic == PanicStrategy::Unwind { | ||
| crates.insert("panic_unwind"); |
There was a problem hiding this comment.
Should be enabled via a feature on sysroot eventually once the rustc loading behaviour has been changed. Again, this doesn't need to block this PR.
There was a problem hiding this comment.
rust-lang/rust#160007 has landed, so this is now fixed
| let (specs, build_panic_unwind) = { | ||
| // If there is anything looks like needing std, resolve with it. | ||
| // If not, we assume only `core` maye be needed, as `core the most fundamental crate. | ||
| // If not, we assume only `core` may be needed, as `core` the most fundamental crate. |
There was a problem hiding this comment.
nit: "as core is the most fundamental crate"
c45cd72 to
c603013
Compare
|
@rustbot ready (CI is green and Adam sees his concerns as non-blocking) |
| let profile = profiles.base_profile(); | ||
| if profile.panic == PanicStrategy::Unwind { | ||
| crates.insert("panic_unwind"); | ||
| } |
There was a problem hiding this comment.
This doesn't seem to handle the situation for cargo test which forces the unwind strategy to be "unwind" even when the strategy is "abort". Thus, when running cargo test, it will end up with the same duplicate lang item problem since it tries to load the wrong unwind.
There's also some complexities when running host tests (proc-macro tests), which I think are also AlwaysUnwind.
I'm a little concerned that trying to deal with these complexities will make this optimization difficult to support. For abort-only targets, the unwind crate should be empty and essentially have no cost.
There was a problem hiding this comment.
Does this test exercise that case? https://github.com/rust-lang/cargo/pull/17185/changes#diff-736f9dbd0f15c0f86f99fa4c395a7639c384213e0d5fe33aadab3f411d53de92R1050
There was a problem hiding this comment.
it turned out that the test is incorrect due to:
Today I plan to open a PR in rustc to address #17185 (comment) (load panic runtime with -L dependency) and then I'll come back to this concern.
| // those included because we'll never use them anyway. | ||
| std_ws.set_require_optional_deps(false); | ||
| let specs = { | ||
| let profiles = Profiles::new(ws, build_config.requested_profile)?; |
There was a problem hiding this comment.
Just a minor nit, but I worry that this function has the possibility to be expensive to call. Would it be possible to pass it in?
There was a problem hiding this comment.
Done, but this requires moving profile creation before std resolution. Not sure if this is desirable as it might slow down error paths. If necessary I can undo the change.
This comment has been minimized.
This comment has been minimized.
|
@rustbot author (need to fix #17185 (comment) and #17185 (comment) first) |
|
Blocked on rust-lang/rust#160007. |
c603013 to
f4371d0
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
View all comments
What does this PR try to resolve?
Implementation for rust-lang/wg-cargo-std-aware#29
Tracking issue: rust-lang/rust#155363
fixes #7359 (Technically fixed by rust-lang/rust#160007)
fixes #17404
How to test and review this PR?
Commit 1: add
panic_abortto mock std and make the panic configuration closer to real std.Commit 2: add multiple tests.
Commit 3: add test for #17404
Commit 4: remove
panic_unwindfrom roots. With rust-lang/rust#160007 panic runtimes can be loaded like regular transitive dependencies.Commit 5: implementation for rules described in https://rust-lang.github.io/rfcs/3874-build-std-always.html#panic-strategies. In short, with this change
panic_unwindis no longer built when theabortorimmediate-abortprofiles are used. (previouslypanic_unwindwas always built).Future steps:
panic-unwindis currently a default feature(it's not in mock-std):https://github.com/rust-lang/rust/blob/36714a9983d6ba11203d8bb87a1b372247fbcf06/library/sysroot/Cargo.toml#L23
This should be removed to enable this change.
Additional information
Proposal says:
but I found that in cargo
-Cpanic=unwindis not passed with "unwind" profile:cargo/src/cargo/core/compiler/mod.rs
Lines 1344 to 1346 in 28fa7f2
Because rustc in that case uses default which is based on target:
https://github.com/rust-lang/rust/blob/36714a9983d6ba11203d8bb87a1b372247fbcf06/compiler/rustc_session/src/session.rs#L700-L704
Is this a mistake in the RFC, or did I misunderstand something? I have not changed this behavior at the moment for build-std.
cc @adamgemmell