Skip to content

chore(hashes): drop no-std supp for hashes#520

Open
ZocoLini wants to merge 1 commit intov0.42-devfrom
chore/drop-nostd-hashes
Open

chore(hashes): drop no-std supp for hashes#520
ZocoLini wants to merge 1 commit intov0.42-devfrom
chore/drop-nostd-hashes

Conversation

@ZocoLini
Copy link
Collaborator

@ZocoLini ZocoLini commented Mar 12, 2026

Summary by CodeRabbit

  • Refactor

    • Restructured feature flag sets for improved compatibility across different build configurations.
    • Simplified dependency feature handling by updating default feature behavior.
    • Removed conditional compilation guards to streamline build requirements.
  • Tests

    • Updated test compilation gating for broader test coverage across configurations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

The changes systematically refactor feature flags across multiple crates by removing default-features = false constraints on dashcore_hashes dependencies, adjusting default feature sets (hashes crate now defaults to empty instead of std), removing conditional compilation guards for tests and std/alloc-specific code, and eliminating std error trait implementations. This consolidates feature management and reduces platform-specific branching.

Changes

Cohort / File(s) Summary
Feature Flag Restructuring
dash/Cargo.toml, dash/core/Cargo.toml, hashes/Cargo.toml, key-wallet-manager/Cargo.toml, key-wallet/Cargo.toml
Removed default-features = false constraint from dashcore_hashes dependencies across crates. Redefined std/no-std feature sets; hashes crate now defaults to no features instead of std. Removed dashcore_hashes/std from dependent crate feature lists. Removed core2 dependency and added actual-schemars.
Test Compilation Gating Removal
hashes/src/hash160.rs, hashes/src/hmac.rs, hashes/src/ripemd160.rs, hashes/src/sha1.rs, hashes/src/sha256.rs, hashes/src/sha256d.rs, hashes/src/sha256t.rs, hashes/src/sha512.rs, hashes/src/sha512_256.rs
Removed #[cfg(feature = "alloc")] gating from test functions and test modules, allowing tests to compile unconditionally regardless of alloc feature configuration.
Conditional Import and Module Removal
hashes/src/hash_x11.rs, hashes/src/impls.rs, hashes/src/lib.rs
Removed conditional compilation attributes for std, core2, and alloc feature gates on imports. Eliminated feature-specific documentation and module conditionals. Removed no_std crate attribute and conditional extern crate declarations.
Error Trait and IO Impl Removal
hashes/src/error.rs, hashes/src/hex.rs
Removed impl std::error::Error for Error blocks previously guarded by #[cfg(feature = "std")]. Removed impl io::Read for HexIterator<'a> conditional implementation. Made FromHex for Vec<u8> unconditional by removing feature gating.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 No more gates to guard each test so dear,
Default features gone, the paths are clear,
Simplified flags hop through the code,
Lighter burdens on the alloc road,
Simpler builds skip the feature chain! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: removing no-std support from the hashes crate, which is reflected across all modified files including Cargo.toml feature flag changes and removal of conditional compilation attributes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/drop-nostd-hashes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@hashes/Cargo.toml`:
- Around line 15-18: The workspace removed no-std support causing dashcore's
no-std builds to fail because hashes' hex.rs and impls.rs use std::io and
std::error::Error unconditionally; restore a no-std-compatible contract by
either re-introducing a "std" feature in hashes' Cargo.toml (e.g., add a feature
like std = ["alloc/std"] or similar) and gate std-only imports behind
cfg(feature = "std") in hex.rs and impls.rs, or keep the removed no-std surface
but then update dash/Cargo.toml/dash/src/lib.rs to drop the no-std feature; if
you choose to keep no-std support, replace uses of std::io and std::error::Error
with cfg-gated alternatives and use core2 equivalents where dash/src/lib.rs
expects core2 compatibility so no-std builds of dashcore can compile against
hashes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c04f5d5a-3de8-43d4-bfa6-1d80f0a0f5c1

📥 Commits

Reviewing files that changed from the base of the PR and between 33cefc9 and e42aad7.

📒 Files selected for processing (18)
  • dash/Cargo.toml
  • hashes/Cargo.toml
  • hashes/src/error.rs
  • hashes/src/hash160.rs
  • hashes/src/hash_x11.rs
  • hashes/src/hex.rs
  • hashes/src/hmac.rs
  • hashes/src/impls.rs
  • hashes/src/lib.rs
  • hashes/src/ripemd160.rs
  • hashes/src/sha1.rs
  • hashes/src/sha256.rs
  • hashes/src/sha256d.rs
  • hashes/src/sha256t.rs
  • hashes/src/sha512.rs
  • hashes/src/sha512_256.rs
  • key-wallet-manager/Cargo.toml
  • key-wallet/Cargo.toml
💤 Files with no reviewable changes (14)
  • hashes/src/sha256.rs
  • hashes/src/error.rs
  • hashes/src/sha512_256.rs
  • hashes/src/sha256d.rs
  • hashes/src/hmac.rs
  • hashes/src/ripemd160.rs
  • hashes/src/sha512.rs
  • hashes/src/sha256t.rs
  • hashes/src/sha1.rs
  • hashes/src/lib.rs
  • hashes/src/hash160.rs
  • hashes/src/hash_x11.rs
  • hashes/src/hex.rs
  • hashes/src/impls.rs

Comment on lines 15 to 18
[features]
default = ["std"]
std = ["alloc", "internals/std"]
alloc = ["internals/alloc"]
default = []
schemars = ["actual-schemars"]
serde-std = ["serde/std"]
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== hashes feature surface ==\n'
rg -n -C2 '^\[features\]|^default\s*=|^std\s*=|^alloc\s*=' hashes/Cargo.toml

printf '\n== dash no-std surface ==\n'
rg -n -C2 'cfg\(not\(feature = "std"\)\)|core2::io|core2::error|no-std\s*=' dash/Cargo.toml dash/src/lib.rs

printf '\n== std-only APIs still present in hashes ==\n'
rg -n -C2 'use std::io|impl std::error::Error|impl.*io::Write|impl.*io::Read' \
  hashes/src/impls.rs hashes/src/hex.rs

Repository: dashpay/rust-dashcore

Length of output: 4053


Coordinate the no-std removal with downstream feature contracts.

hashes now lacks std/alloc features but uses std::io and std::error::Error unconditionally in hex.rs and impls.rs. Meanwhile, dashcore still exposes a no-std feature (line 44 of dash/Cargo.toml) with no-std code paths in dash/src/lib.rs using core2. This creates a broken contract: no-std builds of dashcore will fail when compiling its hashes dependency.

Either remove the workspace no-std surface or keep hashes no-std compatible (e.g., gate std::io imports with cfg features and use core2 equivalents for no-std paths).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@hashes/Cargo.toml` around lines 15 - 18, The workspace removed no-std support
causing dashcore's no-std builds to fail because hashes' hex.rs and impls.rs use
std::io and std::error::Error unconditionally; restore a no-std-compatible
contract by either re-introducing a "std" feature in hashes' Cargo.toml (e.g.,
add a feature like std = ["alloc/std"] or similar) and gate std-only imports
behind cfg(feature = "std") in hex.rs and impls.rs, or keep the removed no-std
surface but then update dash/Cargo.toml/dash/src/lib.rs to drop the no-std
feature; if you choose to keep no-std support, replace uses of std::io and
std::error::Error with cfg-gated alternatives and use core2 equivalents where
dash/src/lib.rs expects core2 compatibility so no-std builds of dashcore can
compile against hashes.

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.76%. Comparing base (9959201) to head (e42aad7).
⚠️ Report is 2 commits behind head on v0.42-dev.

