From e4dc0ddc67053e915efd7489f19a68d0a3da8291 Mon Sep 17 00:00:00 2001 From: Rawan10101 Date: Mon, 2 Mar 2026 08:45:44 +0200 Subject: [PATCH] build: add Emscripten/WASM support The wasm build requires the Emscripten SDK to be available. Then the library can be built with something like: zig build -Dtarget=wasm32-emscripten --search-prefix $EMSDK/upstream/emscripten/cache/sysroot --- build.zig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/build.zig b/build.zig index 04846ea..5c62ff5 100644 --- a/build.zig +++ b/build.zig @@ -130,6 +130,18 @@ pub fn build(b: *std.Build) void { "uv/linux.h", ); }, + .emscripten => { + root_module.addCMacro("UV_PLATFORM_LOOP_FIELDS", "struct pollfd* poll_fds; size_t poll_fds_used; size_t poll_fds_size; unsigned char poll_fds_iterating;"); + root_module.addCSourceFiles(.{ + .root = src_root, + .files = emscripten_sources, + .flags = cflags, + }); + lib.installHeader( + include_root.path(b, "uv/posix.h"), + "uv/posix.h", + ); + }, .haiku => { root_module.addCMacro("_BSD_SOURCE", ""); root_module.linkSystemLibrary("bsd", .{}); @@ -440,6 +452,13 @@ const solaris_sources: []const []const u8 = &.{ "unix/sunos.c", }; +const emscripten_sources: []const []const u8 = &.{ + "unix/no-fsevents.c", + "unix/no-proctitle.c", + "unix/posix-hrtime.c", + "unix/posix-poll.c", +}; + const haiku_sources: []const []const u8 = &.{ "unix/haiku.c", "unix/bsd-ifaddrs.c",