feat(no_std): portable-atomic integration for targets with no atomic types (#2076)

Improves compatibility with no-std targets that don't support atomic
types.

We support three different scenarios depending on the target:
1. Terminal applications and other std targets (e.g. espidf):
- `std` enabled, `portable-atomic` disabled
2. Embedded targets with atomic types, bare metal x86, etc.:
- `std` disabled `portable-atomic` disabled
3. Embedded targets without atomic types (e.g. single-core MCUs):
- `std` disabled, `portable-atomic` enabled

Turning on `portable-atomic` together with `std` will fall back to `std`
atomic.
This commit is contained in:
Jagoda Estera Ślązak 2025-09-04 20:14:25 +02:00 committed by GitHub
parent 46e7c6cbbf
commit e89a526aab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 48 additions and 8 deletions

50
Cargo.lock generated
View File

@ -969,6 +969,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "foldhash"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
[[package]]
name = "form_urlencoded"
version = "1.2.1"
@ -1153,7 +1159,18 @@ checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"allocator-api2",
"equivalent",
"foldhash",
"foldhash 0.1.5",
]
[[package]]
name = "hashbrown"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d"
dependencies = [
"allocator-api2",
"equivalent",
"foldhash 0.2.0",
]
[[package]]
@ -1448,7 +1465,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661"
dependencies = [
"equivalent",
"hashbrown",
"hashbrown 0.15.5",
]
[[package]]
@ -1569,11 +1586,13 @@ dependencies = [
[[package]]
name = "kasuari"
version = "0.4.7"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d9e0d6a8bf886abccc1cbcac7d74f9000ae5882aedc4a9042188bbc9cd4487"
checksum = "12a3d6645acdef96d256c1f9fd3be7ecfa60d8457520a50bbd1600b6053f8173"
dependencies = [
"hashbrown",
"hashbrown 0.16.0",
"portable-atomic",
"portable-atomic-util",
"thiserror 2.0.16",
]
@ -1685,7 +1704,7 @@ version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86ea4e65087ff52f3862caff188d489f1fab49a0cb09e01b2e3f1a617b10aaed"
dependencies = [
"hashbrown",
"hashbrown 0.15.5",
]
[[package]]
@ -2212,6 +2231,21 @@ dependencies = [
"ratatui",
]
[[package]]
name = "portable-atomic"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
[[package]]
name = "portable-atomic-util"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"
dependencies = [
"portable-atomic",
]
[[package]]
name = "potential_utf"
version = "0.1.2"
@ -2492,7 +2526,7 @@ dependencies = [
"bitflags 2.9.2",
"compact_str",
"document-features",
"hashbrown",
"hashbrown 0.15.5",
"indoc",
"itertools 0.14.0",
"kasuari",
@ -2570,7 +2604,7 @@ dependencies = [
"color-eyre",
"crossterm 0.29.0",
"document-features",
"hashbrown",
"hashbrown 0.15.5",
"indoc",
"instability",
"itertools 0.14.0",

View File

@ -43,6 +43,9 @@ anstyle = ["dep:anstyle"]
## enables conversions from colors in the [`palette`] crate to [`Color`](crate::style::Color).
palette = ["std", "dep:palette"]
## enables portable-atomic integration for targets that don't support atomic types.
portable-atomic = ["kasuari/portable-atomic"]
## enables the backend code that sets the underline color. Underline color is only supported by
## the Crossterm backend, and is not supported on Windows 7.
underline-color = []

View File

@ -59,6 +59,9 @@ layout-cache = ["std", "ratatui-core/layout-cache"]
## enables conversions from colors in the [`palette`] crate to [`Color`](crate::style::Color).
palette = ["std", "ratatui-core/palette", "dep:palette"]
## enables portable-atomic integration for targets that don't support atomic types.
portable-atomic = ["ratatui-core/portable-atomic"]
## Use terminal scrolling regions to make some operations less prone to
## flickering. (i.e. Terminal::insert_before).
scrolling-regions = [