Skip to content

Commit 04aaa18

Browse files
authored
feat: Allow external build scripts to link Lua libraries (#529)
Allow external build scripts to link Lua libraries
1 parent d8455c0 commit 04aaa18

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

mlua-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ luau = ["luau0-src"]
3030
luau-codegen = ["luau"]
3131
luau-vector4 = ["luau"]
3232
vendored = ["lua-src", "luajit-src"]
33+
external = []
3334
module = []
3435

3536
[dependencies]

mlua-sys/build/main_inner.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,29 @@ fn main() {
1414
#[cfg(all(feature = "luau", feature = "module", windows))]
1515
compile_error!("Luau does not support `module` mode on Windows");
1616

17-
#[cfg(all(feature = "module", feature = "vendored"))]
18-
compile_error!("`vendored` and `module` features are mutually exclusive");
17+
#[cfg(any(
18+
all(feature = "vendored", any(feature = "external", feature = "module")),
19+
all(feature = "external", any(feature = "vendored", feature = "module")),
20+
all(feature = "module", any(feature = "vendored", feature = "external"))
21+
))]
22+
compile_error!("`vendored`, `external` and `module` features are mutually exclusive");
1923

2024
println!("cargo:rerun-if-changed=build");
2125

22-
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
23-
if target_os == "windows" && cfg!(feature = "module") {
24-
if !std::env::var("LUA_LIB_NAME").unwrap_or_default().is_empty() {
25-
// Don't use raw-dylib linking
26-
find::probe_lua();
27-
return;
26+
// Check if compilation and linking is handled by external crate
27+
if !cfg!(feature = "external") {
28+
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
29+
if target_os == "windows" && cfg!(feature = "module") {
30+
if !std::env::var("LUA_LIB_NAME").unwrap_or_default().is_empty() {
31+
// Don't use raw-dylib linking
32+
find::probe_lua();
33+
return;
34+
}
35+
36+
println!("cargo:rustc-cfg=raw_dylib");
2837
}
2938

30-
println!("cargo:rustc-cfg=raw_dylib");
39+
#[cfg(not(feature = "module"))]
40+
find::probe_lua();
3141
}
32-
33-
#[cfg(not(feature = "module"))]
34-
find::probe_lua();
3542
}

0 commit comments

Comments
 (0)