Skip to content

feat: enable no_std compilation and check it in CI#93

Open
JoseSK999 wants to merge 3 commits intomit-dci:mainfrom
JoseSK999:feat-enable-no-std
Open

feat: enable no_std compilation and check it in CI#93
JoseSK999 wants to merge 3 commits intomit-dci:mainfrom
JoseSK999:feat-enable-no-std

Conversation

@JoseSK999
Copy link

@JoseSK999 JoseSK999 commented Feb 5, 2026

Description

This PR adds two new dependencies that are needed for no_std support: hashbrown (HashMap alternative) and bitcoin_io (io trait and type replacements).

The AccumulatorHash trait bounds depend on whether we use std or no_std now.

Note

This seems to work but perhaps we should add a feature powerset CI check to ensure all 4 combinations work fine for clippy and testing.

The prelude list is from floresta-common, I think I can trim a couple of these imports.

bitcoin_hashes = { version = "0.19", default-features = false }
hex-conservative = { version = "1.0.0", default-features = false }
serde = { version = "1.0", features = ["derive"], optional = true }
hashbrown = "0.16.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure: you can't disable a dependency if a feature is on, right? You can only enable them. Because now we have at least one non rust-bitcoin dependency that's not feature-gated. I guess it's ok, since hashbrown is super small and is the basis for std's hashmap implementation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sort of ugly. Otherwise we would have to create a no-std or hashbrown feature required for no-std.

But as you say, std::collections::HashMap is wrapping the hashbrown one: https://doc.rust-lang.org/src/std/collections/hash/map.rs.html

@JoseSK999
Copy link
Author

Pushed 21ae740

  • Cleanup the prelude mod, now it's mostly exporting alloc items to mirror the std prelude, io and HashMap/HashSet
  • Imported some items

And very important:

  • Test and check rustreexo without the std feature (this catched doctest issues and a panic in tests)

@luisschwab
Copy link
Contributor

luisschwab commented Feb 5, 2026

@JoseSK999 you could also add a test-no-std recipe to the justfile and have CI run the recipe, so we can avoid duplication and have the justfile as the single source of truth for testing.

@JoseSK999
Copy link
Author

@JoseSK999 you could also add a test-no-std recipe to the justfile and have CI run the recipe, so we can avoid duplication and have the justfile as the single source of truth for testing.

I had extended the just test recipe to test no default features (i.e., no-std), I think better than a separate just test-no-std. But CI is not using just test. Should I make the recipe be

test:
    cargo +nightly test --no-default-features
    cargo +nightly test --all-features
    cargo +stable test --no-default-features
    cargo +stable test --all-features

and use it in CI? (not sure)

@luisschwab
Copy link
Contributor

Oh, I thought I had changed CI to use the justfile's recipes. I think that is a better approach (I do it on my own repos). Thoughts @Davidson-Souza

@JoseSK999
Copy link
Author

CI here uses just check and just test-msrv, but not just test

@luisschwab
Copy link
Contributor

I guess that just test and just test-msrv should be extended to check for no-std and have CI use those instead.

@JoseSK999
Copy link
Author

JoseSK999 commented Feb 6, 2026

So I have made just test delegate to just test-stable and just test-nightly. In CI we now call these two 👺

just test-{stable/nightly/msrv} and just check are all now running with --no-default-features too

//! Nodes are kept in memory, and they hold their hashes, a reference to their **aunt** (not
//! parent!), and their nieces (not children!). We do this to allow for proof generation, while
//! prunning as much as possible. In a merkle proof, we only need the sibling of the path to the
//! root, the parent is always computed on the fly as we walk up the tree. Some there's no need to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! root, the parent is always computed on the fly as we walk up the tree. Some there's no need to
//! root, the parent is always computed on the fly as we walk up the tree. So, there's no need to

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

This commit adds two new dependencies that are needed for `no_std` support: `hashbrown` (`HashMap` alternative) and `bitcoin_io` (`io` trait and type replacements).

The `AccumulatorHash` trait bounds depend on whether we use `std` or `no_std` now.
This ensures skipping the `std` feature works as expected even though some traits and types are from `hashbrown` and `bitcoin_io`. Also runs doctests and clippy.

Created `test-stable` and `test-nightly` recipes for use in CI.
Copy link
Collaborator

@Davidson-Souza Davidson-Souza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 4bd5934

extern crate alloc;

#[cfg(not(feature = "std"))]
/// Re-exports `alloc`/`std` basics plus HashMap/HashSet and IO traits.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Re-exports `alloc`/`std` basics plus HashMap/HashSet and IO traits.
/// Re-exports `alloc` basics plus HashMap/HashSet and IO traits.

Comment on lines 43 to 54
@@ -33,7 +48,7 @@ test-msrv:
cargo update -p serde_json --precise 1.0.81
cargo update -p serde --precise 1.0.160
cargo update -p half --precise 2.4.1


cargo +1.74.0 test --no-default-features
cargo +1.74.0 test --all-features
rm Cargo.lock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could add a ci/pin-msrv.sh script to pin dependencies and have the justfile and CI run it so we have a single source of truth (see https://github.com/bitcoindevkit/bdk/blob/master/ci/pin-msrv.sh and https://github.com/bitcoindevkit/bdk/blob/master/.github/workflows/cont_integration.yml#L45-L47)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoseSK999 you could also add a section to the README about building with MSRV:

Minimum Supported Rust Version

This library should compile with any combination of features with Rust 1.74.0.

To build with the MSRV you will need to pin dependencies:

bash ci/pin-msrv.sh

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.

3 participants