diff --git a/.githooks/pre-push b/.githooks/pre-push index 7250c343f..3bb6cd118 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -4,8 +4,8 @@ cargo fmt --all -- --config format_code_in_doc_comments=true buildargs=( "-p nostr" - "-p nostr --no-default-features" - "-p nostr --no-default-features --features all-nips" + "-p nostr --no-default-features --features alloc" + "-p nostr --no-default-features --features alloc,all-nips" "-p nostr --features blocking" "-p nostr-sdk-net" "-p nostr-sdk" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2c5f0cc4..61bc19067 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,8 +28,8 @@ jobs: build-args: [ -p nostr, - -p nostr --no-default-features, - -p nostr --no-default-features --features all-nips, + -p nostr --no-default-features --features alloc, + -p nostr --no-default-features --features "alloc all-nips", -p nostr --features blocking, -p nostr-sdk, -p nostr-sdk --no-default-features, diff --git a/crates/nostr/Cargo.toml b/crates/nostr/Cargo.toml index 442f9f613..21649cba5 100644 --- a/crates/nostr/Cargo.toml +++ b/crates/nostr/Cargo.toml @@ -18,7 +18,8 @@ rustdoc-args = ["--cfg", "docsrs"] [features] default = ["std", "all-nips"] std = [ - "dep:once_cell", + "dep:once_cell", + "cbc?/std", "base64?/std", "bitcoin/std", "bitcoin/rand-std", @@ -28,6 +29,14 @@ std = [ "serde_json/std", "tracing/std", "url-fork/std", + "alloc", +] +alloc = [ + "cbc?/alloc", + "base64?/alloc", + "bitcoin/no-std", + "serde/alloc", + "serde_json/alloc", ] blocking = ["reqwest?/blocking"] all-nips = ["nip04", "nip05", "nip06", "nip11", "nip46", "nip47"] @@ -42,16 +51,16 @@ nip47 = ["nip04"] [dependencies] aes = { version = "0.8", optional = true } -base64 = { version = "0.21", default-features = false, features = ["alloc"], optional = true } +base64 = { version = "0.21", default-features = false, optional = true } bip39 = { version = "2.0", default-features = false, optional = true } -bitcoin = { version = "0.30", default-features = false, features = ["no-std", "rand", "serde"] } -cbc = { version = "0.1", features = ["alloc"], optional = true } +bitcoin = { version = "0.30", default-features = false, features = ["rand", "serde"] } +cbc = { version = "0.1", optional = true } chacha20 = { version = "0.9", optional = true } nostr-ots = { version = "0.2", optional = true } once_cell = { workspace = true, optional = true } reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls-webpki-roots", "socks"], optional = true } -serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] } -serde_json = { version = "1.0", default-features = false, features = ["alloc"] } +serde = { version = "1.0", default-features = false, features = ["derive"] } +serde_json = { version = "1.0", default-features = false } tracing = { workspace = true } url-fork = { workspace = true, features = ["serde"] } diff --git a/crates/nostr/README.md b/crates/nostr/README.md index 9d29af559..828d6ef44 100644 --- a/crates/nostr/README.md +++ b/crates/nostr/README.md @@ -94,6 +94,7 @@ The following crate feature flags are available: | Feature | Default | Description | | ------------------- | :-----: | ---------------------------------------------------------------------------------------- | | `std` | Yes | Enable `std` library | +| `alloc` | Yes | Enable `alloc` library | | `blocking` | No | Needed to use `NIP-05` and `NIP-11` features in not async/await context | | `all-nips` | Yes | Enable all NIPs | | `nip03` | No | Enable NIP-03: OpenTimestamps Attestations for Events | diff --git a/crates/nostr/examples/embedded/Cargo.toml b/crates/nostr/examples/embedded/Cargo.toml index 821f47ce1..02b4e44ec 100644 --- a/crates/nostr/examples/embedded/Cargo.toml +++ b/crates/nostr/examples/embedded/Cargo.toml @@ -17,7 +17,7 @@ alloc-cortex-m = "0.4.1" cortex-m = "0.6.0" cortex-m-rt = "0.6.10" cortex-m-semihosting = "0.3.3" -nostr = { path = "../../../nostr", default-features = false, features = ["nip06"] } +nostr = { path = "../../../nostr", default-features = false, features = ["alloc", "nip06"] } [profile.release] opt-level = "z" diff --git a/crates/nostr/src/lib.rs b/crates/nostr/src/lib.rs index 236131e4e..b73d3b46a 100644 --- a/crates/nostr/src/lib.rs +++ b/crates/nostr/src/lib.rs @@ -6,12 +6,15 @@ #![warn(missing_docs)] #![warn(rustdoc::bare_urls)] #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(all(not(feature = "std"), feature = "alloc"), feature(error_in_core))] +//#![cfg_attr(all(not(feature = "std"), feature = "alloc"), feature(error_in_core))] #![cfg_attr( feature = "default", doc = include_str!("../README.md") )] +#[cfg(not(any(feature = "std", feature = "alloc")))] +compile_error!("at least one of the `std` or `alloc` features must be enabled"); + #[cfg(feature = "std")] #[macro_use] extern crate std;