47
47
48
48
# Finally, sanity-check the generated C and C++ bindings with demo apps:
49
49
50
+ CFLAGS=" -Wall -Wno-nullability-completeness -pthread"
51
+
50
52
# Naively run the C demo app:
51
- gcc -Wall -g -pthread demo.c target/debug/libldk.a -ldl
53
+ gcc $CFLAGS -Wall -g -pthread demo.c target/debug/libldk.a -ldl
52
54
./a.out
53
55
54
56
# And run the C++ demo app in valgrind to test memory model correctness and lack of leaks.
55
- g++ -std=c++11 -Wall -g -pthread demo.cpp -Ltarget/debug/ -lldk -ldl
57
+ g++ $CFLAGS -std=c++11 -Wall -g -pthread demo.cpp -Ltarget/debug/ -lldk -ldl
56
58
if [ -x " ` which valgrind` " ]; then
57
59
LD_LIBRARY_PATH=target/debug/ valgrind --error-exitcode=4 --memcheck:leak-check=full --show-leak-kinds=all ./a.out
58
60
echo
59
61
else
60
62
echo " WARNING: Please install valgrind for more testing"
61
63
fi
62
64
63
- CLANGOPTS=" -Wall -Wno-nullability-completeness -pthread"
64
-
65
65
# Test a statically-linked C++ version, tracking the resulting binary size and runtime
66
66
# across debug, LTO, and cross-language LTO builds (using the same compiler each time).
67
- clang++ $CLANGOPTS demo.cpp target/debug/libldk.a -ldl
67
+ clang++ $CFLAGS -std=c++11 demo.cpp target/debug/libldk.a -ldl
68
68
strip ./a.out
69
69
echo " C++ Bin size and runtime w/o optimization:"
70
70
ls -lha a.out
@@ -85,11 +85,11 @@ if [ "$HOST_PLATFORM" = "host: x86_64-unknown-linux-gnu" ]; then
85
85
set +e
86
86
87
87
# First the C demo app...
88
- clang-$LLVM_V $CLANGOPTS -fsanitize=memory -fsanitize-memory-track-origins -g demo.c target/debug/libldk.a -ldl
88
+ clang-$LLVM_V $CFLAGS -fsanitize=memory -fsanitize-memory-track-origins -g demo.c target/debug/libldk.a -ldl
89
89
./a.out
90
90
91
91
# ...then the C++ demo app
92
- clang++-$LLVM_V -std=c++11 $CLANGOPTS -fsanitize=memory -fsanitize-memory-track-origins -g demo.cpp target/debug/libldk.a -ldl
92
+ clang++-$LLVM_V $CFLAGS -std=c++11 -fsanitize=memory -fsanitize-memory-track-origins -g demo.cpp target/debug/libldk.a -ldl
93
93
./a.out > /dev/null
94
94
95
95
# restore exit-on-failure
@@ -155,11 +155,11 @@ if [ "$HOST_PLATFORM" = "host: x86_64-unknown-linux-gnu" -o "$HOST_PLATFORM" = "
155
155
mv Cargo.toml.bk Cargo.toml
156
156
157
157
# First the C demo app...
158
- $CLANG $CLANGOPTS -fsanitize=address -g demo.c target/debug/libldk.a -ldl
158
+ $CLANG $CFLAGS -fsanitize=address -g demo.c target/debug/libldk.a -ldl
159
159
ASAN_OPTIONS=' detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' ./a.out
160
160
161
161
# ...then the C++ demo app
162
- $CLANGPP $CLANGOPTS -std=c++11 -fsanitize=address -g demo.cpp target/debug/libldk.a -ldl
162
+ $CLANGPP $CFLAGS -std=c++11 -fsanitize=address -g demo.cpp target/debug/libldk.a -ldl
163
163
ASAN_OPTIONS=' detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' ./a.out > /dev/null
164
164
else
165
165
echo " WARNING: Please install clang-$RUSTC_LLVM_V and clang++-$RUSTC_LLVM_V to build with address sanitizer"
170
170
171
171
# Now build with LTO on on both C++ and rust, but without cross-language LTO:
172
172
CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release -- -C lto
173
- clang++ $CLANGOPTS -std=c++11 -flto -O2 demo.cpp target/release/libldk.a -ldl
173
+ clang++ $CFLAGS -std=c++11 -flto -O2 demo.cpp target/release/libldk.a -ldl
174
174
strip ./a.out
175
175
echo " C++ Bin size and runtime with only RL (LTO) optimized:"
176
176
ls -lha a.out
@@ -183,7 +183,7 @@ if [ "$HOST_PLATFORM" != "host: x86_64-apple-darwin" -a "$CLANGPP" != "" ]; then
183
183
# packaging than simply shipping the rustup binaries (eg Debian should Just Work
184
184
# here).
185
185
CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release -- -C linker-plugin-lto -C lto -C link-arg=-fuse-ld=lld
186
- $CLANGPP $CLANGOPTS -flto -fuse-ld=lld -O2 demo.cpp target/release/libldk.a -ldl
186
+ $CLANGPP $CFLAGS -flto -fuse-ld=lld -O2 demo.cpp target/release/libldk.a -ldl
187
187
strip ./a.out
188
188
echo " C++ Bin size and runtime with cross-language LTO:"
189
189
ls -lha a.out
0 commit comments