Commit 6f17be063d

r00ster91 <r00ster91@proton.me>
2022-07-07 20:40:31
std.log: give friendly error to freestanding users
1 parent 81bbefe
Changed files (2)
lib
test
standalone
issue_7030
lib/std/log.zig
@@ -156,11 +156,11 @@ pub fn defaultLog(
     comptime format: []const u8,
     args: anytype,
 ) void {
-    if (builtin.os.tag == .freestanding) {
-        // On freestanding one must provide a log function; we do not have
-        // any I/O configured.
-        return;
-    }
+    if (builtin.os.tag == .freestanding)
+        @compileError(
+            \\freestanding targets do not have I/O configured;
+            \\please provide at least an empty `log` function declaration
+        );
 
     const level_txt = comptime message_level.asText();
     const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
test/standalone/issue_7030/main.zig
@@ -1,5 +1,17 @@
 const std = @import("std");
 
+pub fn log(
+    comptime message_level: std.log.Level,
+    comptime scope: @Type(.EnumLiteral),
+    comptime format: []const u8,
+    args: anytype,
+) void {
+    _ = message_level;
+    _ = scope;
+    _ = format;
+    _ = args;
+}
+
 pub fn main() anyerror!void {
     std.log.info("All your codebase are belong to us.", .{});
 }