zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 7c1236e267e536379f8b91148117fb0b8e965334 (tree)
parent 9aee45be97020e65a3eaca67f7a343823a3439f5
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon, 22 Dec 2025 16:10:43 -0800

std: different way of doing some options

to avoid dependency loops

Diffstat:
Mlib/std/Io/File.zig | 2+-
Mlib/std/Thread.zig | 2+-
Mlib/std/debug.zig | 10+++++-----
Mlib/std/dynamic_library.zig | 2+-
Mlib/std/start.zig | 4++--
Mlib/std/std.zig | 14+++++++-------
6 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/lib/std/Io/File.zig b/lib/std/Io/File.zig @@ -389,7 +389,7 @@ pub fn setOwner(file: File, io: Io, owner: ?Uid, group: ?Gid) SetOwnerError!void /// Cross-platform representation of permissions on a file. /// /// On POSIX systems this corresponds to "mode" and on Windows this corresponds to "attributes". -pub const Permissions = if (is_windows) enum(std.os.windows.DWORD) { +pub const Permissions = std.Options.FilePermissions orelse if (is_windows) enum(std.os.windows.DWORD) { default_file = 0, _, diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig @@ -322,7 +322,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co var buf: [32]u8 = undefined; const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()}); - const io = std.options.debug_io; + const io = std.Options.debug_io; const file = try Io.Dir.cwd().openFile(io, path, .{}); defer file.close(io); diff --git a/lib/std/debug.zig b/lib/std/debug.zig @@ -280,7 +280,7 @@ pub const sys_can_stack_trace = switch (builtin.cpu.arch) { /// Alternatively, use the higher-level `Io.lockStderr` to integrate with the /// application's chosen `Io` implementation. pub fn lockStderr(buffer: []u8) Io.LockedStderr { - const io = std.options.debug_io; + const io = std.Options.debug_io; const prev = io.swapCancelProtection(.blocked); defer _ = io.swapCancelProtection(prev); return io.lockStderr(buffer, null) catch |err| switch (err) { @@ -289,7 +289,7 @@ pub fn lockStderr(buffer: []u8) Io.LockedStderr { } pub fn unlockStderr() void { - const io = std.options.debug_io; + const io = std.Options.debug_io; io.unlockStderr(); } @@ -623,7 +623,7 @@ pub noinline fn captureCurrentStackTrace(options: StackUnwindOptions, addr_buf: defer it.deinit(); if (!it.stratOk(options.allow_unsafe_unwind)) return empty_trace; - const io = std.options.debug_io; + const io = std.Options.debug_io; var total_frames: usize = 0; var index: usize = 0; @@ -685,7 +685,7 @@ pub noinline fn writeCurrentStackTrace(options: StackUnwindOptions, t: Io.Termin var total_frames: usize = 0; var wait_for = options.first_address; var printed_any_frame = false; - const io = std.options.debug_io; + const io = std.Options.debug_io; while (true) switch (it.next(io)) { .switch_to_fp => |unwind_error| { switch (StackIterator.fp_usability) { @@ -793,7 +793,7 @@ pub fn writeStackTrace(st: *const StackTrace, t: Io.Terminal) Writer.Error!void return; }, }; - const io = std.options.debug_io; + const io = std.Options.debug_io; const captured_frames = @min(n_frames, st.instruction_addresses.len); for (st.instruction_addresses[0..captured_frames]) |ret_addr| { // `ret_addr` is the return address, which is *after* the function call. diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig @@ -222,7 +222,7 @@ pub const ElfDynLib = struct { /// Trusts the file. Malicious file will be able to execute arbitrary code. pub fn open(path: []const u8) Error!ElfDynLib { - const io = std.options.debug_io; + const io = std.Options.debug_io; const fd = try resolveFromName(io, path); defer posix.close(fd); diff --git a/lib/std/start.zig b/lib/std/start.zig @@ -669,7 +669,7 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 { std.os.argv = argv[0..argc]; std.os.environ = envp; - if (std.io_options.debug_threaded_io) |t| { + if (std.Options.debug_threaded_io) |t| { if (@sizeOf(std.Io.Threaded.Argv0) != 0) t.argv0.value = argv[0]; t.environ = .{ .block = envp }; } @@ -698,7 +698,7 @@ fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.c) c_int { std.os.argv = @as([*][*:0]u8, @ptrCast(c_argv))[0..@intCast(c_argc)]; if (@sizeOf(std.Io.Threaded.Argv0) != 0) { - if (std.io_options.debug_threaded_io) |t| t.argv0.value = std.os.argv[0]; + if (std.Options.debug_threaded_io) |t| t.argv0.value = std.os.argv[0]; } return callMain(); diff --git a/lib/std/std.zig b/lib/std/std.zig @@ -110,9 +110,6 @@ const root = @import("root"); /// 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, @@ -177,6 +174,10 @@ 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, + pub const debug_threaded_io: ?*Io.Threaded = if (@hasDecl(root, "std_options_debug_threaded_io")) + root.std_options_debug_threaded_io + else + Io.Threaded.global_single_threaded; /// 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 @@ -186,11 +187,10 @@ pub const Options = struct { /// 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 debug_io: Io = if (@hasDecl(root, "std_options_debug_io")) root.std_options_debug_io else debug_threaded_io.?.ioBasic(); -pub const IoOptions = struct { - debug_threaded_io: ?*Io.Threaded = Io.Threaded.global_single_threaded, + /// Overrides `std.Io.File.Permissions`. + pub const FilePermissions: ?type = if (@hasDecl(root, "std_options_FilePermissions")) root.std_options_FilePermissions else null; }; // This forces the start.zig file to be imported, and the comptime logic inside that