std.log: give friendly error to freestanding users

This commit is contained in:
r00ster91 2022-07-07 20:40:31 +02:00 committed by GitHub
parent 81bbefe9b8
commit 6f17be063d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -156,11 +156,11 @@ pub fn defaultLog(
comptime format: []const u8, comptime format: []const u8,
args: anytype, args: anytype,
) void { ) void {
if (builtin.os.tag == .freestanding) { if (builtin.os.tag == .freestanding)
// On freestanding one must provide a log function; we do not have @compileError(
// any I/O configured. \\freestanding targets do not have I/O configured;
return; \\please provide at least an empty `log` function declaration
} );
const level_txt = comptime message_level.asText(); const level_txt = comptime message_level.asText();
const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): "; const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";

View File

@ -1,5 +1,17 @@
const std = @import("std"); 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 { pub fn main() anyerror!void {
std.log.info("All your codebase are belong to us.", .{}); std.log.info("All your codebase are belong to us.", .{});
} }