Skip to content

build.zig: pulled out the options to its own structs #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
60 changes: 32 additions & 28 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other zig-gamedev libs, and for more clarity, let's name this EmccDefaultFlagsOverrides.

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 => {
Expand Down Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again for clarity and consistency let's name this EmccDefaultSettingsOverrides

optimize: std.builtin.OptimizeMode,
emsdk_allocator: EmsdkAllocator = .emmalloc,
Copy link
Preview

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SettingsOptions struct is missing the shell_file field that was present in the original anonymous struct. This removes functionality that was previously available in the emccDefaultSettings function.

Suggested change
emsdk_allocator: EmsdkAllocator = .emmalloc,
emsdk_allocator: EmsdkAllocator = .emmalloc,
shell_file: ?[]const u8 = null,

Copilot uses AI. Check for mistakes.

};

pub fn emccDefaultSettings(allocator: std.mem.Allocator, options: SettingsOptions) EmccSettings {
var settings = EmccSettings.init(allocator);
switch (options.optimize) {
.Debug, .ReleaseSafe => {
Expand All @@ -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)});

Expand Down
Loading