]> git.bitcoin.ninja Git - rust-lightning/commitdiff
[bindings] Use global context for secp256k1
authorMatt Corallo <git@bluematt.me>
Mon, 1 Feb 2021 05:09:50 +0000 (00:09 -0500)
committerMatt Corallo <git@bluematt.me>
Thu, 11 Feb 2021 21:19:56 +0000 (16:19 -0500)
XXX: Note -lm for debug builds (unnecessary with -flto) and rand
dep we probably need to remove upstream for wasm builds

c-bindings-gen/src/types.rs
genbindings.sh
lightning-c-bindings/Cargo.toml

index 2b195e2dcb957d630bf4478e3204fc5d76a895c5..60ee11120009f40038d34723f0aba902aee5e221 100644 (file)
@@ -583,7 +583,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
        /// Returns true we if can just skip passing this to C entirely
        fn no_arg_path_to_rust(&self, full_path: &str) -> &str {
                if full_path == "bitcoin::secp256k1::Secp256k1" {
-                       "&bitcoin::secp256k1::Secp256k1::new()"
+                       "secp256k1::SECP256K1"
                } else { unimplemented!(); }
        }
 
index 1ca2f6e8e886d1463d24bc9da55ae487ab04fde3..db870ff0d78393dda34286e9f997b94f6098fb30 100755 (executable)
@@ -53,11 +53,11 @@ fi
 CFLAGS="-Wall -Wno-nullability-completeness -pthread"
 
 # Naively run the C demo app:
-gcc $CFLAGS -Wall -g -pthread demo.c target/debug/libldk.a -ldl
+gcc $CFLAGS -Wall -g -pthread demo.c target/debug/libldk.a -ldl -lm
 ./a.out
 
 # And run the C++ demo app in valgrind to test memory model correctness and lack of leaks.
-g++ $CFLAGS -std=c++11 -Wall -g -pthread demo.cpp -Ltarget/debug/ -lldk -ldl
+g++ $CFLAGS -std=c++11 -Wall -g -pthread demo.cpp -Ltarget/debug/ -lldk -ldl -lm
 if [ -x "`which valgrind`" ]; then
        LD_LIBRARY_PATH=target/debug/ valgrind --error-exitcode=4 --memcheck:leak-check=full --show-leak-kinds=all ./a.out
        echo
@@ -67,7 +67,7 @@ fi
 
 # Test a statically-linked C++ version, tracking the resulting binary size and runtime
 # across debug, LTO, and cross-language LTO builds (using the same compiler each time).
-clang++ $CFLAGS -std=c++11 demo.cpp target/debug/libldk.a -ldl
+clang++ $CFLAGS -std=c++11 demo.cpp target/debug/libldk.a -ldl -lm
 strip ./a.out
 echo " C++ Bin size and runtime w/o optimization:"
 ls -lha a.out
@@ -88,11 +88,11 @@ if [ "$HOST_PLATFORM" = "host: x86_64-unknown-linux-gnu" ]; then
                        set +e
 
                        # First the C demo app...
-                       clang-$LLVM_V $CFLAGS -fsanitize=memory -fsanitize-memory-track-origins -g demo.c target/debug/libldk.a -ldl
+                       clang-$LLVM_V $CFLAGS -fsanitize=memory -fsanitize-memory-track-origins -g demo.c target/debug/libldk.a -ldl -lm
                        ./a.out
 
                        # ...then the C++ demo app
-                       clang++-$LLVM_V $CFLAGS -std=c++11 -fsanitize=memory -fsanitize-memory-track-origins -g demo.cpp target/debug/libldk.a -ldl
+                       clang++-$LLVM_V $CFLAGS -std=c++11 -fsanitize=memory -fsanitize-memory-track-origins -g demo.cpp target/debug/libldk.a -ldl -lm
                        ./a.out >/dev/null
 
                        # restore exit-on-failure
@@ -158,11 +158,11 @@ if [ "$HOST_PLATFORM" = "host: x86_64-unknown-linux-gnu" -o "$HOST_PLATFORM" = "
                mv Cargo.toml.bk Cargo.toml
 
                # First the C demo app...
-               $CLANG $CFLAGS -fsanitize=address -g demo.c target/debug/libldk.a -ldl
+               $CLANG $CFLAGS -fsanitize=address -g demo.c target/debug/libldk.a -ldl -lm
                ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' ./a.out
 
                # ...then the C++ demo app
-               $CLANGPP $CFLAGS -std=c++11 -fsanitize=address -g demo.cpp target/debug/libldk.a -ldl
+               $CLANGPP $CFLAGS -std=c++11 -fsanitize=address -g demo.cpp target/debug/libldk.a -ldl -lm
                ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' ./a.out >/dev/null
        else
                echo "WARNING: Please install clang-$RUSTC_LLVM_V and clang++-$RUSTC_LLVM_V to build with address sanitizer"
index 6bde30475f93382ffe58d0f0df3eaf63a580d57f..19e8031c24fa0514d99afdeccb786a59f1b68e95 100644 (file)
@@ -16,6 +16,7 @@ crate-type = ["staticlib"
 
 [dependencies]
 bitcoin = "0.24"
+secp256k1 = { version = "0.18", features = ["global-context", "rand-std"] }
 lightning = { version = "0.0.12", path = "../lightning" }
 
 # We eventually want to join the root workspace, but for now, the bindings generation is