File tree 3 files changed +13
-15
lines changed 3 files changed +13
-15
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ fn get_env_var(name: &str) -> String {
10
10
}
11
11
}
12
12
13
- pub fn probe_lua ( ) -> PathBuf {
13
+ pub fn probe_lua ( ) -> Option < PathBuf > {
14
14
let include_dir = get_env_var ( "LUA_INC" ) ;
15
15
let lib_dir = get_env_var ( "LUA_LIB" ) ;
16
16
let lua_lib = get_env_var ( "LUA_LIB_NAME" ) ;
@@ -38,7 +38,7 @@ pub fn probe_lua() -> PathBuf {
38
38
println ! ( "cargo:rustc-link-search=native={}" , lib_dir) ;
39
39
println ! ( "cargo:rustc-link-lib={}{}" , link_lib, lua_lib) ;
40
40
}
41
- return PathBuf :: from ( include_dir) ;
41
+ return Some ( PathBuf :: from ( include_dir) ) ;
42
42
}
43
43
44
44
// Find using `pkg-config`
@@ -73,11 +73,7 @@ pub fn probe_lua() -> PathBuf {
73
73
lua. expect ( & format ! ( "cannot find Lua {} using `pkg-config`" , ver) )
74
74
. include_paths
75
75
. get ( 0 )
76
- . expect ( & format ! (
77
- "cannot find Lua {} include paths using `pkg-config`" ,
78
- ver
79
- ) )
80
- . clone ( )
76
+ . cloned ( )
81
77
}
82
78
83
79
#[ cfg( feature = "luajit" ) ]
@@ -90,7 +86,6 @@ pub fn probe_lua() -> PathBuf {
90
86
lua. expect ( "cannot find LuaJIT using `pkg-config`" )
91
87
. include_paths
92
88
. get ( 0 )
93
- . expect ( "cannot find LuaJIT include paths using `pkg-config`" )
94
- . clone ( )
89
+ . cloned ( )
95
90
}
96
91
}
Original file line number Diff line number Diff line change 1
1
use std:: path:: PathBuf ;
2
2
3
- pub fn probe_lua ( ) -> PathBuf {
3
+ pub fn probe_lua ( ) -> Option < PathBuf > {
4
4
#[ cfg( feature = "lua54" ) ]
5
5
let artifacts = lua_src:: Build :: new ( ) . build ( lua_src:: Lua54 ) ;
6
6
#[ cfg( feature = "lua53" ) ]
@@ -21,5 +21,5 @@ pub fn probe_lua() -> PathBuf {
21
21
#[ cfg( not( feature = "module" ) ) ]
22
22
artifacts. print_cargo_metadata ( ) ;
23
23
24
- artifacts. include_dir ( ) . to_owned ( )
24
+ Some ( artifacts. include_dir ( ) . to_owned ( ) )
25
25
}
Original file line number Diff line number Diff line change @@ -68,11 +68,14 @@ impl CommandExt for Command {
68
68
}
69
69
}
70
70
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 > > ) {
72
73
let build_dir = PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) ;
73
74
74
75
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
+ }
76
79
77
80
// Compile and run glue.c
78
81
let glue = build_dir. join ( "glue" ) ;
@@ -243,11 +246,11 @@ fn main() {
243
246
+ "Please, use `pkg-config` or custom mode to link to a Lua dll."
244
247
) ;
245
248
246
- let include_dir = find:: probe_lua ( ) ;
247
249
if env:: var ( "TARGET" ) . unwrap ( ) != env:: var ( "HOST" ) . unwrap ( ) {
248
250
generate_glue ( ) . unwrap ( ) ;
249
251
} else {
250
- build_glue ( & include_dir) ;
252
+ let include_dir = find:: probe_lua ( ) ;
253
+ build_glue ( include_dir) ;
251
254
println ! ( "cargo:rerun-if-changed=src/ffi/glue/glue.c" ) ;
252
255
}
253
256
You can’t perform that action at this time.
0 commit comments