zig

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

commit 7255f3e724d7f889c32c65481b27110ef48f077d (tree)
parent eedf7d92990676922ddbf1d2928d3d2a4d2e7487
Author: Jari Vetoniemi <jari.vetoniemi@cloudef.pw>
Date:   Fri,  5 Jun 2026 08:35:05 +0900

std.debug: add TargetInfo function which returns the default SelfInfo

If one overrides `SelfInfo` in their `root.debug`, it is no longer possible
to refer to the default `SelfInfo` that the std.debug uses.

This allows the developer to still refer to the std's default without
copying the SelfInfo zig files to their project.

Diffstat:
Mlib/std/debug.zig | 26++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/lib/std/debug.zig b/lib/std/debug.zig @@ -63,16 +63,22 @@ pub const cpu_context = @import("debug/cpu_context.zig"); /// ``` pub const SelfInfo = if (@hasDecl(root, "debug") and @hasDecl(root.debug, "SelfInfo")) root.debug.SelfInfo -else switch (std.Target.ObjectFormat.default(native_os, native_arch)) { - .coff => if (native_os == .windows) @import("debug/SelfInfo/Windows.zig") else void, - .elf => switch (native_os) { - .freestanding, .other => void, - else => @import("debug/SelfInfo/Elf.zig"), - }, - .macho => @import("debug/SelfInfo/MachO.zig"), - .plan9, .spirv, .wasm => void, - .c, .hex, .raw => unreachable, -}; +else + TargetInfo(native_os, native_arch); + +/// Returns the default `SelfInfo` for the given `os` and `arch`. +pub fn TargetInfo(os: std.Target.Os.Tag, arch: std.Target.Cpu.Arch) type { + return switch (std.Target.ObjectFormat.default(os, arch)) { + .coff => if (os == .windows) @import("debug/SelfInfo/Windows.zig") else void, + .elf => switch (os) { + .freestanding, .other => void, + else => @import("debug/SelfInfo/Elf.zig"), + }, + .macho => @import("debug/SelfInfo/MachO.zig"), + .plan9, .spirv, .wasm => void, + .c, .hex, .raw => unreachable, + }; +} pub const SelfInfoError = error{ /// The required debug info is invalid or corrupted.