From dd3ca084640f794c59427a507686bbd9bec1ed6b Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Tue, 14 Oct 2025 22:23:59 -0500 Subject: Started work on emscripten, fixed single frame leak caused by infinite splits --- build.zig | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index a333a8a..b41b644 100644 --- a/build.zig +++ b/build.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const raylib = @import("raylib"); pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); @@ -11,6 +12,7 @@ pub fn build(b: *std.Build) !void { }); const raylib_artifact = raylib_zig.artifact("raylib"); + const zgui = b.dependency("zgui", .{ .shared = false, .with_implot = true, @@ -34,7 +36,6 @@ pub fn build(b: *std.Build) !void { .optimize = optimize, }), }); - // exe.linkLibCpp(); exe.linkLibrary(raylib_artifact); exe.linkLibrary(zgui.artifact("imgui")); exe.addIncludePath(zgui.path("libs/imgui")); @@ -61,6 +62,38 @@ pub fn build(b: *std.Build) !void { const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); + if (target.query.os_tag == .emscripten) { + const emsdk = raylib.emsdk; + const wasm = b.addLibrary(.{ + .name = "particle-sim-web", + .root_module = exe.root_module, + }); + + wasm.linkLibCpp(); + + const install_dir: std.Build.InstallDir = .{ .custom = "web" }; + const emcc_flags = emsdk.emccDefaultFlags(b.allocator, .{ .optimize = optimize }); + const emcc_settings = emsdk.emccDefaultSettings(b.allocator, .{ .optimize = optimize }); + + const emcc_step = emsdk.emccStep(b, raylib_artifact, wasm, .{ + .optimize = optimize, + .flags = emcc_flags, + .settings = emcc_settings, + .install_dir = install_dir, + }); + b.getInstallStep().dependOn(emcc_step); + + const html_filename = try std.fmt.allocPrint(b.allocator, "{s}.html", .{wasm.name}); + const emrun_step = emsdk.emrunStep( + b, + b.getInstallPath(install_dir, html_filename), + &.{}, + ); + + emrun_step.dependOn(emcc_step); + run_step.dependOn(emrun_step); + } + // const exe_unit_tests = b.addTest(.{ // .root_source_file = b.path("src/quad.zig"), // .target = target, -- cgit v1.2.3