diff --git a/Cargo.toml b/Cargo.toml index fb432cf8..1fc14c05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ luau = ["ffi/luau", "dep:libloading"] luau-jit = ["luau", "ffi/luau-codegen"] luau-vector4 = ["luau", "ffi/luau-vector4"] vendored = ["ffi/vendored"] +external = ["ffi/external"] module = ["dep:mlua_derive", "ffi/module"] async = ["dep:futures-util"] send = ["parking_lot/send_guard", "error-send"] diff --git a/mlua-sys/Cargo.toml b/mlua-sys/Cargo.toml index f4171a15..39b6f276 100644 --- a/mlua-sys/Cargo.toml +++ b/mlua-sys/Cargo.toml @@ -30,6 +30,7 @@ luau = ["luau0-src"] luau-codegen = ["luau"] luau-vector4 = ["luau"] vendored = ["lua-src", "luajit-src"] +external = [] module = [] [dependencies] diff --git a/mlua-sys/build/main_inner.rs b/mlua-sys/build/main_inner.rs index 05ac53b5..dc97f38d 100644 --- a/mlua-sys/build/main_inner.rs +++ b/mlua-sys/build/main_inner.rs @@ -14,22 +14,29 @@ fn main() { #[cfg(all(feature = "luau", feature = "module", windows))] compile_error!("Luau does not support `module` mode on Windows"); - #[cfg(all(feature = "module", feature = "vendored"))] - compile_error!("`vendored` and `module` features are mutually exclusive"); + #[cfg(any( + all(feature = "vendored", any(feature = "external", feature = "module")), + all(feature = "external", any(feature = "vendored", feature = "module")), + all(feature = "module", any(feature = "vendored", feature = "external")) + ))] + compile_error!("`vendored`, `external` and `module` features are mutually exclusive"); println!("cargo:rerun-if-changed=build"); - let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); - if target_os == "windows" && cfg!(feature = "module") { - if !std::env::var("LUA_LIB_NAME").unwrap_or_default().is_empty() { - // Don't use raw-dylib linking - find::probe_lua(); - return; + // Check if compilation and linking is handled by external crate + if !cfg!(feature = "external") { + let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); + if target_os == "windows" && cfg!(feature = "module") { + if !std::env::var("LUA_LIB_NAME").unwrap_or_default().is_empty() { + // Don't use raw-dylib linking + find::probe_lua(); + return; + } + + println!("cargo:rustc-cfg=raw_dylib"); } - println!("cargo:rustc-cfg=raw_dylib"); + #[cfg(not(feature = "module"))] + find::probe_lua(); } - - #[cfg(not(feature = "module"))] - find::probe_lua(); }