diff --git a/build.zig b/build.zig index 00acafd..eb20733 100644 --- a/build.zig +++ b/build.zig @@ -151,7 +151,6 @@ pub const EmsdkAllocator = enum { pub const EmccDefaultSettingsOverrides = struct { optimize: std.builtin.OptimizeMode, emsdk_allocator: EmsdkAllocator = .emmalloc, - shell_file: ?[]const u8 = null, }; pub fn emccDefaultSettings(allocator: std.mem.Allocator, options: EmccDefaultSettingsOverrides) EmccSettings { @@ -182,6 +181,7 @@ pub const StepOptions = struct { embed_paths: ?[]const EmccFilePath = null, preload_paths: ?[]const EmccFilePath = null, shell_file_path: ?std.Build.LazyPath = null, + js_library_path: ?std.Build.LazyPath = null, out_file_name: ?[]const u8 = null, install_dir: std.Build.InstallDir, }; @@ -227,13 +227,9 @@ pub fn emccStep( } emcc.addArg("-o"); - const out_file = out_file: { - if (options.out_file_name) |out_file_name| { - break :out_file emcc.addOutputFileArg(out_file_name); - } else { - break :out_file emcc.addOutputFileArg(b.fmt("{s}.html", .{wasm.name})); - } - }; + const out_file = emcc.addOutputFileArg( + options.out_file_name orelse b.fmt("{s}.html", .{wasm.name}), + ); if (options.use_preload_plugins) { emcc.addArg("--use-preload-plugins"); @@ -273,6 +269,12 @@ pub fn emccStep( emcc.addFileInput(shell_file_path); } + if (options.js_library_path) |js_library_path| { + emcc.addArg("--js-library"); + emcc.addFileArg(js_library_path); + emcc.addFileInput(js_library_path); + } + const install_step = b.addInstallDirectory(.{ .source_dir = out_file.dirname(), .install_dir = options.install_dir, diff --git a/src/zemscripten.zig b/src/zemscripten.zig index f33a635..b3eabbc 100644 --- a/src/zemscripten.zig +++ b/src/zemscripten.zig @@ -11,7 +11,7 @@ pub extern fn emscripten_sleep(ms: u32) void; pub const MainLoopCallback = *const fn () callconv(.c) void; extern fn emscripten_set_main_loop(MainLoopCallback, c_int, c_int) void; pub fn setMainLoop(cb: MainLoopCallback, maybe_fps: ?i16, simulate_infinite_loop: bool) void { - emscripten_set_main_loop(cb, if (maybe_fps) |fps| fps else -1, @intFromBool(simulate_infinite_loop)); + emscripten_set_main_loop(cb, maybe_fps orelse -1, @intFromBool(simulate_infinite_loop)); } extern fn emscripten_cancel_main_loop() void; @@ -22,7 +22,7 @@ pub fn cancelMainLoop() void { pub const MainLoopArgCallback = *const fn (arg: *anyopaque) callconv(.c) void; extern fn emscripten_set_main_loop_arg(MainLoopArgCallback, arg: *anyopaque, c_int, c_int) void; pub fn setMainLoopArg(cb: MainLoopArgCallback, arg: *anyopaque, maybe_fps: ?i16, simulate_infinite_loop: bool) void { - emscripten_set_main_loop_arg(cb, arg, if (maybe_fps) |fps| fps else -1, @intFromBool(simulate_infinite_loop)); + emscripten_set_main_loop_arg(cb, arg, maybe_fps orelse -1, @intFromBool(simulate_infinite_loop)); } pub const AnimationFrameCallback = *const fn (f64, ?*anyopaque) callconv(.c) c_int; @@ -111,9 +111,8 @@ pub const EmmallocAllocator = struct { ) ?[*]u8 { _ = ctx; _ = return_address; - const ptr_align: u32 = @as(u32, 1) << @as(u5, @intFromEnum(ptr_align_log2)); - if (!std.math.isPowerOfTwo(ptr_align)) unreachable; - const ptr = emmalloc_memalign(ptr_align, len) orelse return null; + const ptr_align = ptr_align_log2.toByteUnits(); + const ptr = emmalloc_memalign(@intCast(ptr_align), @intCast(len)) orelse return null; return @ptrCast(ptr); } @@ -127,7 +126,7 @@ pub const EmmallocAllocator = struct { _ = ctx; _ = return_address; _ = buf_align_log2; - return emmalloc_realloc_try(buf.ptr, new_len) != null; + return emmalloc_realloc_try(buf.ptr, @intCast(new_len)) != null; } fn remap(