Skip to content

Commit

Permalink
make sha2 an optional dep when target_os = "solana", because it's unl…
Browse files Browse the repository at this point in the history
…ikely to be used in that case
  • Loading branch information
kevinheavey committed Aug 9, 2024
1 parent 14d97f5 commit 693ba62
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 7 additions & 1 deletion sdk/hasher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
11 changes: 6 additions & 5 deletions sdk/hasher/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ solana-decode-error = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true, features = ["frozen-abi"] }
solana-frozen-abi-macro = { workspace = true, optional = true, features = ["frozen-abi"] }
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 }
Expand Down

0 comments on commit 693ba62

Please sign in to comment.