diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-12-22 14:37:41 -0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-12-23 22:15:12 -0800 |
| commit | 3c2f5adf41f0e75fd5e8f6661891dd7d4fa770a9 (patch) | |
| tree | 5ae7765b93dfde9f5638b83ba2436fbbdd0da24d /lib/std/std.zig | |
| parent | 86e9e32cf0d5a028d6ebb32f8d0f3d0a23e717b6 (diff) | |
| download | zig-3c2f5adf41f0e75fd5e8f6661891dd7d4fa770a9.tar.gz zig-3c2f5adf41f0e75fd5e8f6661891dd7d4fa770a9.zip | |
std: integrate Io.Threaded with environment variables
* std.option allows overriding the debug Io instance
* if the default is used, start code initializes environ and argv0
also fix some places that needed recancel(), thanks mlugg!
See #30562
Diffstat (limited to 'lib/std/std.zig')
| -rw-r--r-- | lib/std/std.zig | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/std/std.zig b/lib/std/std.zig index 1690c0575c..46f6415d09 100644 --- a/lib/std/std.zig +++ b/lib/std/std.zig @@ -108,8 +108,11 @@ pub const start = @import("start.zig"); const root = @import("root"); -/// Stdlib-wide options that can be overridden by the root file. +/// Compile-time known settings overridable by the root source file. pub const options: Options = if (@hasDecl(root, "std_options")) root.std_options else .{}; +/// Minimal set of `options` moved here to avoid dependency loop compilation +/// errors. +pub const io_options: IoOptions = if (@hasDecl(root, "std_io_options")) root.std_io_options else .{}; pub const Options = struct { enable_segfault_handler: bool = debug.default_enable_segfault_handler, @@ -174,8 +177,22 @@ pub const Options = struct { /// stack traces will just print an error to the relevant `Io.Writer` and return. allow_stack_tracing: bool = !@import("builtin").strip_debug_info, + /// The `Io` instance that `std.debug` uses for `std.debug.print`, + /// capturing stack traces, loading debug info, finding the executable's + /// own path, and environment variables that affect terminal mode + /// detection. The default is to use statically initialized singleton that + /// is independent from the application's `Io` instance in order to make + /// debugging more straightforward. For example, while debugging an `Io` + /// implementation based on coroutines, one likely wants `std.debug.print` + /// to directly write to stderr without trying to interact with the code + /// being debugged. + debug_io: Io = io_options.debug_threaded_io.?.ioBasic(), +}; + +pub const IoOptions = struct { /// Overrides `std.Io.File.Permissions`. FilePermissions: ?type = null, + debug_threaded_io: ?*Io.Threaded = Io.Threaded.global_single_threaded, }; // This forces the start.zig file to be imported, and the comptime logic inside that |
