lib-vt: disable logging in wasm release builds

This commit is contained in:
Mitchell Hashimoto
2026-08-14 20:23:50 -07:00
parent d760ee96e5
commit d61920d80e
2 changed files with 25 additions and 10 deletions

View File

@@ -391,16 +391,15 @@ pub const std_options: std.Options = opts: {
var options: std.Options = .{};
if (builtin.target.cpu.arch.isWasm()) {
// Wasm builds we specifically want to optimize for space with small
// releases so we bump up to warn. Everything else acts pretty normal.
options.log_level = switch (builtin.mode) {
.Debug => .debug,
.ReleaseSmall => .warn,
else => .info,
};
// Wasm doesn't have access to stdio so we have a custom log function.
options.logFn = @import("os/wasm/log.zig").log;
// In non-debug modes, we want to ship effectively no logging
// warn and lower add ~200KB at the time of this comment.
if (builtin.mode == .Debug) {
options.log_level = .debug;
options.logFn = @import("os/wasm/log.zig").log;
} else {
options.log_level = .err;
options.logFn = @import("os/wasm/log.zig").noop;
}
} else if (terminal.options.c_abi) {
// For C ABI builds, use a custom log function that dispatches to an
// embedder-provided callback (or silently discards when none is set).

View File

@@ -4,6 +4,22 @@ const wasm = @import("../wasm.zig");
// Use the correct implementation
pub const log = Freestanding.log;
/// A log function that discards everything. Since the format string and
/// scope are comptime parameters, using this compiles out all logging
/// machinery: call sites, format strings, and the std.fmt code they
/// reference (~220KB in a ReleaseFast wasm build).
pub fn noop(
comptime level: std.log.Level,
comptime scope: @TypeOf(.EnumLiteral),
comptime format: []const u8,
args: anytype,
) void {
_ = level;
_ = scope;
_ = format;
_ = args;
}
/// Freestanding implementation calls an extern "log" function.
pub const Freestanding = struct {
// The function std.log will call.