Skip to content

Compile luau for wasm32-unknown-unknown: skip stdio heap dump there - #743

Open
nikolchaa wants to merge 1 commit into
mlua-rs:mainfrom
nikolchaa:wasm32-unknown-heap-dump
Open

nikolchaa wants to merge 1 commit into
mlua-rs:mainfrom
nikolchaa:wasm32-unknown-heap-dump

Conversation

@nikolchaa

Copy link
Copy Markdown

Fixes #742. Related: #23, #662.

HeapDump::new uses libc stdio (tmpfile, fseek, ftell, rewind, fread, fclose), which the libc crate does not provide for wasm32-unknown-unknown, so the luau feature does not compile for that target.

This PR puts the stdio block behind #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]. On that target the dump buffer stays empty and HeapDump::new returns None, so Lua::heap_dump() returns the existing "unable to dump heap" error. Two allow attributes silence the unused-code warnings on that target only.

Every other target, including wasm32-unknown-emscripten, compiles exactly the same code as before.

Testing

  • cargo test --features "luau vendored": 310 passed, 0 failed, including test_heap_dump.
  • cargo clippy --features "luau vendored" -- -D warnings and cargo fmt --all --check: clean.
  • cargo build --lib --features "luau vendored" --target wasm32-unknown-unknown, with Luau's C++ built by clang against a wasi-sdk sysroot (LUAU_CXXFLAGS): fails on main with the 7 errors in luau feature fails to compile for wasm32-unknown-unknown (HeapDump uses libc stdio) #742, compiles with this change. Luau then runs in the browser under wasm-bindgen: eval, runtime and syntax errors, pcall and coroutines.

This doesn't make wasm32-unknown-unknown an officially supported target. It only removes the one Rust-side compile error, so projects that provide their own C++ toolchain can use it.

@yahyehussein

Copy link
Copy Markdown

We ran into the same problem building for wasm32-unknown-unknown with wgpu and winit; this fix works for us, and mlua's tests pass natively and on wasm32. Thanks!

@nikolchaa

Copy link
Copy Markdown
Author

We ran into the same problem building for wasm32-unknown-unknown with wgpu and winit; this fix works for us, and mlua's tests pass natively and on wasm32. Thanks!

Glad to hear it worked for you. I hope that this PR will be approved by the maintainer soon.
Cheers! 🍻

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

luau feature fails to compile for wasm32-unknown-unknown (HeapDump uses libc stdio)

2 participants