Skip to content

std.Build.Step.Options: handle std.log.Level and std.log.ScopeLevel #24196

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: master
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
37 changes: 37 additions & 0 deletions lib/std/Build/Step/Options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,36 @@ fn printType(options: *Options, out: anytype, comptime T: type, value: T, indent
}
return;
},
std.log.Level => {
if (name) |some| {
try out.print("pub const {}: @import(\"std\").log.Level = .{s};\n", .{
std.zig.fmtId(some),
@tagName(value),
});
} else {
try out.print(".{s},\n", .{@tagName(value)});
}
return;
},
std.log.ScopeLevel => {
if (name) |some| {
try out.print("pub const {}: @import(\"std\").log.ScopeLevel = ", .{std.zig.fmtId(some)});
}

try out.writeAll(".{\n");
try out.writeByteNTimes(' ', indent);
try out.print(" .scope = .{p_},\n", .{std.zig.fmtId(@tagName(value.scope))});
try out.writeByteNTimes(' ', indent);
try out.print(" .level = .{s},\n", .{@tagName(value.level)});

try out.writeByteNTimes(' ', indent);
if (name != null) {
try out.writeAll("};\n");
} else {
try out.writeAll("},\n");
}
return;
},
else => {},
}

Expand Down Expand Up @@ -572,6 +602,8 @@ test Options {
options.addOption(NestedStruct, "nested_struct", NestedStruct{
.normal_struct = .{ .hello = "bar" },
});
options.addOption(std.log.Level, "log_level", .warn);
options.addOption(std.log.ScopeLevel, "scope_level", .{ .scope = .a_scope, .level = .debug });

try std.testing.expectEqualStrings(
\\pub const option1: usize = 1;
Expand Down Expand Up @@ -640,6 +672,11 @@ test Options {
\\ },
\\ .normal_enum = .foo,
\\};
\\pub const log_level: @import("std").log.Level = .warn;
\\pub const scope_level: @import("std").log.ScopeLevel = .{
\\ .scope = .a_scope,
\\ .level = .debug,
\\};
\\
, options.contents.items);

Expand Down
Loading