Skip to content

Commit 6a452e8

Browse files
committed
Fix vendored Lua bundling in static libraries
Bundle the Lua archive while keeping WASI support libraries external. Fixes mlua-rs/mlua#728
1 parent 1664c63 commit 6a452e8

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎src/lib.rs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct Build {
2828
pub struct Artifacts {
2929
include_dir: PathBuf,
3030
lib_dir: PathBuf,
31+
lua_lib: String,
3132
libs: Vec<String>,
3233
}
3334

@@ -131,7 +132,8 @@ impl Build {
131132
}
132133
}
133134

134-
let mut libs = vec![version.lib_name().to_string()];
135+
let lua_lib = version.lib_name().to_string();
136+
let mut libs = vec![lua_lib.clone()];
135137
match target {
136138
_ if target.contains("linux") => {
137139
config.define("LUA_USE_LINUX", None);
@@ -223,7 +225,7 @@ impl Build {
223225
.flag_if_supported("-fno-common") // Compile common globals like normal definitions
224226
.add_files_by_ext(&source_dir, "c")?
225227
.out_dir(&lib_dir)
226-
.try_compile(version.lib_name())?;
228+
.try_compile(&lua_lib)?;
227229

228230
for f in &["lauxlib.h", "lua.h", "luaconf.h", "lualib.h"] {
229231
let from = source_dir.join(f);
@@ -235,6 +237,7 @@ impl Build {
235237
Ok(Artifacts {
236238
include_dir,
237239
lib_dir,
240+
lua_lib,
238241
libs,
239242
})
240243
}
@@ -284,7 +287,8 @@ impl Artifacts {
284287
/// about the location of the Lua libraries and how to link them.
285288
pub fn print_cargo_metadata(&self) {
286289
println!("cargo:rustc-link-search=native={}", self.lib_dir.display());
287-
for lib in self.libs.iter() {
290+
println!("cargo:rustc-link-lib=static={}", self.lua_lib);
291+
for lib in self.libs.iter().filter(|lib| *lib != &self.lua_lib) {
288292
println!("cargo:rustc-link-lib=static:-bundle={lib}");
289293
}
290294
println!("cargo:include={}", self.include_dir.display());

0 commit comments

Comments
 (0)