A year or so ago I added Rust support to Tundra https://github.com/deplinenoise/tundra
Tundra is written in C++ and uses Lua as a description lang for the build setup. I added so you can integrate RustCrates, RustPrograms etc to be used next to C/C++ libs directly.
To setup a C library you do:
StaticLibrary {
Name = "test_lib",
Sources = { "native_lib/lib.c" },
}
This will create a lib called test_lib and compiles the file lib.c
Now to build a Rust program that depends on this one does
RustProgram {
Name = "prog",
CargoConfig = "prog/Cargo.toml",
Sources = { "prog/src/main.rs", "prog/build.rs" },
Depends = { "test_lib" },
}
My problem here is how do I tell Cargo about this dependency? The only way I found out really was to use env variables so it would do something like this
export TUNDRA_OBJECTDIR=t2-output/macosx-gcc-debug-default ;
export CARGO_TARGET_DIR=t2-output/macosx-gcc-debug-default/__prog ;
export TUNDRA_STATIC_LIBS="test_lib" ; cargo build --manifest-path=prog/Cargo.toml
Then inside build.rs I have to take the TUNDRA_STATIC_LIBS apart to tell Cargo what libs to link with:
use std::env;
fn main() {
let tundra_dir = env::var("TUNDRA_OBJECTDIR").unwrap_or("".to_string());
let libs = env::var("TUNDRA_STATIC_LIBS").unwrap_or("".to_string());
let native_libs = libs.split(" ");
println!("cargo:rustc-link-search=native={}", tundra_dir);
for lib in native_libs {
println!("cargo:rustc-link-lib=static={}", lib);
println!("cargo:rerun-if-changed={}", lib);
}
}
So while this works it’s slightly annoying. It would be great if this could have been passed to Cargo as general arguments instead because now I have to rely on build.rs that takes this in. In practice it hasn’t been a major issue but this could be improved.