Allow pkg-config to omit include paths if they equals to standard.

See #114
This commit is contained in:
Alex Orlenko 2021-12-28 11:58:20 +00:00
parent 888b2bbf8d
commit 84a174c94d
No known key found for this signature in database
GPG key ID: 4C150C250863B96D
3 changed files with 13 additions and 15 deletions

View file

@ -10,7 +10,7 @@ fn get_env_var(name: &str) -> String {
}
}
pub fn probe_lua() -> PathBuf {
pub fn probe_lua() -> Option<PathBuf> {
let include_dir = get_env_var("LUA_INC");
let lib_dir = get_env_var("LUA_LIB");
let lua_lib = get_env_var("LUA_LIB_NAME");
@ -38,7 +38,7 @@ pub fn probe_lua() -> PathBuf {
println!("cargo:rustc-link-search=native={}", lib_dir);
println!("cargo:rustc-link-lib={}{}", link_lib, lua_lib);
}
return PathBuf::from(include_dir);
return Some(PathBuf::from(include_dir));
}
// Find using `pkg-config`
@ -73,11 +73,7 @@ pub fn probe_lua() -> PathBuf {
lua.expect(&format!("cannot find Lua {} using `pkg-config`", ver))
.include_paths
.get(0)
.expect(&format!(
"cannot find Lua {} include paths using `pkg-config`",
ver
))
.clone()
.cloned()
}
#[cfg(feature = "luajit")]
@ -90,7 +86,6 @@ pub fn probe_lua() -> PathBuf {
lua.expect("cannot find LuaJIT using `pkg-config`")
.include_paths
.get(0)
.expect("cannot find LuaJIT include paths using `pkg-config`")
.clone()
.cloned()
}
}

View file

@ -1,6 +1,6 @@
use std::path::PathBuf;
pub fn probe_lua() -> PathBuf {
pub fn probe_lua() -> Option<PathBuf> {
#[cfg(feature = "lua54")]
let artifacts = lua_src::Build::new().build(lua_src::Lua54);
#[cfg(feature = "lua53")]
@ -21,5 +21,5 @@ pub fn probe_lua() -> PathBuf {
#[cfg(not(feature = "module"))]
artifacts.print_cargo_metadata();
artifacts.include_dir().to_owned()
Some(artifacts.include_dir().to_owned())
}

View file

@ -68,11 +68,14 @@ impl CommandExt for Command {
}
}
fn build_glue<P: AsRef<Path> + std::fmt::Debug>(include_path: &P) {
// `include_path` is optional as Lua headers can be also found in compiler standard paths
fn build_glue(include_path: Option<impl AsRef<Path>>) {
let build_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let mut config = cc::Build::new();
config.include(include_path);
if let Some(include_path) = include_path {
config.include(include_path.as_ref());
}
// Compile and run glue.c
let glue = build_dir.join("glue");
@ -243,11 +246,11 @@ fn main() {
+ "Please, use `pkg-config` or custom mode to link to a Lua dll."
);
let include_dir = find::probe_lua();
if env::var("TARGET").unwrap() != env::var("HOST").unwrap() {
generate_glue().unwrap();
} else {
build_glue(&include_dir);
let include_dir = find::probe_lua();
build_glue(include_dir);
println!("cargo:rerun-if-changed=src/ffi/glue/glue.c");
}