Skip to content

Commit 723cd6e

Browse files
committed
refactor(build): extract buildExamples options
- Create BuildExamplesOptions struct to hold parameters - Update buildExamples function to accept options struct - Replace direct parameter references with options fields
1 parent 619ac91 commit 723cd6e

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

build.zig

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,26 @@ pub fn build(b: *Build) !void {
6464

6565
const compat_module = b.addModule("compat", .{ .root_source_file = b.path(b.pathJoin(&.{ "examples", "compat.zig" })) });
6666

67-
buildExamples(b, optimize, target, webui_module, compat_module) catch |err| {
67+
buildExamples(b, .{
68+
.optimize = optimize,
69+
.target = target,
70+
.webui_module = webui_module,
71+
.compat_module = compat_module,
72+
}) catch |err| {
6873
log.err("failed to build examples: {}", .{err});
6974
std.process.exit(1);
7075
};
7176

7277
generateDocs(b, optimize, target, flags_module);
7378
}
7479

80+
const BuildExamplesOptions = struct {
81+
optimize: OptimizeMode,
82+
target: Build.ResolvedTarget,
83+
webui_module: *Module,
84+
compat_module: *Module,
85+
};
86+
7587
fn generateDocs(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget, flags_module: *Module) void {
7688
const webui_lib = b.addObject(if (builtin.zig_version.minor == 14) .{
7789
.name = "webui_lib",
@@ -99,13 +111,7 @@ fn generateDocs(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget,
99111
docs_step.dependOn(&docs_install.step);
100112
}
101113

102-
fn buildExamples(
103-
b: *Build,
104-
optimize: OptimizeMode,
105-
target: Build.ResolvedTarget,
106-
webui_module: *Module,
107-
compat_module: *Module,
108-
) !void {
114+
fn buildExamples(b: *Build, options: BuildExamplesOptions) !void {
109115
var lazy_path = b.path("examples");
110116
const build_all_step = b.step("examples", "build all examples");
111117
const examples_path = lazy_path.getPath(b);
@@ -132,19 +138,19 @@ fn buildExamples(
132138
const exe = b.addExecutable(if (builtin.zig_version.minor == 14) .{
133139
.name = example_name,
134140
.root_source_file = b.path(path),
135-
.target = target,
136-
.optimize = optimize,
141+
.target = options.target,
142+
.optimize = options.optimize,
137143
} else .{
138144
.name = example_name,
139145
.root_module = b.addModule(example_name, .{
140146
.root_source_file = b.path(path),
141-
.target = target,
142-
.optimize = optimize,
147+
.target = options.target,
148+
.optimize = options.optimize,
143149
}),
144150
});
145151

146-
exe.root_module.addImport("webui", webui_module);
147-
exe.root_module.addImport("compat", compat_module);
152+
exe.root_module.addImport("webui", options.webui_module);
153+
exe.root_module.addImport("compat", options.compat_module);
148154

149155
const exe_install = b.addInstallArtifact(exe, .{});
150156
build_all_step.dependOn(&exe_install.step);

0 commit comments

Comments
 (0)