Skip to content

Build the library for a target without std - #287

Merged
soareschen merged 1 commit into
mainfrom
docs/no-std
Nov 7, 2026
Merged

soareschen merged 1 commit into
mainfrom
docs/no-std

Conversation

@soareschen

Copy link
Copy Markdown
Collaborator

Overview

[deepseek-v4.1-flash] The cgp crate now builds for a target without std, and its default features need neither std nor alloc. A no_std test crate builds the library for x86_64-unknown-none with and without alloc, so a leak fails the build.

Motivation

The library could not be used in a no_std environment. cgp-base-types, cgp-runtime, and cgp-base lacked #![no_std], so cargo check -p cgp --target x86_64-unknown-none failed on cgp-base-types with "can't find crate for std". Two defaults also turned alloc on: cgp-extra's default = ["full"], where full enabled cgp-error-extra/alloc, and cgp-error-extra's own default = ["alloc"], which turned the feature on regardless of who asked.

Impact

The three crates carry #![no_std]. cgp-error-extra's default is empty and its alloc feature gates DebugError and DisplayError; cgp-extra's default is empty and forwards alloc; and cgp gained an alloc feature that forwards to it. A no_std user who needs an allocator writes default-features = false, features = ["alloc"].

The error backends keep their requirements: cgp-error-anyhow and cgp-error-std need alloc, and cgp-error-eyre needs std.

cgp-no-std-tests is #![no_std], uses a component, a provider, #[cgp_fn], Symbol!, and a wiring table, and gates an alloc-using provider behind its alloc feature. Building it for x86_64-unknown-none fails if any crate in the tree needs std, and planting a std use in it fails with "cannot find module or crate std".

One finding is left for a follow-up: a #[cgp_fn] with an #[implicit] name: &str argument generates a String field bound, so it needs alloc. The test crate uses a u32 implicit instead.

The `cgp` crate could not be used in a `no_std` environment: `cgp-base-types`,
`cgp-runtime`, and `cgp-base` lacked `#![no_std]`, so a build for a target
without `std` failed on them, and two defaults turned `alloc` on, so even
`default-features = false` pulled it in.

The three crates now carry `#![no_std]`. `cgp-error-extra`'s default is empty
and its `alloc` feature gates the providers that need an allocator;
`cgp-extra`'s default is empty and forwards `alloc`; and `cgp` gained an
`alloc` feature that forwards to it. With default features the crate needs
neither `std` nor `alloc`.

`cgp-no-std-tests` builds the library for `x86_64-unknown-none` with and
without `alloc`, so a `std` or `alloc` leak fails the build.
@soareschen
soareschen marked this pull request as ready for review November 7, 2026 22:20
@soareschen
soareschen merged commit 7bbaf59 into main Nov 7, 2026
3 checks passed
@soareschen
soareschen deleted the docs/no-std branch November 7, 2026 22:21
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