diff options
| author | Veikka Tuominen <git@vexu.eu> | 2023-01-03 19:37:11 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-01-05 02:31:29 -0700 |
| commit | f83834993e2628e347da71a11ffb07c804fc46c5 (patch) | |
| tree | 21fd10b3ba19c4236326549872a202a4ffe29b3f /src | |
| parent | fe2bd9dda8467b775da4fe3bd535aece9e07ee1b (diff) | |
| download | zig-f83834993e2628e347da71a11ffb07c804fc46c5.tar.gz zig-f83834993e2628e347da71a11ffb07c804fc46c5.zip | |
std: collect all options under one namespace
Diffstat (limited to 'src')
| -rw-r--r-- | src/crash_report.zig | 8 | ||||
| -rw-r--r-- | src/main.zig | 26 |
2 files changed, 19 insertions, 15 deletions
diff --git a/src/crash_report.zig b/src/crash_report.zig index ba08db8266..6f657a9e01 100644 --- a/src/crash_report.zig +++ b/src/crash_report.zig @@ -13,12 +13,10 @@ const Decl = Module.Decl; pub const is_enabled = builtin.mode == .Debug; -/// To use these crash report diagnostics, publish these symbols in your main file. +/// To use these crash report diagnostics, publish this panic in your main file +/// and add `pub const enable_segfault_handler = false;` to your `std_options`. /// You will also need to call initialize() on startup, preferably as the very first operation in your program. -pub const root_decls = struct { - pub const panic = if (is_enabled) compilerPanic else std.builtin.default_panic; - pub const enable_segfault_handler = false; -}; +pub const panic = if (is_enabled) compilerPanic else std.builtin.default_panic; /// Install signal handlers to identify crashes and report diagnostics. pub fn initialize() void { diff --git a/src/main.zig b/src/main.zig index 421164de1c..814e60f97a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -25,11 +25,23 @@ const target_util = @import("target.zig"); const ThreadPool = @import("ThreadPool.zig"); const crash_report = @import("crash_report.zig"); -// Crash report needs to override the panic handler and other root decls -pub usingnamespace crash_report.root_decls; +pub const std_options = struct { + pub const wasiCwd = wasi_cwd; + pub const logFn = log; + pub const enable_segfault_handler = false; + + pub const log_level: std.log.Level = switch (builtin.mode) { + .Debug => .debug, + .ReleaseSafe, .ReleaseFast => .info, + .ReleaseSmall => .err, + }; +}; + +// Crash report needs to override the panic handler +pub const panic = crash_report.panic; var wasi_preopens: fs.wasi.Preopens = undefined; -pub inline fn wasi_cwd() fs.Dir { +pub fn wasi_cwd() fs.Dir { // Expect the first preopen to be current working directory. const cwd_fd: std.os.fd_t = 3; assert(mem.eql(u8, wasi_preopens.names[cwd_fd], ".")); @@ -111,12 +123,6 @@ const debug_usage = normal_usage ++ const usage = if (debug_extensions_enabled) debug_usage else normal_usage; -pub const log_level: std.log.Level = switch (builtin.mode) { - .Debug => .debug, - .ReleaseSafe, .ReleaseFast => .info, - .ReleaseSmall => .err, -}; - var log_scopes: std.ArrayListUnmanaged([]const u8) = .{}; pub fn log( @@ -128,7 +134,7 @@ pub fn log( // Hide debug messages unless: // * logging enabled with `-Dlog`. // * the --debug-log arg for the scope has been provided - if (@enumToInt(level) > @enumToInt(std.log.level) or + if (@enumToInt(level) > @enumToInt(std.options.log_level) or @enumToInt(level) > @enumToInt(std.log.Level.info)) { if (!build_options.enable_logging) return; |
