nostrdb-rs

nostrdb in rust!
git clone git://jb55.com/nostrdb-rs
Log | Files | Refs | Submodules | README | LICENSE

commit c099dc9ed7a7d6889871132ee3d3aa8d5921d05e
parent 6956b9f955463404b8eff3b7abe0cc3092cb5958
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  4 Dec 2025 00:27:59 -0800

build: add libsodium

needed for nip44/giftwrap stuff in nostrdb

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
MCargo.toml | 1+
Mbuild.rs | 23+++++++++++++++++++++++
2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -24,6 +24,7 @@ thiserror = "2.0.7" futures = "0.3.31" tokio = { version = "1", features = ["rt-multi-thread", "macros", "time"] } tracing = "0.1.40" +libsodium-sys-stable = { version = "1.22.5", features = ["optimized", "minimal"] } [dev-dependencies] hex = "0.4.3" diff --git a/build.rs b/build.rs @@ -30,6 +30,10 @@ fn secp256k1_build(base_config: &mut Build) { .file("nostrdb/deps/secp256k1/src/precomputed_ecmult.c") .file("nostrdb/deps/secp256k1/src/secp256k1.c"); + // libsodium + //base_config + //.file("nostrdb/deps/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20.c"); + if env::var("PROFILE").unwrap() == "debug" { base_config.flag("-O1"); } @@ -69,6 +73,10 @@ fn main() { "nostrdb/src/bolt11/bech32.c", "nostrdb/src/block.c", "nostrdb/src/metadata.c", + "nostrdb/src/nip44.c", + "nostrdb/src/base64.c", + "nostrdb/src/hmac_sha256.c", + "nostrdb/src/hkdf_sha256.c", "nostrdb/src/binmoji.c", "nostrdb/deps/flatcc/src/runtime/json_parser.c", "nostrdb/deps/flatcc/src/runtime/verifier.c", @@ -88,6 +96,15 @@ fn main() { //.flag("-Werror") //.flag("-g") + // Provided by libsodium-sys-stable’s build script + let sodium_include = std::env::var("DEP_SODIUM_INCLUDE") + .expect("DEP_SODIUM_INCLUDE not set; is libsodium-sys-stable a dependency?"); + + // Optionally use DEP_SODIUM_LIB as well + let sodium_lib_dir = std::env::var("DEP_SODIUM_LIB").ok(); + + build.include(&sodium_include); + // Link Security framework on macOS if !cfg!(target_os = "windows") { build.files(bolt11_deps()); @@ -118,7 +135,13 @@ fn main() { build.compile("libnostrdb.a"); + // Make sure the linker knows where libsodium lives + if let Some(lib_dir) = sodium_lib_dir { + println!("cargo:rustc-link-search=native={lib_dir}"); + } + println!("cargo:rustc-link-lib=static=nostrdb"); + println!("cargo:rustc-link-lib=static=sodium"); // Re-run the build script if any of the C files or headers change for file in &["nostrdb/src/nostrdb.c", "nostrdb/src/nostrdb.h"] {