diff --git a/build/find_normal.rs b/build/find_normal.rs index cf71691..d9c0e1c 100644 --- a/build/find_normal.rs +++ b/build/find_normal.rs @@ -10,7 +10,7 @@ fn get_env_var(name: &str) -> String { } } -pub fn probe_lua() -> PathBuf { +pub fn probe_lua() -> Option { 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() } } diff --git a/build/find_vendored.rs b/build/find_vendored.rs index 46b87d3..3b8902f 100644 --- a/build/find_vendored.rs +++ b/build/find_vendored.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -pub fn probe_lua() -> PathBuf { +pub fn probe_lua() -> Option { #[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()) } diff --git a/build/main.rs b/build/main.rs index 833766d..a11327f 100644 --- a/build/main.rs +++ b/build/main.rs @@ -68,11 +68,14 @@ impl CommandExt for Command { } } -fn build_glue + 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>) { 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"); }