1 个不稳定版本
0.1.0 | 2021年1月18日 |
---|
#7 在 #federated-learning
用于 xaynet
470KB
8K SLoC
Xaynet FFI
生成 C-头文件
ffi-support
提供了一些有助于减少样板代码的宏。然而,在生成 C-头文件期间展开这些宏的功能(--pretty=expanded
)仍然不稳定。因此,我们需要使用 rust nightly。
要生成头文件,请安装 cbindgen
并运行
cargo build
RUSTUP_TOOLCHAIN=nightly cbindgen \
--config cbindgen.toml \
--crate xaynet-mobile \
--output xaynet_ffi.h
运行测试
macOS
cc -o tests/ffi_test.o -Wl,-dead_strip -I. tests/ffi_test.c ../target/debug/libxaynet_mobile.a -framework Security -framework Foundation
./tests/ffi_test.o
Linux
gcc \
tests/ffi_test.c
-Wall \
-I. \
-lpthread -lm -ldl \
../target/debug/libxaynet_mobile.a \
-o tests/ffi_test.o
./tests/ffi_test.o
要检查内存泄漏,可以使用 Valgrind
valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all -s ./tests/ffi_test.o
依赖
~31MB
~339K SLoC