Skip to content

Make the crate no_std, with std as a default feature - #16

Merged
droundy merged 6 commits into
mainfrom
no-std
Oct 18, 2026
Merged

droundy merged 6 commits into
mainfrom
no-std

Conversation

@droundy

@droundy droundy commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Summary

AppendOnlyVec only needs core and alloc; its one use of std was std::thread::yield_now() in the spin-wait. This makes the crate no_std unless the new default std feature is on:

  • std (default): unchanged behaviour, including yielding to the OS after a few failed spins.
  • default-features = false: #![no_std]; the spin-wait always spins (there is no scheduler to yield to).
  • portable-atomic (optional dependency, so an implicit feature): use portable_atomic::AtomicUsize, for targets without compare-and-swap such as thumbv6m-none-eabi. Those targets also need one of portable-atomic's features saying how to provide atomics (e.g. critical-section).

Everything else is std:: → core::/alloc:: paths. Default users see no change.

Why

internment's intern and intern32 features use AppendOnlyVec, and its CI checks them on x86_64-unknown-none and thumbv6m-none-eabi, which fails with "can't find crate for std" in this crate (see droundy/internment#66). After a release, internment can depend on append-only-vec with default-features = false and forward std / portable-atomic.

Test plan

  • cargo test and cargo test --no-default-features --features portable-atomic (stable)
  • cargo check --lib with default, --no-default-features, --features portable-atomic, and both (stable)
  • cargo +1.65.0 check --lib with and without default features (and with portable-atomic)
  • New CI job Check without std: cargo check --no-default-features on x86_64-unknown-none, and on thumbv6m-none-eabi with portable-atomic,portable-atomic/critical-section (I don't have these targets installed locally)

Not included: the version bump and the release.

🤖 Generated with Claude Code

AppendOnlyVec only needs core and alloc.  The one use of std is yielding
to the operating system when a push has spun for a long time; that is
now behind a default `std` feature, and without it the crate is no_std
and always spins.  An optional `portable-atomic` feature uses that
crate's atomics, for targets such as thumbv6m-none-eabi that have no
compare-and-swap.  CI checks both no_std targets.

This lets internment's `intern` feature, which uses AppendOnlyVec,
build without std.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
droundy and others added 2 commits October 18, 2026 13:42
- Define BITS_USED for 16-bit targets, which no_std makes reachable.
- Saturate the spin_wait failure counter, since without std a waiter
  can spin long enough to overflow it on 32-bit targets.
- Document that a no_std push must not preempt another push to the
  same vec (e.g. from an interrupt handler), and that std users who
  disable default features should re-enable std.
- Run the tests in CI with std disabled, with and without
  portable-atomic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Instead of one function that mixes cfg! in its condition, a cfg
attribute on the yield, and a min(3) that only the no_std path needs,
define spin_wait once for each configuration.  Behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
droundy and others added 3 commits October 18, 2026 13:45
Split spin_wait into std and no_std versions
Resolve conflicts with #17 by keeping its allocation-failure and
zero-sized-type handling, using core/alloc paths instead of std.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a job that checks the crate on msp430-none-elf, so the 16-bit
BITS_USED setting is compiled.  It is a tier 3 target, so it needs
nightly and -Zbuild-std.

The MSRV job ran cargo test on Rust 1.56, which builds the
dev-dependencies, and parking_lot_core and libc now need 1.65+, so
that job failed on main too.  Check only the library there instead,
with default, all, and no default features.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@droundy
droundy merged commit 86abb5b into main Oct 18, 2026
24 checks passed
@droundy droundy mentioned this pull request Oct 18, 2026
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.

1 participant