Skip to content

fix: guard libuv symbols in io.cpp for Emscripten WASM builds (#6817)#13298

Open
kjsdesigns wants to merge 1 commit intoleanprover:masterfrom
kjsdesigns:wasm-libuv-symbol-leakage
Open

fix: guard libuv symbols in io.cpp for Emscripten WASM builds (#6817)#13298
kjsdesigns wants to merge 1 commit intoleanprover:masterfrom
kjsdesigns:wasm-libuv-symbol-leakage

Conversation

@kjsdesigns
Copy link
Copy Markdown
Contributor

@kjsdesigns kjsdesigns commented Apr 7, 2026

This PR guards libuv symbols in src/runtime/io.cpp behind #if defined(LEAN_EMSCRIPTEN) to fix unresolved references to uv_strerror, uv_os_tmpdir, uv_fs_mkstemp, and uv_fs_mkdtemp in the linux_wasm32 libleanrt.a release artifact (issue #6817).

Details

Adds #if defined(LEAN_EMSCRIPTEN) guards following the same pattern already used in src/runtime/uv/dns.cpp (PR #9258):

  • lean_decode_uv_error: provides a numeric fallback error string ("libuv error %d") instead of calling uv_strerror. The rest of the function (error classification via UV_* constants from uv.h) is unchanged and works without linking libuv.
  • lean_io_create_tempfile: returns an unsupported operation error in Emscripten (no filesystem temp directory in browser WASM).
  • lean_io_create_tempdir: same treatment as createTempFile.

How I know it works

I've been using an equivalent patch in a production project that builds a Lean module to WASM via Emscripten since v4.27.0. The fix eliminates the 4 unresolved symbols without affecting any other code paths.

Context

Discussed on Zulip: #lean4 > WASM build fixes: libuv symbol leakage (#6817) and unique_lock

Closes #6817

The linux_wasm32 libleanrt.a release artifact contains unresolved
references to uv_strerror, uv_os_tmpdir, uv_fs_mkstemp, and
uv_fs_mkdtemp (issue leanprover#6817). These symbols are called from
lean_decode_uv_error, lean_io_create_tempfile, and
lean_io_create_tempdir, which are compiled into the WASM artifact
even though they cannot function in a browser environment.

This commit adds #if defined(LEAN_EMSCRIPTEN) guards following the
same pattern already used in src/runtime/uv/dns.cpp (PR leanprover#9258):

- lean_decode_uv_error: provides a numeric fallback error string
  instead of calling uv_strerror, since the rest of the function
  (error classification via UV_* constants) works without libuv
- lean_io_create_tempfile: returns unsupported operation error in
  Emscripten (no filesystem temp directory in browser WASM)
- lean_io_create_tempdir: same treatment as createTempFile

Discovered and proven in a production project that builds a Lean
module to WASM via Emscripten. The equivalent fix has been running
in production since Lean v4.27.0.

Closes leanprover#6817
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Apr 7, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 8bb07f336daea461f1187d6336fef77cfe790f9a --onto 0cd6dbaad297021c43b906ec247de446d056056f. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-07 10:27:14)

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 8bb07f336daea461f1187d6336fef77cfe790f9a --onto 861bc19e0c1c45b5766cc5c9ef0488568368b236. You can force reference manual CI using the force-manual-ci label. (2026-04-07 10:27:16)

@kjsdesigns
Copy link
Copy Markdown
Contributor Author

Could a maintainer please add the changelog-ffi label? This guards libuv symbols behind Emscripten preprocessor checks to fix unresolved references in the WASM build artifact.

I've also updated the PR body to follow the changelog convention (starts with "This PR ...").

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

Labels

toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linux_wasm32 libleanrt.a seems to incorrectly refer to libuv symbols

2 participants