Tart is a Rust library for compiling and linking code written in multiple languages by their native toolchains. This project is inspired by and contains adapted code from cc.
- C
- C++
- Go
Language support is controlled via Cargo features:
ccppgo
In your build.rs, you'd want to have this:
fn main() {
tart::Build::new()
.language(tart::Languages::C) // Whichever language you are using
.add_file("src/my_file.c") // Path to your file
.compile("my_lib"); // Name of your library
}In your source files, your want to list your functions in an extern "C" block.
#[link(name = "my_lib")]
unsafe extern "C" {
fn add(a: i32, b: i32) -> i32;
fn multiply(a: i32, b: i32) -> i32;
...
}Call your functions in a unsafe block.
unsafe {
add(1, 2);
}Check the examples folder for language specific syntax.
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/license/mit)
at your option.