This project demonstrates the recommended pattern of building Rust wrappers around a C library:
c-mylib
: a C library that builds into a static archive atc-mylib/out/libmylib.a
mylib-sys
: a minimal Rust FFI crate to expose that C library as unsafe Rustmylib-rs
: a safe Rust library that depends onmylib-sys
and makes it usable by other Rust code
To see a basic build and tests passing:
./test.sh
Or to build the C library using Link Time Optimizations (LTO), do
LDFLAGS=-flto ./test.sh
In this case, the rustflags
set in .cargo/config.toml allow
Rust to still link with the C library.