Skip to content

Commit 87270de

Browse files
committed
refactor(build): remove verbose comments
- Remove lengthy comment blocks throughout build functions - Clean up unnecessary blank lines between code sections - Preserve core documentation in comments where needed
1 parent 5673495 commit 87270de

File tree

1 file changed

+2
-47
lines changed

1 file changed

+2
-47
lines changed

build.zig

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,28 @@ const Module = Build.Module;
77
const builtin = @import("builtin");
88
const current_zig = builtin.zig_version;
99

10-
// Minimum required Zig version for this project
1110
const min_zig_string = "0.12.0";
12-
// NOTE: we should note that when enable tls support we cannot compile with musl
13-
14-
// Compile-time check to ensure the Zig version meets the minimum requirement
11+
// NOTE: when enable tls support we cannot compile with musl
1512
comptime {
1613
const min_zig = std.SemanticVersion.parse(min_zig_string) catch unreachable;
1714
if (current_zig.order(min_zig) == .lt) {
1815
@compileError(std.fmt.comptimePrint("Your Zig version v{} does not meet the minimum build requirement of v{}", .{ current_zig, min_zig }));
1916
}
2017
}
2118

22-
// Define logger and useful type aliases
2319
const log = std.log.scoped(.WebUI);
24-
// Default build configuration options
2520
const default_isStatic = true;
2621
const default_enableTLS = false;
2722

2823
pub fn build(b: *Build) !void {
29-
// Parse command-line options or use defaults
3024
const isStatic = b.option(bool, "is_static", "whether lib is static") orelse default_isStatic;
3125
const enableTLS = b.option(bool, "enable_tls", "whether lib enable tls") orelse default_enableTLS;
3226
const enableWebUILog = b.option(bool, "enable_webui_log", "whether lib enable tls") orelse default_enableTLS;
3327

34-
// Standard build options for target and optimization
3528
const target = b.standardTargetOptions(.{});
3629
const optimize = b.standardOptimizeOption(.{});
3730

38-
// TLS support has some limitations
31+
// TLS does not support cross compilation
3932
if (enableTLS) {
4033
log.info("enable TLS support", .{});
4134
if (!target.query.isNative()) {
@@ -44,16 +37,9 @@ pub fn build(b: *Build) !void {
4437
}
4538
}
4639

47-
// Create build options that will be used as a module
4840
const flags_options = b.addOptions();
49-
50-
// Configure compile-time options
5141
flags_options.addOption(bool, "enableTLS", enableTLS);
52-
53-
// Create a module that exposes the options
5442
const flags_module = flags_options.createModule();
55-
56-
// Get the webui dependency with appropriate options
5743
const webui = b.dependency("webui", .{
5844
.target = target,
5945
.optimize = optimize,
@@ -62,8 +48,6 @@ pub fn build(b: *Build) !void {
6248
.@"enable-webui-log" = enableWebUILog,
6349
.verbose = .err,
6450
});
65-
66-
// Create the webui module that applications can import
6751
const webui_module = b.addModule("webui", .{
6852
.root_source_file = b.path(b.pathJoin(&.{ "src", "webui.zig" })),
6953
.imports = &.{
@@ -73,31 +57,23 @@ pub fn build(b: *Build) !void {
7357
},
7458
},
7559
});
76-
// Link against the webui library
7760
webui_module.linkLibrary(webui.artifact("webui"));
7861
if (!isStatic) {
79-
// For dynamic libraries, install the shared library
8062
b.installArtifact(webui.artifact("webui"));
8163
}
8264

83-
// Setup documentation generation
8465
generateDocs(b, optimize, target, flags_module);
8566

86-
// Create compatibility module for Zig version differences
8767
const compat_module = b.addModule("compat", .{
8868
.root_source_file = b.path(b.pathJoin(&.{ "examples", "compat.zig" })),
8969
});
90-
91-
// Build example applications
9270
buildExamples(b, optimize, target, webui_module, compat_module, webui.artifact("webui")) catch |err| {
9371
log.err("failed to build examples: {}", .{err});
9472
std.process.exit(1);
9573
};
9674
}
9775

98-
// Function to generate API documentation
9976
fn generateDocs(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget, flags_module: *Module) void {
100-
// Create a temporary object for documentation generation
10177
const webui_lib = b.addObject(if (builtin.zig_version.minor == 14) .{
10278
.name = "webui_lib",
10379
.root_source_file = b.path(b.pathJoin(&.{ "src", "webui.zig" })),
@@ -114,10 +90,7 @@ fn generateDocs(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget,
11490

11591
webui_lib.root_module.addImport("flags", flags_module);
11692

117-
// Create a build step for documentation
11893
const docs_step = b.step("docs", "Generate docs");
119-
120-
// Setup documentation installation
12194
const docs_install = b.addInstallDirectory(.{
12295
.source_dir = webui_lib.getEmittedDocs(),
12396
.install_dir = .prefix,
@@ -127,18 +100,10 @@ fn generateDocs(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget,
127100
docs_step.dependOn(&docs_install.step);
128101
}
129102

130-
// Function to build all example applications
131103
fn buildExamples(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget, webui_module: *Module, compat_module: *Module, webui_lib: *Compile) !void {
132-
133-
// Get the absolute path to the examples directory
134104
var lazy_path = b.path("examples");
135-
136-
// Create a step to build all examples
137105
const build_all_step = b.step("examples", "build all examples");
138-
139106
const examples_path = lazy_path.getPath(b);
140-
141-
// Open the examples directory for iteration
142107
var iter_dir = std.fs.openDirAbsolute(
143108
examples_path,
144109
.{ .iterate = true },
@@ -152,16 +117,13 @@ fn buildExamples(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget
152117

153118
var itera = iter_dir.iterate();
154119

155-
// Iterate through all subdirectories in the examples directory
156120
while (try itera.next()) |val| {
157121
if (val.kind != .directory) {
158122
continue;
159123
}
160124

161125
const example_name = val.name;
162126
const path = b.pathJoin(&.{ "examples", example_name, "main.zig" });
163-
164-
// Create an executable for each example
165127
const exe = b.addExecutable(if (builtin.zig_version.minor == 14) .{
166128
.name = example_name,
167129
.root_source_file = b.path(path),
@@ -176,25 +138,18 @@ fn buildExamples(b: *Build, optimize: OptimizeMode, target: Build.ResolvedTarget
176138
}),
177139
});
178140

179-
// Add the webui and compat modules and link against the library
180141
exe.root_module.addImport("webui", webui_module);
181142
exe.root_module.addImport("compat", compat_module);
182143
exe.linkLibrary(webui_lib);
183144

184-
// Setup installation
185145
const exe_install = b.addInstallArtifact(exe, .{});
186-
187146
build_all_step.dependOn(&exe_install.step);
188147

189-
// Create a run step for the example
190148
const exe_run = b.addRunArtifact(exe);
191149
exe_run.step.dependOn(&exe_install.step);
192150

193-
// Set the working directory for the run
194151
const cwd = b.path(b.pathJoin(&.{ "examples", example_name }));
195152
exe_run.setCwd(cwd);
196-
197-
// Create a named step to run this specific example
198153
const step_name = try std.fmt.allocPrint(b.allocator, "run_{s}", .{example_name});
199154
const step_desc = try std.fmt.allocPrint(b.allocator, "run_{s}", .{example_name});
200155

0 commit comments

Comments
 (0)