Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/zemscripten.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -111,9 +111,9 @@ pub const EmmallocAllocator = struct {
) ?[*]u8 {
_ = ctx;
_ = return_address;
const ptr_align: u32 = @as(u32, 1) << @as(u5, @intFromEnum(ptr_align_log2));
const ptr_align: u32 = @as(u32, 1) << @intCast(@intFromEnum(ptr_align_log2));
if (!std.math.isPowerOfTwo(ptr_align)) unreachable;
const ptr = emmalloc_memalign(ptr_align, len) orelse return null;
const ptr = emmalloc_memalign(ptr_align, @intCast(len)) orelse return null;
return @ptrCast(ptr);
}

Expand All @@ -127,7 +127,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(
Expand Down
Loading