Skip to content

Commit

Permalink
No_std support for floresta-common
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseSK999 committed Oct 15, 2024
1 parent 1359daa commit 0b5857c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/floresta-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spin = "0.9.8"
core2 = { version = "0.4.0", default-features = false }
hashbrown = { version = "0.14.0", optional = true }
secp256k1 = { version = "*", features = ["alloc"], optional = true }
floresta-common = { path = "../floresta-common", default-features = false }
floresta-common = { path = "../floresta-common", default-features = false, features = ["std"] }

[dev-dependencies]
rand = "0.8.5"
Expand Down
20 changes: 15 additions & 5 deletions crates/floresta-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ readme = "README.md"


[dependencies]
sha2 = "^0.10.6"
bitcoin = "0.31"
miniscript = { version = "11", optional = true }
# Common dependencies
sha2 = { version = "0.10.6", default-features = false }
bitcoin = { version = "0.31", default-features = false, features = ["serde"] }
spin = "0.9.8"

# No-std specific dependencies
hashbrown = { version = "0.14.0", optional = true }
core2 = { version = "0.4.0", default-features = false, optional = true }

# Optional as descriptors feature
miniscript = { version = "11", default-features = false, optional = true }

[features]
default = ["descriptors"]
descriptors = ["miniscript"]
default = ["std", "descriptors"]
std = ["bitcoin/std", "sha2/std"]
no-std = ["bitcoin/no-std", "hashbrown", "core2"]
descriptors = ["miniscript/std"]
descriptors-no-std = ["miniscript/no-std"]
21 changes: 16 additions & 5 deletions crates/floresta-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
// SPDX-License-Identifier: MIT

#![no_std]
// Ensure that both `std` and `no-std` are not enabled simultaneously
#[cfg(all(feature = "std", feature = "no-std"))]
compile_error!("Features `std` and `no-std` cannot be enabled simultaneously.");

// Ensure that one of `std` or `no-std` is enabled
#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("One of the `std` or `no-std` features must be enabled.");

#[cfg(all(feature = "no-std", feature = "descriptors"))]
compile_error!("For `no-std` enable the `descriptors-no-std` feature instead of `descriptors`.");

use bitcoin::hashes::sha256;
use bitcoin::hashes::Hash;
use bitcoin::ScriptBuf;
#[cfg(feature = "descriptors")]
#[cfg(any(feature = "descriptors", feature = "descriptors-no-std"))]
use miniscript::Descriptor;
#[cfg(feature = "descriptors")]
#[cfg(any(feature = "descriptors", feature = "descriptors-no-std"))]
use miniscript::DescriptorPublicKey;
use sha2::Digest;
pub mod spsc;
Expand Down Expand Up @@ -35,7 +46,7 @@ pub mod service_flags {
pub const UTREEXO_FILTER: u64 = 1 << 25;
}

#[cfg(feature = "descriptors")]
#[cfg(any(feature = "descriptors", feature = "descriptors-no-std"))]
pub fn parse_descriptors(
descriptors: &[String],
) -> Result<Vec<Descriptor<DescriptorPublicKey>>, miniscript::Error> {
Expand Down Expand Up @@ -64,7 +75,6 @@ pub mod prelude {
pub use alloc::vec::Vec;
pub use core::cmp;
pub use core::convert;
pub use core::core::str::FromStr;
pub use core::fmt;
pub use core::fmt::Display;
pub use core::iter;
Expand All @@ -76,6 +86,7 @@ pub mod prelude {
pub use core::result;
pub use core::slice;
pub use core::str;
pub use core::str::FromStr;

pub use core2::error::Error;
pub use core2::io::Error as ioError;
Expand All @@ -84,7 +95,7 @@ pub mod prelude {
pub use hashbrown::HashMap;
pub use hashbrown::HashSet;
}
#[cfg(not(feature = "no-std"))]
#[cfg(feature = "std")]
pub mod prelude {
extern crate alloc;
extern crate std;
Expand Down

0 comments on commit 0b5857c

Please sign in to comment.