From 86d63ef27b257583675d8cd515d60c60ee650fe9 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Thu, 22 Jan 2026 15:46:31 +0000 Subject: [PATCH] Fix missing BUFSIZ for wasm32 in libc --- mlua-sys/src/lua51/lauxlib.rs | 8 ++++++-- mlua-sys/src/lua52/lauxlib.rs | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mlua-sys/src/lua51/lauxlib.rs b/mlua-sys/src/lua51/lauxlib.rs index 2b99083..767d8fe 100644 --- a/mlua-sys/src/lua51/lauxlib.rs +++ b/mlua-sys/src/lua51/lauxlib.rs @@ -154,10 +154,14 @@ pub unsafe fn luaL_opt( // Generic Buffer Manipulation // +#[cfg(target_arch = "wasm32")] +const BUFSIZ: usize = 1024; // WASI libc's BUFSIZ is 1024 +#[cfg(not(target_arch = "wasm32"))] +const BUFSIZ: usize = libc::BUFSIZ as usize; + // The buffer size used by the lauxlib buffer system. // The "16384" workaround is taken from the LuaJIT source code. -#[rustfmt::skip] -pub const LUAL_BUFFERSIZE: usize = if libc::BUFSIZ > 16384 { 8192 } else { libc::BUFSIZ as usize }; +pub const LUAL_BUFFERSIZE: usize = if BUFSIZ > 16384 { 8192 } else { BUFSIZ }; #[repr(C)] pub struct luaL_Buffer { diff --git a/mlua-sys/src/lua52/lauxlib.rs b/mlua-sys/src/lua52/lauxlib.rs index 635bf92..eb954a4 100644 --- a/mlua-sys/src/lua52/lauxlib.rs +++ b/mlua-sys/src/lua52/lauxlib.rs @@ -189,10 +189,14 @@ pub unsafe fn luaL_opt( // Generic Buffer Manipulation // +#[cfg(target_arch = "wasm32")] +const BUFSIZ: usize = 1024; // WASI libc's BUFSIZ is 1024 +#[cfg(not(target_arch = "wasm32"))] +const BUFSIZ: usize = libc::BUFSIZ as usize; + // The buffer size used by the lauxlib buffer system. // The "16384" workaround is taken from the LuaJIT source code. -#[rustfmt::skip] -pub const LUAL_BUFFERSIZE: usize = if libc::BUFSIZ > 16384 { 8192 } else { libc::BUFSIZ as usize }; +pub const LUAL_BUFFERSIZE: usize = if BUFSIZ > 16384 { 8192 } else { BUFSIZ }; #[repr(C)] pub struct luaL_Buffer {