Hello,
I have a dumb question, but lots of reading and trial-error hasn't worked yet. @kornel 's guide (Using C libraries in Rust: make a sys crate) is awesome, and the Cargo book also tiptoes right up to my question but unfortunately stops short of answering it. (Build Script Examples - The Cargo Book)
I'm trying to create a sys crate to build a C project from source. (https://rosie-lang.org, if you're curious) It has a dependency on Lua.
So, I depend on the mlua crate in my Cargo.toml like this:
[dependencies]
mlua = { version = "0.6.4", features = ["lua53", "vendored"] }
And, sure enough, it builds the dependency I need. And in my build.rs
file, I can get the include path and the library dir path (and by extension the library path) from the environment variables like this:
let lua_include_dir = std::env::var_os("DEP_LUA_INCLUDE").unwrap().into_string().unwrap();
let lua_lib_dir = std::env::var_os("DEP_LUA_LIB").unwrap().into_string().unwrap();
let lua_lib = format!("{}/liblua5.3.a", lua_lib_dir);
And when I manually invoke cc
(clang) from the terminal, using these paths, I get the build output that I want. But I cannot for the life of me figure out the right calls to make to cc::Build
to get it to link the Lua build's output archive into my library.
On the command line, I just pass the path to the .a
I want to link as another file in the list of source files, but that doesn't work for cc::Build
, nor does passing it to include()
or object()
.
Here is what I have right now:
let mut cfg = cc::Build::new();
cfg.static_flag(true);
cfg.include(lua_include_dir);
//How do I specify lua_lib_dir or lua_lib so it gets linked into my output lib??
for src_file in src_files {
cfg.file(src_file);
}
cfg.compile("rosie");
Any help or insight is very much appreciated. Thank you.