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 {
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 {
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 => {
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