From 1905178bd28effaf043a6f063ff2db228b6a050f Mon Sep 17 00:00:00 2001 From: Sculas Date: Sat, 15 Feb 2025 01:25:46 +0100 Subject: [PATCH 1/2] feat: Allow external build scripts to link Lua libraries --- Cargo.toml | 1 + mlua-sys/Cargo.toml | 1 + mlua-sys/build/main_inner.rs | 31 +++++++++++++++++++------------ 3 files changed, 21 insertions(+), 12 deletions(-) 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(); } From 248770e52d9961b8189e23f7672bed26c0af83f2 Mon Sep 17 00:00:00 2001 From: Sculas Date: Wed, 11 Jun 2025 12:22:15 +0200 Subject: [PATCH 2/2] refactor: remove `external` feature flag --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index dd2d2ba5..65ac1ba8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,6 @@ luau = ["ffi/luau"] luau-jit = ["luau", "ffi/luau-codegen"] luau-vector4 = ["luau", "ffi/luau-vector4"] vendored = ["ffi/vendored"] -external = ["ffi/external"] module = ["mlua_derive", "ffi/module"] async = ["dep:futures-util"] send = ["error-send"]