Skip to content

cmake/tools: Fix panic_immediate_abort deprecation in Rust build#3421

Merged
acassis merged 2 commits intoapache:masterfrom
no1wudi:rust
Mar 10, 2026
Merged

cmake/tools: Fix panic_immediate_abort deprecation in Rust build#3421
acassis merged 2 commits intoapache:masterfrom
no1wudi:rust

Conversation

@no1wudi
Copy link
Contributor

@no1wudi no1wudi commented Mar 10, 2026

Summary

Fix the panic_immediate_abort compile error in Rust build system by replacing the deprecated -Zbuild-std-features=panic_immediate_abort flag with the new -Cpanic=immediate-abort compiler flag.

Recent Rust nightly versions have stabilized panic_immediate_abort as a real panic strategy. The old method of enabling it via -Zbuild-std-features=panic_immediate_abort is no longer supported and triggers a compile error in core/src/panicking.rs:

error: panic_immediate_abort is now a real panic strategy!
Enable it with `panic = "immediate-abort"` in Cargo.toml,
or with the compiler flags `-Zunstable-options -Cpanic=immediate-abort`.

This change updates both CMake and Makefile build systems to use the new approach via RUSTFLAGS environment variable.

Impact

  • Impact on user: NO - No user-facing changes, only fixes build with newer Rust toolchains
  • Impact on build: YES - Fixes Rust build with recent nightly compilers
  • Impact on hardware: NO
  • Impact on documentation: NO
  • Impact on security: NO
  • Impact on compatibility: YES - Maintains compatibility with both old and new Rust versions by using the officially supported flag

Testing

Build Host: Ubuntu 22.04, x86_64, Rust nightly 2025-03-01
Target: ARM stm32f746g-disco:nsh

Verified the fix by:

  1. Enabling Rust hello example with cargo (CONFIG_EXAMPLES_HELLO_RUST_CARGO=y)
  2. Enabling release mode (CONFIG_DEBUG_FULLOPT=y)
  3. Enabling TLS support (CONFIG_TLS_NELEM=4) required for Rust std library
  4. Building successfully without the panic_immediate_abort error

Build output:

[1123/1127] Building Rust crate hello
   Compiling hello v0.1.0
    Finished `release` profile [optimized] target(s) in 11.34s
[1124/1127] Linking CXX executable nuttx
Memory region         Used Size  Region Size  %age Used
           flash:      126020 B         1 MB     12.02%
           sram1:        5896 B       240 KB      2.40%
[1127/1127] Generating System.map

The firmware builds successfully and links the Rust static library without errors.

Replace deprecated -Zbuild-std-features=panic_immediate_abort with
-Cpanic=immediate-abort compiler flag via RUSTFLAGS.

The panic_immediate_abort feature has been stabilized as a real panic
strategy in recent Rust nightly versions. The old method of enabling
it via -Zbuild-std-features is no longer supported and triggers a
compile error in core/src/panicking.rs.

Changes:
* cmake/nuttx_add_rust.cmake: Use RUSTFLAGS with -Cpanic=immediate-abort
* tools/Rust.mk: Use RUSTFLAGS with -Cpanic=immediate-abort

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
ARCHTYPE is a valid abbreviation for 'architecture type' used
consistently across the codebase. This matches the nuttx repo's
.codespellrc configuration.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

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

Thank you @no1wudi :-)

@acassis acassis merged commit 68f9e54 into apache:master Mar 10, 2026
62 of 77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants