]> git.bitcoin.ninja Git - rust-lightning/commitdiff
[bindings] Fix genbindings.sh compile issues on OSX 2020-12-chanman-bindings-deser
authorMatt Corallo <git@bluematt.me>
Wed, 3 Feb 2021 00:28:40 +0000 (19:28 -0500)
committerMatt Corallo <git@bluematt.me>
Wed, 3 Feb 2021 15:11:35 +0000 (10:11 -0500)
There were two issues on OSX - we need to give gcc the clang
warnings flags because `gcc` *is* clang on OSX and we missed an
`-std=c++11` on one of the clang++ calls, causing compile failures.

genbindings.sh

index c63de7dbc055f5d56c0a5d1085eb7ad4ea38b7e0..29e6ac1867eb460f2d886ff4419e9eef2efa4077 100755 (executable)
@@ -47,12 +47,14 @@ fi
 
 # Finally, sanity-check the generated C and C++ bindings with demo apps:
 
+CFLAGS="-Wall -Wno-nullability-completeness -pthread"
+
 # Naively run the C demo app:
-gcc -Wall -g -pthread demo.c target/debug/libldk.a -ldl
+gcc $CFLAGS -Wall -g -pthread demo.c target/debug/libldk.a -ldl
 ./a.out
 
 # And run the C++ demo app in valgrind to test memory model correctness and lack of leaks.
-g++ -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
 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
@@ -60,11 +62,9 @@ else
        echo "WARNING: Please install valgrind for more testing"
 fi
 
-CLANGOPTS="-Wall -Wno-nullability-completeness -pthread"
-
 # 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++ $CLANGOPTS demo.cpp target/debug/libldk.a -ldl
+clang++ $CFLAGS -std=c++11 demo.cpp target/debug/libldk.a -ldl
 strip ./a.out
 echo " C++ Bin size and runtime w/o optimization:"
 ls -lha a.out
@@ -85,11 +85,11 @@ if [ "$HOST_PLATFORM" = "host: x86_64-unknown-linux-gnu" ]; then
                        set +e
 
                        # First the C demo app...
-                       clang-$LLVM_V $CLANGOPTS -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
                        ./a.out
 
                        # ...then the C++ demo app
-                       clang++-$LLVM_V -std=c++11 $CLANGOPTS -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
                        ./a.out >/dev/null
 
                        # restore exit-on-failure
@@ -155,11 +155,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 $CLANGOPTS -fsanitize=address -g demo.c target/debug/libldk.a -ldl
+               $CLANG $CFLAGS -fsanitize=address -g demo.c target/debug/libldk.a -ldl
                ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' ./a.out
 
                # ...then the C++ demo app
-               $CLANGPP $CLANGOPTS -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
                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"
@@ -170,7 +170,7 @@ fi
 
 # 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
+clang++ $CFLAGS -std=c++11 -flto -O2 demo.cpp target/release/libldk.a -ldl
 strip ./a.out
 echo "C++ Bin size and runtime with only RL (LTO) optimized:"
 ls -lha a.out
@@ -183,7 +183,7 @@ if [ "$HOST_PLATFORM" != "host: x86_64-apple-darwin" -a "$CLANGPP" != "" ]; then
        # packaging than simply shipping the rustup binaries (eg Debian should Just Work
        # here).
        CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release -- -C linker-plugin-lto -C lto -C link-arg=-fuse-ld=lld
-       $CLANGPP $CLANGOPTS -flto -fuse-ld=lld -O2 demo.cpp target/release/libldk.a -ldl
+       $CLANGPP $CFLAGS -flto -fuse-ld=lld -O2 demo.cpp target/release/libldk.a -ldl
        strip ./a.out
        echo "C++ Bin size and runtime with cross-language LTO:"
        ls -lha a.out