This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
58 lines (51 loc) · 1.72 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#[cfg(feature = "vendored")]
fn main() {
use std::env;
use std::path::Path;
const LUA_DIR_NAME: &str = "lua-5.4.4";
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap();
let mut config = lua_builder();
if target_os == "linux" {
config.warnings(false).extra_warnings(false);
config.define("LUA_USE_LINUX", None);
} else if target_os == "macos" {
config.define("LUA_USE_MACOSX", None);
} else if target_family == "unix" {
config.define("LUA_USE_POSIX", None);
} else if target_family == "windows" {
config.define("LUA_USE_WINDOWS", None);
}
if cfg!(debug_assertions) {
config.define("LUA_USE_APICHECK", None);
}
println!("cargo:rerun-if-changed={LUA_DIR_NAME}/");
println!(
"cargo:luasrc={}",
Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap())
.join(LUA_DIR_NAME)
.to_string_lossy()
);
if env::var("CARGO_FEATURE_THREAD").is_ok() {
config.define("LUA_USER_H", "\"../src/llua.h\"");
}
add_files(&mut config, LUA_DIR_NAME, |n| {
n.ends_with(".c") && !n.ends_with("lua.c") && !n.ends_with("luac.c")
});
config.compile("lua54");
fn add_files(b: &mut cc::Build, dir: &str, cb: fn(&str) -> bool) {
for entry in std::fs::read_dir(dir).unwrap() {
let path = entry.unwrap().path();
if path.to_str().map(cb).unwrap_or(false) {
b.file(path);
}
}
}
fn lua_builder() -> cc::Build {
let mut result = cc::Build::new();
result.include(LUA_DIR_NAME);
result
}
}
#[cfg(not(feature = "vendored"))]
fn main() {}