X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=genbindings.sh;h=bfeda6bcdaebac000f32e4d1968355395c314821;hb=d924c7a8ae4344abfa934d95a0d3dc5f1d3437d3;hp=29e6ac1867eb460f2d886ff4419e9eef2efa4077;hpb=89be6254aea425552bd97e0d0b07ed5932017ca0;p=rust-lightning diff --git a/genbindings.sh b/genbindings.sh index 29e6ac18..bfeda6bc 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -6,7 +6,7 @@ set -x # Generate (and reasonably test) C bindings # First build the latest c-bindings-gen binary -cd c-bindings-gen && cargo build && cd .. +cd c-bindings-gen && cargo build --release && cd .. # Then wipe all the existing C bindings (because we're being run in the right directory) # note that we keep the few manually-generated files first: @@ -20,12 +20,15 @@ mv ./mod.rs lightning-c-bindings/src/c_types/ mv ./bitcoin lightning-c-bindings/src/ # Finally, run the c-bindings-gen binary, building fresh bindings. -SRC="$(pwd)/lightning/src" OUT="$(pwd)/lightning-c-bindings/src" OUT_TEMPL="$(pwd)/lightning-c-bindings/src/c_types/derived.rs" OUT_F="$(pwd)/lightning-c-bindings/include/rust_types.h" OUT_CPP="$(pwd)/lightning-c-bindings/include/lightningpp.hpp" -RUST_BACKTRACE=1 ./c-bindings-gen/target/debug/c-bindings-gen $SRC/ $OUT/ lightning $OUT_TEMPL $OUT_F $OUT_CPP + +cd lightning +RUSTC_BOOTSTRAP=1 cargo rustc --profile=check -- -Zunstable-options --pretty=expanded | + RUST_BACKTRACE=1 ../c-bindings-gen/target/release/c-bindings-gen $OUT/ lightning $OUT_TEMPL $OUT_F $OUT_CPP +cd .. # Now cd to lightning-c-bindings, build the generated bindings, and call cbindgen to build a C header file PATH="$PATH:~/.cargo/bin" @@ -41,8 +44,16 @@ HOST_PLATFORM="$(rustc --version --verbose | grep "host:")" if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then # OSX sed is for some reason not compatible with GNU sed sed -i '' 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h + + # 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 //g' include/lightning.h else sed -i 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h + + # 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 //g' include/lightning.h fi # Finally, sanity-check the generated C and C++ bindings with demo apps: @@ -168,6 +179,9 @@ else echo "WARNING: Can't use address sanitizer on non-Linux, non-OSX non-x86 platforms" fi +cargo rustc -v --target=wasm32-wasi -- -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-wasi -- -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++ $CFLAGS -std=c++11 -flto -O2 demo.cpp target/release/libldk.a -ldl