use cmake::Config;
macro_rules! define_lua_cfg {
([no_override] $config:ident, $c_macro:literal, $value:expr) => {
let value = $value;
$config.cflag(format!("-D{}={}", $c_macro, value));
$config.cxxflag(format!("-D{}={}", $c_macro, value));
println!("cargo::rustc-env={}={}", $c_macro, value);
};
($config:ident, $c_macro:literal, $src:literal) => {
let val = std::env::var($c_macro).unwrap_or(($src).to_string());
define_lua_cfg!([no_override] $config, $c_macro, val)
};
}
fn do_cfg(config: &mut Config) {
define_lua_cfg!(config, "LUA_IDSIZE", "256");
define_lua_cfg!(config, "LUA_MINSTACK", "20");
define_lua_cfg!(config, "LUAI_MAXCSTACK", "8000");
define_lua_cfg!(config, "LUAI_MAXCALLS", "20000");
define_lua_cfg!(config, "LUAI_MAXCCALLS", "200");
define_lua_cfg!(config, "LUA_BUFFERSIZE", "512");
define_lua_cfg!(config, "LUA_UTAG_LIMIT", "128");
define_lua_cfg!(config, "LUA_LUTAG_LIMIT", "128");
define_lua_cfg!(config, "LUA_SIZECLASSES", "40");
define_lua_cfg!(config, "LUA_MEMORY_CATEGORIES", "256");
define_lua_cfg!(config, "LUA_MINSTRTABSIZE", "32");
define_lua_cfg!(config, "LUA_MAXCAPTURES", "32");
#[cfg(not(feature="luau_vector4"))]
define_lua_cfg!(config, "LUA_VECTOR_SIZE", "3");
#[cfg(feature="luau_vector4")]
define_lua_cfg!(config, "LUA_VECTOR_SIZE", "4");
}
fn main() {
let mut config = cmake::Config::new("luau");
config
.define("LUAU_BUILD_CLI", "OFF")
.define("LUAU_BUILD_TESTS", "OFF")
.define("LUAU_STATIC_CRT", "ON")
.define("LUAU_EXTERN_C", "ON")
.define("LUAU_ENABLE_ASSERT", "ON")
.profile(if cfg!(debug_assertions) {
"RelWithDebInfo"
} else {
"Release"
})
.no_build_target(true);
do_cfg(&mut config);
#[cfg(target_os = "windows")]
config.cxxflag("/EHsc");
let destination = config.build();
#[cfg(not(target_os = "windows"))]
println!(
"cargo:rustc-link-search=native={}/build",
destination.display()
);
#[cfg(target_os = "windows")]
{
#[cfg(debug_assertions)]
println!(
"cargo:rustc-link-search=native={}/build/RelWithDebInfo",
destination.display()
);
#[cfg(not(debug_assertions))]
println!(
"cargo:rustc-link-search=native={}/build/Release",
destination.display()
);
}
println!("cargo:rustc-link-lib=static=Luau.VM");
#[cfg(feature = "compiler")]
println!("cargo:rustc-link-lib=static=Luau.Compiler");
#[cfg(feature = "compiler")]
println!("cargo:rustc-link-lib=static=Luau.Ast");
#[cfg(feature = "codegen")]
println!("cargo:rustc-link-lib=static=Luau.CodeGen");
#[cfg(not(target_os = "windows"))]
println!("cargo:rustc-link-lib=stdc++");
}