ultrasaurus / rust-clib

example of writing a library that can be called from C or Rust
MIT License
9 stars 3 forks source link

rust-clib

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

Docs I found helpful

The Rust part

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

references that might be helpful

Changelog