-
Notifications
You must be signed in to change notification settings - Fork 157
sha256-hasher: Make it no-std compatible #384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
#### Problem The sha256-hasher doesn't compile in real no-std environments. #### Summary of changes This was an easy fix, simply don't pull in default features for the sha2 crate. This means we disable OIDs for hashes, and the ability to finalize hashes into Box'ed values. Since we don't use that, it should be safe to disable. Also, the crate was a no-op to build without the sha2 feature, so I changed the no-std checking strategy to *exclude* features rather than include certain features, and moved it to `cargo hack` so that each crate and feature is tested individually.
| ./cargo nightly hack check \ | ||
| -Zbuild-std=core \ | ||
| "--target=$target" \ | ||
| --no-default-features \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be building each individual feature with no defaults, so having the --no-default-features argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's included with --each-feature on cargo hack:
+ exec cargo +nightly-2025-06-29 hack check -Zbuild-std=core --target=bpfel-unknown-none --exclude-features=atomic,bincode,default,dev-context-only-utils,frozen-abi,rand,std,verify,alloc,borsh,curve25519,serde --each-feature -p solana-address -p solana-clock -p solana-commitment-config -p solana-define-syscall -p solana-epoch-info -p solana-fee-calculator -p solana-hash -p solana-msg -p solana-program-error -p solana-program-log -p solana-program-log-macro -p solana-program-memory -p solana-rent -p solana-sanitize -p solana-sdk-ids -p solana-sha256-hasher -p solana-signature -p solana-sysvar-id -p solana-system-interface
info: running `cargo check -Zbuild-std=core --target bpfel-unknown-none --no-default-features` on solana-address (1/32)
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then it enables each feature one by one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
Do we need to test the build with just |
febo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Problem
The sha256-hasher doesn't compile in real no-std environments.
Summary of changes
This was an easy fix, simply don't pull in default features for the sha2 crate. This means we disable OIDs for hashes, and the ability to finalize hashes into Box'ed values. Since we don't use that, it should be safe to disable.
Also, the crate was a no-op to build without the sha2 feature, so I changed the no-std checking strategy to exclude features rather than include certain features, and moved it to
cargo hackso that each crate and feature is tested individually.