From 7255f3e724d7f889c32c65481b27110ef48f077d Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Fri, 5 Jun 2026 08:35:05 +0900 Subject: [PATCH] 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. --- lib/std/debug.zig | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 2bf8d54d17dd913634d3ef58df5415e5d9d1bab5..ccbb38a1d6743ae0d099dac5e62ebbe6ab0c6d86 100644 --- 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. -- 2.54.0