Additional details and impacted files
@@              Coverage Diff              @@
##           v0.42-dev     #520      +/-   ##
=============================================
- Coverage      66.82%   66.76%   -0.06%     
=============================================
  Files            313      313              
  Lines          64756    64746      -10     
=============================================
- Hits           43272    43230      -42     
- Misses         21484    21516      +32     
Flag Coverage Δ *Carryforward flag
core ?
dash-network 74.92% <ø> (ø) Carriedforward from 9959201
dash-network-ffi 34.74% <ø> (ø) Carriedforward from 9959201
dash-spv 68.28% <ø> (ø) Carriedforward from 9959201
dash-spv-ffi 34.74% <ø> (ø) Carriedforward from 9959201
dashcore 74.92% <ø> (ø) Carriedforward from 9959201
dashcore-private 74.92% <ø> (ø) Carriedforward from 9959201
dashcore-rpc 19.92% <ø> (ø) Carriedforward from 9959201
dashcore-rpc-json 19.92% <ø> (ø) Carriedforward from 9959201
dashcore_hashes 74.92% <ø> (ø) Carriedforward from 9959201
ffi 36.43% <ø> (+1.18%) ⬆️
key-wallet 65.69% <ø> (ø) Carriedforward from 9959201
key-wallet-ffi 34.74% <ø> (ø) Carriedforward from 9959201
key-wallet-manager 65.69% <ø> (ø) Carriedforward from 9959201
rpc 19.92% <ø> (ø)
spv 81.07% <ø> (-0.09%) ⬇️
wallet 65.68% <ø> (-0.01%) ⬇️

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
hashes/src/error.rs 0.00% <ø> (ø)
hashes/src/hash160.rs 100.00% <ø> (ø)
hashes/src/hash_x11.rs 34.78% <ø> (ø)
hashes/src/hex.rs 76.84% <ø> (ø)
hashes/src/hmac.rs 76.68% <ø> (ø)
hashes/src/impls.rs 73.13% <ø> (ø)
hashes/src/lib.rs 81.25% <ø> (ø)
hashes/src/ripemd160.rs 98.89% <ø> (ø)
hashes/src/sha1.rs 95.68% <ø> (ø)
hashes/src/sha256.rs 95.37% <ø> (ø)
... and 4 more

... and 19 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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