Skip to content

feat(core): no_std support for the core module (Phase 1)#86

Open
kalwalt wants to merge 5 commits into
feat/no_stdfrom
feat/no-std-core-phase1
Open

feat(core): no_std support for the core module (Phase 1)#86
kalwalt wants to merge 5 commits into
feat/no_stdfrom
feat/no-std-core-phase1

Conversation

@kalwalt

@kalwalt kalwalt commented Jul 13, 2026

Copy link
Copy Markdown
Member

Makes the core module compile without the Rust standard library, using only core + alloc, so purecv can run on microcontrollers such as the ESP32 (#82).

std is now an explicit opt-in feature (still on by default — no change for existing users). With --no-default-features:

  • lib.rs sets #![cfg_attr(not(feature = "std"), no_std)] with extern crate alloc
  • all std:: paths in src/core moved to core::/alloc::; PureCvError implements core::error::Error (MSRV set to 1.88, which the codebase already required via is_multiple_of)
  • float math (sqrt, sin, …, 243 call sites) resolves through num_traits::Float backed by libm, since those methods don't exist on f32/f64 without std
  • genuinely std-only APIs are gated: get_tick_count/get_tick_frequency (no bare-metal clock) and the thread-local RNG (set_rng_seed, randu, randn, rand_shuffle)
  • the not-yet-converted modules (imgproc, features2d, video, calib3d, features) and the parallel/simd/fft/ndarray features require std until their own phases land

A new build-only crate crates/no-std-smoke consumes the public API from a #![no_std] crate, and a new CI job builds both purecv and the smoke crate for thumbv7em-none-eabihf and lints the no-default-features configuration.

Verified: full test suite passes with default features (358 unit + 35 doc tests), clippy/fmt clean on both configurations, and matrix arithmetic ran end-to-end on real ESP32-S3 hardware (Xtensa, esp toolchain) with output logged over serial.

Alternative considered: splitting a purecv-core sub-crate for isolation — rejected for Phase 1 as the mechanical move would dominate the diff; the single-crate cfg_attr approach keeps the change reviewable.

Closes #83
Refs #82

🤖 Generated with Claude Code

kalwalt and others added 5 commits July 13, 2026 16:39
num-traits switches to libm-backed float math so core compiles without
the standard library; parallel/simd/fft/ndarray require std until their
own no_std phases land (#82). Default features are unchanged.

Refs #83

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- add #![cfg_attr(not(feature = "std"), no_std)] and extern crate alloc
- std-gate the not-yet-converted modules (calib3d, features, features2d,
  imgproc, video) and their prelude re-exports
- switch std:: paths to core::/alloc:: throughout src/core
- PureCvError now implements core::error::Error (MSRV 1.88)
- float methods resolve through num_traits::Float (libm) in no_std builds
- std-gate get_tick_count/get_tick_frequency (no bare-metal clock) and the
  thread-local RNG API; replace a debug eprintln! with log::warn!

Verified on thumbv7em-none-eabihf and ESP32-S3 (Xtensa).

Refs #83

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
crates/no-std-smoke consumes the purecv public API from a #![no_std]
crate; building it for a bare-metal target proves downstream no_std
usability. Excluded from the workspace as its own root.

Refs #83

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Builds and lints with --no-default-features on the host, then builds
purecv and the smoke-test consumer for thumbv7em-none-eabihf.

Refs #83

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
default-features = false previously only dropped rayon; now that std
gates the non-core modules, the wasm wrapper must opt back into it.

Refs #83

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kalwalt kalwalt self-assigned this Jul 13, 2026
@kalwalt kalwalt added enhancement New feature or request rust-code rust Pull requests that update rust code github_actions Pull requests that update GitHub Actions code core-module labels Jul 13, 2026
@kalwalt kalwalt linked an issue Jul 13, 2026 that may be closed by this pull request
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-module enhancement New feature or request github_actions Pull requests that update GitHub Actions code rust Pull requests that update rust code rust-code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[no_std] Phase 1 — make purecv-core compile under no_std + alloc

1 participant