Skip to content

Commit 84a174c

Browse files
committed
Allow pkg-config to omit include paths if they equals to standard.
See #114
1 parent 888b2bb commit 84a174c

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

build/find_normal.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn get_env_var(name: &str) -> String {
1010
}
1111
}
1212

13-
pub fn probe_lua() -> PathBuf {
13+
pub fn probe_lua() -> Option<PathBuf> {
1414
let include_dir = get_env_var("LUA_INC");
1515
let lib_dir = get_env_var("LUA_LIB");
1616
let lua_lib = get_env_var("LUA_LIB_NAME");
@@ -38,7 +38,7 @@ pub fn probe_lua() -> PathBuf {
3838
println!("cargo:rustc-link-search=native={}", lib_dir);
3939
println!("cargo:rustc-link-lib={}{}", link_lib, lua_lib);
4040
}
41-
return PathBuf::from(include_dir);
41+
return Some(PathBuf::from(include_dir));
4242
}
4343

4444
// Find using `pkg-config`
@@ -73,11 +73,7 @@ pub fn probe_lua() -> PathBuf {
7373
lua.expect(&format!("cannot find Lua {} using `pkg-config`", ver))
7474
.include_paths
7575
.get(0)
76-
.expect(&format!(
77-
"cannot find Lua {} include paths using `pkg-config`",
78-
ver
79-
))
80-
.clone()
76+
.cloned()
8177
}
8278

8379
#[cfg(feature = "luajit")]
@@ -90,7 +86,6 @@ pub fn probe_lua() -> PathBuf {
9086
lua.expect("cannot find LuaJIT using `pkg-config`")
9187
.include_paths
9288
.get(0)
93-
.expect("cannot find LuaJIT include paths using `pkg-config`")
94-
.clone()
89+
.cloned()
9590
}
9691
}

build/find_vendored.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::PathBuf;
22

3-
pub fn probe_lua() -> PathBuf {
3+
pub fn probe_lua() -> Option<PathBuf> {
44
#[cfg(feature = "lua54")]
55
let artifacts = lua_src::Build::new().build(lua_src::Lua54);
66
#[cfg(feature = "lua53")]
@@ -21,5 +21,5 @@ pub fn probe_lua() -> PathBuf {
2121
#[cfg(not(feature = "module"))]
2222
artifacts.print_cargo_metadata();
2323

24-
artifacts.include_dir().to_owned()
24+
Some(artifacts.include_dir().to_owned())
2525
}

build/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ impl CommandExt for Command {
6868
}
6969
}
7070

71-
fn build_glue<P: AsRef<Path> + std::fmt::Debug>(include_path: &P) {
71+
// `include_path` is optional as Lua headers can be also found in compiler standard paths
72+
fn build_glue(include_path: Option<impl AsRef<Path>>) {
7273
let build_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
7374

7475
let mut config = cc::Build::new();
75-
config.include(include_path);
76+
if let Some(include_path) = include_path {
77+
config.include(include_path.as_ref());
78+
}
7679

7780
// Compile and run glue.c
7881
let glue = build_dir.join("glue");
@@ -243,11 +246,11 @@ fn main() {
243246
+ "Please, use `pkg-config` or custom mode to link to a Lua dll."
244247
);
245248

246-
let include_dir = find::probe_lua();
247249
if env::var("TARGET").unwrap() != env::var("HOST").unwrap() {
248250
generate_glue().unwrap();
249251
} else {
250-
build_glue(&include_dir);
252+
let include_dir = find::probe_lua();
253+
build_glue(include_dir);
251254
println!("cargo:rerun-if-changed=src/ffi/glue/glue.c");
252255
}
253256

0 commit comments

Comments
 (0)