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
This commit is contained in:
Rawan10101
2026-03-02 08:45:44 +02:00
committed by torque
parent dd606c7686
commit e4dc0ddc67

View File

@@ -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",