authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-07-07 20:40:31+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-07-07 21:40:31+03:00
log6f17be063d37f5ecd9552479e65428a5c60d9152
treeea5072883e66ff72d591637c7e2ebd197b65f503
parent81bbefe9b837dc439a68458ca91d522c1c49b96b
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

std.log: give friendly error to freestanding users


2 files changed, 17 insertions(+), 5 deletions(-)

lib/std/log.zig+5-5
...@@ -156,11 +156,11 @@ pub fn defaultLog(...@@ -156,11 +156,11 @@ pub fn defaultLog(
156 comptime format: []const u8,156 comptime format: []const u8,
157 args: anytype,157 args: anytype,
158) void {158) void {
159 if (builtin.os.tag == .freestanding) {159 if (builtin.os.tag == .freestanding)
160 // On freestanding one must provide a log function; we do not have160 @compileError(
161 // any I/O configured.161 \\freestanding targets do not have I/O configured;
162 return;162 \\please provide at least an empty `log` function declaration
163 }163 );
164164
165 const level_txt = comptime message_level.asText();165 const level_txt = comptime message_level.asText();
166 const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";166 const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
test/standalone/issue_7030/main.zig+12
...@@ -1,5 +1,17 @@...@@ -1,5 +1,17 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn log(
4 comptime message_level: std.log.Level,
5 comptime scope: @Type(.EnumLiteral),
6 comptime format: []const u8,
7 args: anytype,
8) void {
9 _ = message_level;
10 _ = scope;
11 _ = format;
12 _ = args;
13}
14
3pub fn main() anyerror!void {15pub fn main() anyerror!void {
4 std.log.info("All your codebase are belong to us.", .{});16 std.log.info("All your codebase are belong to us.", .{});
5}17}