diff --git a/sdk/hasher/Cargo.toml b/sdk/hasher/Cargo.toml index 29394ce0d9753a..08bc3754540755 100644 --- a/sdk/hasher/Cargo.toml +++ b/sdk/hasher/Cargo.toml @@ -13,11 +13,17 @@ edition = { workspace = true } targets = ["x86_64-unknown-linux-gnu"] [dependencies] -sha2 = { workspace = true } solana-hash = { workspace = true } +[target.'cfg(not(target_os = "solana"))'.dependencies] +sha2 = { workspace = true } + [target.'cfg(target_os = "solana")'.dependencies] +sha2 = { workspace = true, optional = true } solana-define-syscall = { workspace = true } +[features] +sha2 = ["dep:sha2"] + [dev-dependencies] bs58 = { workspace = true } diff --git a/sdk/hasher/src/lib.rs b/sdk/hasher/src/lib.rs index 91d6911cf43a56..69ef279b82db76 100644 --- a/sdk/hasher/src/lib.rs +++ b/sdk/hasher/src/lib.rs @@ -1,16 +1,17 @@ #![no_std] #[cfg(target_os = "solana")] use solana_define_syscall::define_syscall; -use { - sha2::{Digest, Sha256}, - solana_hash::{Hash, HASH_BYTES}, -}; +#[cfg(any(feature = "sha2", not(target_os = "solana")))] +use sha2::{Digest, Sha256}; +use solana_hash::Hash; +#[cfg(any(feature = "sha2", not(target_os = "solana")))] #[derive(Clone, Default)] pub struct Hasher { hasher: Sha256, } +#[cfg(any(feature = "sha2", not(target_os = "solana")))] impl Hasher { pub fn hash(&mut self, val: &[u8]) { self.hasher.update(val); @@ -21,7 +22,7 @@ impl Hasher { } } pub fn result(self) -> Hash { - let bytes: [u8; HASH_BYTES] = self.hasher.finalize().into(); + let bytes: [u8; solana_hash::HASH_BYTES] = self.hasher.finalize().into(); bytes.into() } } diff --git a/sdk/program/Cargo.toml b/sdk/program/Cargo.toml index ec5e12115feab8..938a59f80c843e 100644 --- a/sdk/program/Cargo.toml +++ b/sdk/program/Cargo.toml @@ -36,7 +36,7 @@ solana-decode-error = { workspace = true } solana-frozen-abi = { workspace = true, optional = true } solana-frozen-abi-macro = { workspace = true, optional = true } solana-hash = { workspace = true, features = ["bytemuck", "serde", "std"] } -solana-hasher = { workspace = true } +solana-hasher = { workspace = true, features = ["sha2"] } solana-msg = { workspace = true } solana-program-memory = { workspace = true } solana-sanitize = { workspace = true }