An example project that uses Rust to create a library with C API.
Build rust lib and run C tests
(cd mylib && cargo build)
make test
successful output looks like this:
Compiling add v0.2.0 (~/src/rust/clib/mylib)
Finished dev [unoptimized + debuginfo] target(s) in 4.21s
cp mylib/target/debug/libmylib.a .
gcc libmylib.a -o test test.o libmylib.a
./test
PASSED
Tests run: 4
in the my
directory is a Rust crate, which has tests along with a very
simple example that calls a function from Rust (that is also callable from C)
cd mylib
cargo test # test that we can call the function in Rust
cargo run --example stdin # interactive example