Skip to content

Commit 6982287

Browse files
committed
fix(build): correct option handling and TLS validation
- Fix enableWebUILog default value from enableTLS - Correct enableWebUILog option description text - Refactor TLS cross-compilation validation logic - Improve TLS error message and use error log level - Reorganize option initialization order
1 parent 9c57695 commit 6982287

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

build.zig

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,31 @@ comptime {
2020
const log = std.log.scoped(.WebUI);
2121
const default_isStatic = true;
2222
const default_enableTLS = false;
23+
const default_enableWebUILog = false;
2324

2425
pub fn build(b: *Build) !void {
25-
const isStatic = b.option(bool, "is_static", "whether lib is static") orelse default_isStatic;
26-
const enableTLS = b.option(bool, "enable_tls", "whether lib enable tls") orelse default_enableTLS;
27-
const enableWebUILog = b.option(bool, "enable_webui_log", "whether lib enable tls") orelse default_enableTLS;
28-
2926
const target = b.standardTargetOptions(.{});
3027
const optimize = b.standardOptimizeOption(.{});
3128

32-
// TLS does not support cross compilation
29+
const isStatic = b.option(bool, "is_static", "whether lib is static") orelse default_isStatic;
30+
const enableTLS = b.option(bool, "enable_tls", "whether lib enable tls") orelse default_enableTLS;
31+
const enableWebUILog = b.option(bool, "enable_webui_log", "whether lib enable webui log") orelse default_enableWebUILog;
32+
3333
if (enableTLS) {
3434
log.info("enable TLS support", .{});
35-
if (!target.query.isNative()) {
36-
log.info("when enable tls, not support cross compile", .{});
37-
std.process.exit(1);
38-
}
35+
}
36+
37+
// TLS does not support cross compilation
38+
if (enableTLS and !target.query.isNative()) {
39+
log.err("TLS support is only available for native builds", .{});
40+
std.process.exit(1);
3941
}
4042

4143
const flags_options = b.addOptions();
4244
flags_options.addOption(bool, "enableTLS", enableTLS);
45+
4346
const flags_module = flags_options.createModule();
47+
4448
const webui = b.dependency("webui", .{
4549
.target = target,
4650
.optimize = optimize,
@@ -51,12 +55,10 @@ pub fn build(b: *Build) !void {
5155
});
5256
const webui_module = b.addModule("webui", .{
5357
.root_source_file = b.path(b.pathJoin(&.{ "src", "webui.zig" })),
54-
.imports = &.{
55-
.{
56-
.name = "flags",
57-
.module = flags_module,
58-
},
59-
},
58+
.imports = &.{ .{
59+
.name = "flags",
60+
.module = flags_module,
61+
} },
6062
});
6163
webui_module.linkLibrary(webui.artifact("webui"));
6264
if (!isStatic) {

0 commit comments

Comments
 (0)