Skip to content

Conversation

@joncinque
Copy link
Collaborator

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.

#### 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.
@joncinque joncinque requested a review from febo October 16, 2025 23:31
./cargo nightly hack check \
-Zbuild-std=core \
"--target=$target" \
--no-default-features \
Copy link
Contributor

@febo febo Oct 16, 2025

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?

Copy link
Collaborator Author

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)
...

Copy link
Collaborator Author

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect!

@febo
Copy link
Contributor

febo commented Oct 16, 2025

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.

Do we need to test the build with just --no-default-features as well?

Copy link
Contributor

@febo febo left a comment

Choose a reason for hiding this comment

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

Looks great!

@joncinque joncinque merged commit f6025a9 into anza-xyz:master Oct 17, 2025
26 checks passed
@joncinque joncinque deleted the no-std-hasher branch October 17, 2025 00:18
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.

2 participants