]> git.bitcoin.ninja Git - rust-lightning/commitdiff
build a wasm binding library
authorMatt Corallo <git@bluematt.me>
Sat, 9 Jan 2021 02:55:47 +0000 (21:55 -0500)
committerMatt Corallo <git@bluematt.me>
Fri, 15 Jan 2021 01:25:08 +0000 (20:25 -0500)
genbindings.sh
lightning-c-bindings/Cargo.toml
lightning-c-bindings/include/lightning.h

index c63de7dbc055f5d56c0a5d1085eb7ad4ea38b7e0..99616cc093a827905daa7a81bd3962d804eb7d33 100755 (executable)
@@ -45,6 +45,10 @@ else
        sed -i 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h
 fi
 
+# stdlib.h doesn't exist in clang's wasm sysroot, and cbindgen
+# doesn't actually use it anyway, so drop the import.
+sed -i 's/#include <stdlib.h>//g' include/lightning.h
+
 # Finally, sanity-check the generated C and C++ bindings with demo apps:
 
 # Naively run the C demo app:
@@ -168,6 +172,9 @@ else
        echo "WARNING: Can't use address sanitizer on non-Linux, non-OSX non-x86 platforms"
 fi
 
+cargo rustc -v --target=wasm32-unknown-unknown -- -C embed-bitcode=yes || echo "WARNING: Failed to generate WASM LLVM-bitcode-embedded library"
+CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release --target=wasm32-unknown-unknown -- -C opt-level=s -C linker-plugin-lto -C lto || echo "WARNING: Failed to generate WASM LLVM-bitcode-embedded optimized library"
+
 # Now build with LTO on on both C++ and rust, but without cross-language LTO:
 CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release -- -C lto
 clang++ $CLANGOPTS -std=c++11 -flto -O2 demo.cpp target/release/libldk.a -ldl
index 6bde30475f93382ffe58d0f0df3eaf63a580d57f..3d073d65984c851976405d99b59b77ba6640e711 100644 (file)
@@ -18,6 +18,13 @@ crate-type = ["staticlib"
 bitcoin = "0.24"
 lightning = { version = "0.0.12", path = "../lightning" }
 
+# Always force panic=abort, further options are set in the genbindings.sh build script
+[profile.dev]
+panic = "abort"
+
+[profile.release]
+panic = "abort"
+
 # We eventually want to join the root workspace, but for now, the bindings generation is
 # a bit brittle and we don't want to hold up other developers from making changes just
 # because they break the bindings
index 92900cb833384c269c25004117b82029df2f03a9..9b7ee16a6c9ed22d77e2e5ca7dcbcefc5d4b40ec 100644 (file)
@@ -7,7 +7,7 @@
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdint.h>
-#include <stdlib.h>
+
 
 /**
  * An error when accessing the chain via [`Access`].