Skip to content

Define CriticalSection, Mutex and Nr locally; make bare-metal optional - #713

Open
stephencox-inveya wants to merge 1 commit into
rust-embedded:mainfrom
stephencox-inveya:inline-bare-metal-types
Open

stephencox-inveya wants to merge 1 commit into
rust-embedded:mainfrom
stephencox-inveya:inline-bare-metal-types

Conversation

@stephencox-inveya

Copy link
Copy Markdown

Closes #651. Alternative to #656 that stays semver-compatible with 0.7.

Problem

cargo audit flags every cortex-m 0.7 user with RUSTSEC-2026-0110
(bare-metal is deprecated/archived). cortex-m 0.7 only uses three items from
it: interrupt::{CriticalSection, Mutex, Nr}, re-exported. #656 removes them,
which is breaking, so it waits for 0.8. Most of the ecosystem (embassy,
stm32-metapac, nrf-pac, panic-probe) depends on cortex-m 0.7 and cannot move
until 0.8 ships and they all migrate.

Change

  • Copy the three items from bare-metal 0.2.5 into cortex_m::interrupt
    (private compat module, re-exported at the same paths). Same layout, same
    methods, same unsafe impl Sync for Mutex<T> where T: Send, same
    compile-fail lifetime test (enable cache and drop target files #6).
  • bare-metal becomes an optional dependency behind a new, non-default
    bare-metal feature. With it on, the old re-exports come back unchanged.
  • InterruptNumber's blanket impl now covers whichever Nr is exported.

Compatibility

Code that names these items through cortex_m::interrupt::* is unaffected,
and so is everything that calls interrupt::free (the closure token's type is
still cortex_m::interrupt::CriticalSection).

Two cases change unless the user enables the bare-metal feature:

  1. Code that mixes cortex_m::interrupt tokens with bare_metal::Mutex /
    bare_metal::CriticalSection directly.
  2. PACs that implement bare_metal::Nr instead of InterruptNumber
    (svd2rust older than the 0.7-era output).

Both get the old behaviour back with features = ["bare-metal"], so they have
a one-line fix rather than a 0.8 migration. cargo-semver-checks against
v0.7.10 reported "no semver update required" (202 checks pass, host target; the tool cannot build rustdoc for thumbv* targets).

Testing

  • cargo test --all --exclude cortex-m-rt --exclude testsuite --features cortex-m/critical-section-single-core (with and without bare-metal)
  • cargo clippy -D warnings on thumbv6m, thumbv7em, thumbv8m.base, thumbv8m.main, both feature states
    (re-run on Rust 1.100.0: no clippy findings; Cargo 1.100 prints an unused-dependency warning for bitfield on thumbv6m/thumbv7em, which main prints too)
  • Downstream: an embassy-stm32 0.6 / embassy-nrf 0.11 firmware (STM32H573 +
    nRF52833) builds with this patch, and bare-metal leaves its Cargo.lock.
    Every image has the same function count and function sizes, and text+data
    moves by at most 8 bytes (layout only).

This change was prepared with the help of an AI coding assistant (Claude). I reviewed and tested it.

🤖 Generated with Claude Code

bare-metal 0.2 is deprecated (RUSTSEC-2026-0110). Copy the three items
cortex-m re-exports from it into interrupt.rs and move the dependency
behind a new, non-default bare-metal feature that restores the old
re-exports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecation of bare-metal

1 participant