Skip to content

Commit

Permalink
nostr: add alloc feature
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Sep 6, 2023
1 parent 6edce14 commit c93ebe0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 15 additions & 6 deletions crates/nostr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"]
Expand All @@ -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"] }

Expand Down
1 change: 1 addition & 0 deletions crates/nostr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion crates/nostr/examples/embedded/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion crates/nostr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c93ebe0

Please sign in to comment.