Skip to content

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Oct 3, 2025

I recently turned -Zbuild-std-features=panic_immediate_abort into -Cpanic=immediate-abort in rust-lang/rust#146317. There was some discussion of the feature on Zulip here: #t-compiler/major changes > Unstably add -Cpanic=immediate-abort compiler-team#909

One of the outcomes of this shipping in nightly is that a few use patterns were broken, see rust-lang/rust#146974 and rust-lang/rust#146317 for examples. I think most of the users commenting on these issues are having trouble with how RUSTFLAGS is propagated through Cargo, and most likely they would have just gotten what they wanted if they could have set a profile option instead. So I'm trying to implement that.

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-documenting-cargo-itself Area: Cargo's documentation A-profiles Area: profiles A-unstable Area: nightly unstable support S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 3, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 3, 2025

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

(unstable, multiple_build_scripts, "", "reference/unstable.html#multiple-build-scripts"),

/// Allows use of panic="immediate-abort".
(unstable, panic_immediate_abort, "", "reference/unstable.html#panic-immediate-abort"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the [profile] table is also supported in Cargo configuration, you might want to add both feature gates:

  • Unstable feature in Cargo.toml manifest
  • Unstable flag in CLI/config.toml

See the first few commits in #12625 for reference


* Tracking Issue: [#16042](https://github.com/rust-lang/cargo/issues/16042)

Allow use of the ImmediateAbort panic strategy in a Cargo profile
Copy link
Member

@weihanglo weihanglo Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we link to rustc book and tracking issue (if any)?


/// The `panic` setting.
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, PartialOrd, Ord, serde::Serialize)]
#[serde(rename_all = "lowercase")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Traced that serialization is used by unit-graph. Before it is too late, i think we should change this to kebab-case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And strip seems wrong as well

#[serde(rename_all = "lowercase")]
pub enum Strip {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[derive(Clone, Eq, PartialOrd, Ord, serde::Serialize)]
pub struct Profile {

Hey we don't even specify anything for the entire struct! Probably worth a separate PR/issue to address it.

ia0 added a commit to google/wasefire that referenced this pull request Oct 3, 2025
We're holding 2 things behind:
- The toolchain because of
rust-lang/rust#146974. We'll wait until
rust-lang/cargo#16041 is fixed to update.
- The WebAssembly spec because non-trivial changes might be needed to
update the interpreter (or at least the test-suite).
Comment on lines +564 to 566
"immediate-abort" => PanicStrategy::ImmediateAbort,
// This should be validated in TomlProfile::validate
_ => panic!("Unexpected panic setting `{}`", panic),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation in there needs to be updated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid I'm lost. What validation? I can't find any validation of the panic setting or a TomlProfile::validate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if let Some(panic) = &root.panic {
if panic != "unwind" && panic != "abort" {
bail!(
"`panic` setting of `{}` is not a valid setting, \
must be `unwind` or `abort`",
panic
);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated comment always 🙇🏾‍♂️

@epage
Copy link
Contributor

epage commented Oct 3, 2025

Generally, we have end-to-end tests for new features (which would have caught #16041 (comment)) and feature gate tests for unstable features.

@rustbot rustbot added the A-manifest Area: Cargo.toml issues label Oct 4, 2025
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you!

Would you mind cleaning the commit history a bit. We usually follow atomic commit pattern and every commit shall pass all tests (not MUST we don't enforce that but encourage).


if let Some(panic) = &root.panic {
if panic != "unwind" && panic != "abort" {
if panic != "unwind" && panic != "abort" && panic != "immediate-abort" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we want to make it a warning or configurable lint in the future. It seems too restrictive. Anyway, it is worth its own separate topic.

@saethlin saethlin force-pushed the panic=immediate-abort branch from efd675c to 50697eb Compare October 4, 2025 02:22
@saethlin
Copy link
Member Author

saethlin commented Oct 4, 2025

I don't think a PR that's this conceptually simple needs multiple commits, but I'll split it up if you prefer.

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't mind for this kind of addition. For bugfix I'll be a bit more nitpicky.

Thanks!

@weihanglo weihanglo enabled auto-merge October 4, 2025 02:27
auto-merge was automatically disabled October 4, 2025 03:34

Head branch was pushed to by a user without write access

@saethlin saethlin force-pushed the panic=immediate-abort branch from 50697eb to 4cb6fe4 Compare October 4, 2025 03:34
@saethlin
Copy link
Member Author

saethlin commented Oct 4, 2025

The test package::reserved_windows_name failed and I don't think it's related to my change. I force-pushed without a diff to re-run CI, just in case the test is flaky. Perhaps it's being broken by a runner update?

@saethlin
Copy link
Member Author

saethlin commented Oct 4, 2025

Oh I see this test has been rather flaky recently. Ouch.

@weihanglo
Copy link
Member

yeah, I should create an issue and temporarily ignore that

@weihanglo weihanglo enabled auto-merge October 4, 2025 03:53
@weihanglo weihanglo added this pull request to the merge queue Oct 4, 2025
Merged via the queue into rust-lang:master with commit 029de48 Oct 4, 2025
44 of 50 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 4, 2025
bors added a commit to rust-lang/rust that referenced this pull request Oct 4, 2025
Update cargo submodule

3 commits in 2394ea6cea8b26d717aa67eb1663a2dbf2d26078..801d9b4981dd07e3aecdca1ab86834c13615737e
2025-10-03 14:13:01 +0000 to 2025-10-04 13:30:15 +0000
- chore: Disabled `reserved_windows_name` test temporaily (rust-lang/cargo#16048)
- Add panic=immediate-abort support to Cargo (rust-lang/cargo#16041)
- Accessing each build script's `OUT_DIR` (rust-lang/cargo#15891)
@rustbot rustbot added this to the 1.92.0 milestone Oct 4, 2025

This can be enabled like so:
```toml
cargo-features = ["immediate-abort"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be

Suggested change
cargo-features = ["immediate-abort"]
cargo-features = ["panic-immediate-abort"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues A-profiles Area: profiles A-unstable Area: nightly unstable support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants