diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2025-10-14 22:23:59 -0500 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2025-10-14 22:23:59 -0500 |
| commit | dd3ca084640f794c59427a507686bbd9bec1ed6b (patch) | |
| tree | 4524af0c7a857a923387c07d58794de6d34a6b19 /build.zig | |
| parent | ec2527a65c9609dc6098b55312a8286e30f9ba46 (diff) | |
| download | particle-sim-dd3ca084640f794c59427a507686bbd9bec1ed6b.tar.gz | |
Started work on emscripten, fixed single frame leak caused by infinite splits
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -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, |
