nostrdb-rs

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

commit 356cbe0fc11ee4dc1f93908dcc1e858c5291e20c
parent 0a3edf49f48c7151b9eedba44d777171ad334a3c
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 17 Aug 2024 11:22:24 -0700

update build.rs to rusty's ccan rework

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

Diffstat:
Mbuild.rs | 34++++++++++++++++++++++------------
Msrc/bindings.rs | 54++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 74 insertions(+), 14 deletions(-)

diff --git a/build.rs b/build.rs @@ -50,19 +50,30 @@ fn main() { build .files([ "nostrdb/src/nostrdb.c", - "nostrdb/src/sha256.c", "nostrdb/src/bolt11/bolt11.c", "nostrdb/src/bolt11/amount.c", "nostrdb/src/bolt11/bech32.c", "nostrdb/src/bolt11/hash_u5.c", - "nostrdb/src/bolt11/list.c", - "nostrdb/src/bolt11/take.c", - "nostrdb/src/bolt11/tal.c", - "nostrdb/src/bolt11/talstr.c", - "nostrdb/src/bolt11/utf8.c", "nostrdb/src/invoice.c", "nostrdb/src/nostr_bech32.c", "nostrdb/src/content_parser.c", + "nostrdb/ccan/ccan/crypto/sha256/sha256.c", + //"nostrdb/ccan/ccan/htable/htable.c", + //"nostrdb/ccan/ccan/htable/tools/density.c", + //"nostrdb/ccan/ccan/htable/tools/hsearchspeed.c", + //"nostrdb/ccan/ccan/htable/tools/speed.c", + //"nostrdb/ccan/ccan/htable/tools/stringspeed.c", + "nostrdb/ccan/ccan/likely/likely.c", + "nostrdb/ccan/ccan/list/list.c", + "nostrdb/ccan/ccan/mem/mem.c", + "nostrdb/ccan/ccan/str/debug.c", + "nostrdb/ccan/ccan/str/str.c", + "nostrdb/ccan/ccan/take/take.c", + //"nostrdb/ccan/ccan/tal/benchmark/samba-allocs.c", + //"nostrdb/ccan/ccan/tal/benchmark/speed.c", + "nostrdb/ccan/ccan/tal/str/str.c", + "nostrdb/ccan/ccan/tal/tal.c", + "nostrdb/ccan/ccan/utf8/utf8.c", "nostrdb/src/block.c", "nostrdb/deps/flatcc/src/runtime/json_parser.c", "nostrdb/deps/flatcc/src/runtime/verifier.c", @@ -75,6 +86,8 @@ fn main() { .include("nostrdb/deps/lmdb") .include("nostrdb/deps/flatcc/include") .include("nostrdb/deps/secp256k1/include") + .include("nostrdb/ccan") + .include("nostrdb/src") // Add other include paths //.flag("-Wall") .flag("-Wno-sign-compare") @@ -94,12 +107,7 @@ fn main() { secp256k1_build(); // Re-run the build script if any of the C files or headers change - for file in &[ - "nostrdb/src/nostrdb.c", - "nostrdb/src/sha256.c", - "nostrdb/src/nostrdb.h", - "nostrdb/src/sha256.h", - ] { + for file in &["nostrdb/src/nostrdb.c", "nostrdb/src/nostrdb.h"] { println!("cargo:rerun-if-changed={}", file); } @@ -124,6 +132,8 @@ fn main() { { let bindings = bindgen::Builder::default() .header("nostrdb/src/nostrdb.h") + .clang_arg("-Inostrdb/ccan") + .clang_arg("-Inostrdb/src") .generate() .expect("Unable to generate bindings"); diff --git a/src/bindings.rs b/src/bindings.rs @@ -3294,9 +3294,50 @@ fn bindgen_test_layout_ndb_iterator() { ); } #[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ndb_filter_string { + pub string: *const ::std::os::raw::c_char, + pub len: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_ndb_filter_string() { + const UNINIT: ::std::mem::MaybeUninit<ndb_filter_string> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<ndb_filter_string>(), + 16usize, + concat!("Size of: ", stringify!(ndb_filter_string)) + ); + assert_eq!( + ::std::mem::align_of::<ndb_filter_string>(), + 8usize, + concat!("Alignment of ", stringify!(ndb_filter_string)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).string) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ndb_filter_string), + "::", + stringify!(string) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ndb_filter_string), + "::", + stringify!(len) + ) + ); +} +#[repr(C)] #[derive(Copy, Clone)] pub union ndb_filter_element { - pub string: *const ::std::os::raw::c_char, + pub string: ndb_filter_string, pub id: *const ::std::os::raw::c_uchar, pub integer: u64, } @@ -3306,7 +3347,7 @@ fn bindgen_test_layout_ndb_filter_element() { let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::<ndb_filter_element>(), - 8usize, + 16usize, concat!("Size of: ", stringify!(ndb_filter_element)) ); assert_eq!( @@ -5077,6 +5118,15 @@ extern "C" { ) -> ::std::os::raw::c_int; } extern "C" { + pub fn ndb_filter_from_json( + arg1: *const ::std::os::raw::c_char, + len: ::std::os::raw::c_int, + filter: *mut ndb_filter, + buf: *mut ::std::os::raw::c_uchar, + bufsize: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { pub fn ndb_filter_get_id_element( arg1: *const ndb_filter, arg2: *const ndb_filter_elements,