Skip to content

Commit

Permalink
make solana-hash no_std by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinheavey committed Jul 30, 2024
1 parent 1b4e6d4 commit 9d97dd4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions sdk/hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ wasm-bindgen = { workspace = true }
rustc_version = { workspace = true }

[features]
borsh = ["dep:borsh"]
borsh = ["dep:borsh", "std"]
bytemuck = ["dep:bytemuck", "dep:bytemuck_derive"]
frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"]
frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", "std"]
serde = ["dep:serde", "dep:serde_derive"]
std = []
15 changes: 11 additions & 4 deletions sdk/hash/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#![no_std]
#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))]
#[cfg(feature = "borsh")]
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
#[cfg(any(feature = "std", target_arch = "wasm32"))]
extern crate std;
#[cfg(any(feature = "borsh", target_arch = "wasm32"))]
use std::string::ToString;
#[cfg(feature = "bytemuck")]
use bytemuck_derive::{Pod, Zeroable};
#[cfg(feature = "serde")]
use serde_derive::{Deserialize, Serialize};
use {
core::fmt,
core::{convert::TryFrom, fmt, mem, str::FromStr},
solana_sanitize::Sanitize,
std::{convert::TryFrom, error::Error, mem, str::FromStr},
};
#[cfg(target_arch = "wasm32")]
use {
js_sys::{Array, Uint8Array},
std::{boxed::Box, format, string::String, vec},
wasm_bindgen::{prelude::*, JsCast},
};

Expand All @@ -35,9 +40,10 @@ pub const MAX_BASE58_LEN: usize = 44;
#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))]
#[cfg_attr(
feature = "borsh",
derive(BorshSerialize, BorshDeserialize, BorshSchema),
derive(BorshSerialize, BorshDeserialize),
borsh(crate = "borsh")
)]
#[cfg_attr(all(feature = "borsh", feature = "std"), derive(BorshSchema))]
#[cfg_attr(feature = "bytemuck", derive(Pod, Zeroable))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize,))]
#[derive(Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
Expand Down Expand Up @@ -76,7 +82,8 @@ pub enum ParseHashError {
Invalid,
}

impl Error for ParseHashError {}
#[cfg(feature = "std")]
impl std::error::Error for ParseHashError {}

impl fmt::Display for ParseHashError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
1 change: 1 addition & 0 deletions sdk/hasher/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![no_std]
#[cfg(target_os = "solana")]
use solana_define_syscall::define_syscall;
use {
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ solana-atomic-u64 = { workspace = true }
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"] }
solana-hash = { workspace = true, features = ["bytemuck", "serde", "std"] }
solana-hasher = { workspace = true }
solana-program-memory = { workspace = true }
solana-sanitize = { workspace = true }
Expand Down

0 comments on commit 9d97dd4

Please sign in to comment.