From cbfbdf16101fd574a2496973178fdfa4fe82072b Mon Sep 17 00:00:00 2001 From: HaxSam Date: Sun, 6 Jul 2025 20:56:12 +0200 Subject: [PATCH] build.zig: pulled out the options to its own structs --- build.zig | 60 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/build.zig b/build.zig index ce8c82d..3aafad9 100644 --- a/build.zig +++ b/build.zig @@ -120,10 +120,12 @@ pub fn activateEmsdkStep(b: *std.Build) *std.Build.Step { pub const EmccFlags = std.StringHashMap(void); -pub fn emccDefaultFlags(allocator: std.mem.Allocator, options: struct { +pub const FlagsOptions = struct { optimize: std.builtin.OptimizeMode, fsanitize: bool, -}) EmccFlags { +}; + +pub fn emccDefaultFlags(allocator: std.mem.Allocator, options: FlagsOptions) EmccFlags { var args = EmccFlags.init(allocator); switch (options.optimize) { .Debug => { @@ -151,22 +153,22 @@ pub fn emccDefaultFlags(allocator: std.mem.Allocator, options: struct { pub const EmccSettings = std.StringHashMap([]const u8); -pub fn emccDefaultSettings( - allocator: std.mem.Allocator, - options: struct { - optimize: std.builtin.OptimizeMode, - emsdk_allocator: enum { - none, - dlmalloc, - emmalloc, - @"emmalloc-debug", - @"emmalloc-memvalidate", - @"emmalloc-verbose", - mimalloc, - } = .emmalloc, - shell_file: ?[]const u8 = null, - }, -) EmccSettings { +pub const EmsdkAllocator = enum { + none, + dlmalloc, + emmalloc, + @"emmalloc-debug", + @"emmalloc-memvalidate", + @"emmalloc-verbose", + mimalloc, +}; + +pub const SettingsOptions = struct { + optimize: std.builtin.OptimizeMode, + emsdk_allocator: EmsdkAllocator = .emmalloc, +}; + +pub fn emccDefaultSettings(allocator: std.mem.Allocator, options: SettingsOptions) EmccSettings { var settings = EmccSettings.init(allocator); switch (options.optimize) { .Debug, .ReleaseSafe => { @@ -186,19 +188,21 @@ pub const EmccFilePath = struct { virtual_path: ?[]const u8 = null, }; +pub const StepOptions = struct { + optimize: std.builtin.OptimizeMode, + flags: EmccFlags, + settings: EmccSettings, + use_preload_plugins: bool = false, + embed_paths: ?[]const EmccFilePath = null, + preload_paths: ?[]const EmccFilePath = null, + shell_file_path: ?[]const u8 = null, + install_dir: std.Build.InstallDir, +}; + pub fn emccStep( b: *std.Build, wasm: *std.Build.Step.Compile, - options: struct { - optimize: std.builtin.OptimizeMode, - flags: EmccFlags, - settings: EmccSettings, - use_preload_plugins: bool = false, - embed_paths: ?[]const EmccFilePath = null, - preload_paths: ?[]const EmccFilePath = null, - shell_file_path: ?[]const u8 = null, - install_dir: std.Build.InstallDir, - }, + options: StepOptions, ) *std.Build.Step { var emcc = b.addSystemCommand(&.{emccPath(b)});