From d61920d80e0e6d2c2a058c96d1b916c7300ddab5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 14 Aug 2026 20:23:50 -0700 Subject: [PATCH] lib-vt: disable logging in wasm release builds --- src/lib_vt.zig | 19 +++++++++---------- src/os/wasm/log.zig | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/lib_vt.zig b/src/lib_vt.zig index 66da515a8..3b66930f2 100644 --- a/src/lib_vt.zig +++ b/src/lib_vt.zig @@ -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). diff --git a/src/os/wasm/log.zig b/src/os/wasm/log.zig index faa885c6e..5c5a8f66c 100644 --- a/src/os/wasm/log.zig +++ b/src/os/wasm/log.zig @@ -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.