Skip to content

fix(widgets): forward portable-atomic feature to ratatui-widgets - #2822

Merged
joshka merged 7 commits into
ratatui:mainfrom
devtechedge:fix/widgets-portable-atomic-forwarding
Oct 9, 2026
Merged

joshka merged 7 commits into
ratatui:mainfrom
devtechedge:fix/widgets-portable-atomic-forwarding

Conversation

@devtechedge

Copy link
Copy Markdown
Contributor

Carries over #2771, which I closed by mistake.

What

The portable-atomic feature on ratatui now also forwards to ratatui-widgets, so builds for targets without native atomic pointers (for example thumbv6m-none-eabi on the RP2040) work with the documented setup.

Root cause

ratatui's portable-atomic feature only forwarded to ratatui-core. ratatui-widgets still imported alloc::sync::Arc unconditionally in block/shadow.rs, and alloc::sync only exists when the target supports atomic pointers. A cargo check --target thumbv6m-none-eabi against a crate enabling ratatui/portable-atomic fails with:

error[E0432]: unresolved import `alloc::sync`
  --> ratatui-widgets/src/block/shadow.rs:1:12
   |
 1 | use alloc::sync::Arc;
   |            ^^^^ could not find `sync` in `alloc`

The change

  • ratatui-widgets gains a portable-atomic feature backed by an optional portable-atomic-util dependency, mirroring how ratatui-core already integrates portable-atomic through kasuari.
  • block/shadow.rs cfg-selects the Arc import: portable_atomic_util::Arc when the feature is on, alloc::sync::Arc otherwise.
  • portable-atomic's Arc does not implement CoerceUnsized on stable Rust, so with the feature on, Shadow::custom erases the concrete effect type through a Box before converting to Arc<dyn CellEffect>. Without it, the code keeps the plain Arc::new. This keeps the same public API and Clone behavior on both paths.
  • The portable-atomic feature on ratatui now forwards to ratatui-widgets/portable-atomic in addition to ratatui-core/portable-atomic.

Verification

  • A no_std scratch crate depending on this branch with ratatui = { default-features = false, features = ["portable-atomic"] } plus portable-atomic with critical-section (the setup from the book's embedded chapter): cargo check --target thumbv6m-none-eabi fails before this change with the E0432 above and passes after.
  • cargo build --target x86_64-unknown-none -p ratatui-widgets (the repository's no-std CI job) passes.
  • cargo xtask format --check and the clippy gate pass locally, and cargo test --all-features -p ratatui-widgets passes with no new failures. My local environment is Windows, so the unix-only crates (termion backend) could not be compiled locally.

This PR was prepared with AI coding assistance and reviewed line by line.

Fixes #2767

The ratatui portable-atomic feature only forwarded to ratatui-core, but
ratatui-widgets imported alloc::sync::Arc unconditionally, which only
exists on targets that support atomic pointers. Builds for targets like
thumbv6m-none-eabi failed with E0432 even with the feature enabled.

Gate the Arc import in block/shadow.rs behind the portable-atomic
feature, backed by portable-atomic-util::Arc, and forward the feature
from the ratatui facade crate. portable-atomic's Arc does not implement
CoerceUnsized on stable Rust, so Shadow::custom erases the concrete
effect type through a Box.

Fixes #2767
kasuari 0.4.9 requires portable-atomic-util ^0.2.4, so the lower bound
declared by ratatui-widgets must match for the minimal-versions CI job
to resolve.
Only erase the effect type through a Box when the portable-atomic feature is enabled, since portable-atomic's Arc cannot coerce to a trait object on stable Rust. Builds without the feature keep the direct Arc::new and skip the extra allocation.
@devtechedge
devtechedge requested a review from a team as a code owner October 9, 2026 07:18
@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.8%. Comparing base (cdccc2b) to head (abcaaf3).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #2822   +/-   ##
=====================================
  Coverage   92.8%   92.8%           
=====================================
  Files        106     106           
  Lines      21668   21669    +1     
=====================================
+ Hits       20117   20118    +1     
  Misses      1551    1551           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joshka
joshka enabled auto-merge (squash) October 9, 2026 07:38
@joshka
joshka merged commit 91dc40f into ratatui:main Oct 9, 2026
41 checks passed
@devtechedge

Copy link
Copy Markdown
Contributor Author

Thanks Josh, both for the quick review and for nudging me to bring this back.

The feature-flag catch made the default build cleaner too.

@nullstalgia

Copy link
Copy Markdown

Great to see this merged!

Apologies if my earlier frustration caused either of you any distress, not my intent if so.

Thanks to both!

@joshka

joshka commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Apologies if my earlier frustration caused either of you any distress, not my intent if so.

Hey, no problems - I think in general, we're all working out how to work in the new world of AI assisted reality of software development. I'm actually fairly bullish on AI assisted comms being reasonable, but it starts with some respect for the receiver. I think it's worth thinking of problems that are encountered along the way as places where both sides of that tension can learn from each other instead of places where we put up barriers to continued discourse.

That is to say, I will use AI to communicate where it adds value. And I will make mistakes on that from time to time on working out that choice, but I'll also look for ways to correct those mistakes going forward. A hard line "no AI generated text in comms" policy that you're calling for in the issue elsewhere isn't aligned with my viewpoint on this.

@devtechedge

Copy link
Copy Markdown
Contributor Author

No worries at all, and thanks for closing yours in favor of this one.

Appreciate you both.

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.

portable-atomic feature on ratatui does not forward to ratatui-widgets, breaking no_std builds on targets without atomic CAS

3 participants