Skip to content

Commit 73528d7

Browse files
committed
Add a POSIX C LDK networking library
1 parent 74665e3 commit 73528d7

File tree

4 files changed

+529
-2
lines changed

4 files changed

+529
-2
lines changed

genbindings.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,23 @@ fi
209209
gcc $LOCAL_CFLAGS -Wall -g -pthread demo.c target/debug/libldk.a -ldl
210210
./a.out
211211

212-
# And run the C++ demo app in valgrind to test memory model correctness and lack of leaks.
212+
# And run the C++ demo app
213213
g++ $LOCAL_CFLAGS -std=c++11 -Wall -g -pthread demo.cpp -Ltarget/debug/ -lldk -ldl
214+
LD_LIBRARY_PATH=target/debug/ ./a.out > /dev/null
215+
216+
# Finally, run the C++ demo app with our native networking library
217+
# in valgrind to test memory model correctness and lack of leaks.
218+
gcc $LOCAL_CFLAGS -std=c99 -Wall -g -pthread -I../ldk-net ../ldk-net/ldk_net.c -c -o ldk_net.o
219+
g++ $LOCAL_CFLAGS -std=c++11 -Wall -g -pthread -DREAL_NET -I../ldk-net ldk_net.o demo.cpp target/debug/libldk.a -ldl
214220
if [ -x "`which valgrind`" ]; then
215-
LD_LIBRARY_PATH=target/debug/ valgrind --error-exitcode=4 --memcheck:leak-check=full --show-leak-kinds=all ./a.out
221+
valgrind --error-exitcode=4 --memcheck:leak-check=full --show-leak-kinds=all ./a.out
216222
echo
217223
else
218224
echo "WARNING: Please install valgrind for more testing"
225+
./a.out
219226
fi
220227

228+
221229
# Test a statically-linked C++ version, tracking the resulting binary size and runtime
222230
# across debug, LTO, and cross-language LTO builds (using the same compiler each time).
223231
clang++ $LOCAL_CFLAGS -std=c++11 demo.cpp target/debug/libldk.a -ldl
@@ -248,6 +256,11 @@ if [ "$HOST_PLATFORM" = "host: x86_64-unknown-linux-gnu" ]; then
248256
clang++-$LLVM_V $LOCAL_CFLAGS -std=c++11 -fsanitize=memory -fsanitize-memory-track-origins -g demo.cpp target/debug/libldk.a -ldl
249257
./a.out >/dev/null
250258

259+
# ...then the C++ demo app with the ldk_net network implementation
260+
clang-$LLVM_V $LOCAL_CFLAGS -std=c99 -fsanitize=memory -fsanitize-memory-track-origins -g -I../ldk-net ../ldk-net/ldk_net.c -c -o ldk_net.o
261+
clang++-$LLVM_V $LOCAL_CFLAGS -std=c++11 -fsanitize=memory -fsanitize-memory-track-origins -g -DREAL_NET -I../ldk-net ldk_net.o demo.cpp target/debug/libldk.a -ldl
262+
./a.out >/dev/null
263+
251264
# restore exit-on-failure
252265
set -e
253266
else
@@ -315,6 +328,11 @@ if [ "$HOST_PLATFORM" = "host: x86_64-unknown-linux-gnu" -o "$HOST_PLATFORM" = "
315328
# ...then the C++ demo app
316329
$CLANGPP $LOCAL_CFLAGS -std=c++11 -fsanitize=address -g demo.cpp target/debug/libldk.a -ldl
317330
ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' ./a.out >/dev/null
331+
332+
# ...then the C++ demo app with the ldk_net network implementation
333+
$CLANG $LOCAL_CFLAGS -fsanitize=address -g -I../ldk-net ../ldk-net/ldk_net.c -c -o ldk_net.o
334+
$CLANGPP $LOCAL_CFLAGS -std=c++11 -fsanitize=address -g -DREAL_NET -I../ldk-net ldk_net.o demo.cpp target/debug/libldk.a -ldl
335+
ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' ./a.out >/dev/null
318336
else
319337
echo "WARNING: Please install clang-$RUSTC_LLVM_V and clang++-$RUSTC_LLVM_V to build with address sanitizer"
320338
fi

0 commit comments

Comments
 (0)