authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-07-07 18:45:59+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-07-07 18:45:59+02:00
log4e5ca9bc42a5f3f64e6b826553a5bf937e3ede91
treeb4bbe112805fccf4570d1a7256d355c176fc48b2
parent8219c86100b9679255ad06bf6a743716bef26102
parent164578636cfe760ab03f8f37f039ca7e5a0c801b

Merge pull request '`std.Target`: add `switch` (Nintendo Switch) Os tag' (#36081) from alexrp/zig:nintendo-switch-target into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36081

8 files changed, 39 insertions(+), 62 deletions(-)

lib/std/Build/Configuration.zig+3
......@@ -2618,6 +2618,7 @@ pub const TargetQuery = struct {
26182618 uefi,
26192619 @"3ds",
26202620 wiiu,
2621 @"switch",
26212622 psx,
26222623 ps3,
26232624 ps4,
......@@ -2669,6 +2670,7 @@ pub const TargetQuery = struct {
26692670 .uefi => .uefi,
26702671 .@"3ds" => .@"3ds",
26712672 .wiiu => .wiiu,
2673 .@"switch" => .@"switch",
26722674 .psx => .psx,
26732675 .ps3 => .ps3,
26742676 .ps4 => .ps4,
......@@ -2720,6 +2722,7 @@ pub const TargetQuery = struct {
27202722 .uefi => .uefi,
27212723 .@"3ds" => .@"3ds",
27222724 .wiiu => .wiiu,
2725 .@"switch" => .@"switch",
27232726 .psx => .psx,
27242727 .ps3 => .ps3,
27252728 .ps4 => .ps4,
lib/std/Target.zig+23-58
......@@ -50,6 +50,7 @@ pub const Os = struct {
5050
5151 @"3ds",
5252 wiiu,
53 @"switch",
5354
5455 psx,
5556 ps3,
......@@ -74,14 +75,6 @@ pub const Os = struct {
7475
7576 ashetos,
7677
77 // LLVM tags deliberately omitted:
78 // - bridgeos
79 // - cheriotrtos
80 // - darwin
81 // - kfreebsd
82 // - nacl
83 // - shadermodel
84
8578 pub inline fn isDarwin(tag: Tag) bool {
8679 return switch (tag) {
8780 .driverkit,
......@@ -204,6 +197,7 @@ pub const Os = struct {
204197
205198 .@"3ds",
206199 .wiiu,
200 .@"switch",
207201
208202 .psp,
209203 .vita,
......@@ -640,6 +634,13 @@ pub const Os = struct {
640634 },
641635 },
642636
637 .@"switch" => .{
638 .semver = .{
639 .min = .{ .major = 1, .minor = 0, .patch = 0 },
640 .max = .{ .major = 22, .minor = 5, .patch = 0 },
641 },
642 },
643
643644 .psp => .{
644645 .semver = .{
645646 // https://www.psdevwiki.com/psp/Official_Firmware_(OFW)#1.XX_Kernel
......@@ -825,33 +826,6 @@ pub const Abi = enum {
825826 ohoseabi,
826827 call0,
827828
828 // LLVM tags deliberately omitted:
829 // - amplification
830 // - anyhit
831 // - callable
832 // - closesthit
833 // - compute
834 // - coreclr
835 // - domain
836 // - geometry
837 // - gnueabit64
838 // - gnueabihft64
839 // - gnuf64
840 // - gnut64
841 // - hull
842 // - intersection
843 // - library
844 // - llvm
845 // - mesh
846 // - miss
847 // - mlibc
848 // - mtia
849 // - pauthtest
850 // - pixel
851 // - raygeneration
852 // - rootsignature
853 // - vertex
854
855829 pub fn default(arch: Cpu.Arch, os_tag: Os.Tag) Abi {
856830 return switch (os_tag) {
857831 .freestanding, .other => switch (arch) {
......@@ -979,6 +953,7 @@ pub const Abi = enum {
979953 .tvos,
980954 .visionos,
981955 .watchos,
956 .@"switch",
982957 .ps3,
983958 .ps4,
984959 .ps5,
......@@ -1079,9 +1054,6 @@ pub const ObjectFormat = enum {
10791054 /// The WebAssembly binary format.
10801055 wasm,
10811056
1082 // LLVM tags deliberately omitted:
1083 // - dxcontainer
1084
10851057 pub fn fileExt(of: ObjectFormat, arch: Cpu.Arch) [:0]const u8 {
10861058 return switch (of) {
10871059 .c => ".c",
......@@ -1439,24 +1411,6 @@ pub const Cpu = struct {
14391411 xtensa,
14401412 xtensaeb,
14411413
1442 // LLVM tags deliberately omitted:
1443 // - aarch64_32
1444 // - amdil
1445 // - amdil64
1446 // - dxil
1447 // - r600
1448 // - hsail
1449 // - hsail64
1450 // - renderscript32
1451 // - renderscript64
1452 // - shave
1453 // - sparcel
1454 // - spir
1455 // - spir64
1456 // - spirv
1457 // - tce
1458 // - tcele
1459
14601414 /// An architecture family can encompass multiple architectures as represented by `Arch`.
14611415 /// For a given family tag, it is guaranteed that an `std.Target.<tag>` namespace exists
14621416 /// containing CPU model and feature data.
......@@ -2096,6 +2050,7 @@ pub const Cpu = struct {
20962050 .ios, .tvos => &aarch64.cpu.apple_a7,
20972051 .visionos => &aarch64.cpu.apple_m2,
20982052 .watchos => &aarch64.cpu.apple_s4,
2053 .@"switch" => &aarch64.cpu.cortex_a57,
20992054 else => generic(arch),
21002055 },
21012056 .avr => &avr.cpu.avr2,
......@@ -2327,8 +2282,9 @@ pub fn requiresLibC(target: *const Target) bool {
23272282 .plan9,
23282283 .other,
23292284 .@"3ds",
2330 .tios,
23312285 .wiiu,
2286 .@"switch",
2287 .tios,
23322288 .ashetos,
23332289 => false,
23342290 };
......@@ -2477,6 +2433,7 @@ pub const DynamicLinker = struct {
24772433
24782434 .@"3ds",
24792435 .wiiu,
2436 .@"switch",
24802437
24812438 .emscripten,
24822439 .wasi,
......@@ -2696,7 +2653,6 @@ pub const DynamicLinker = struct {
26962653 .or1k,
26972654 => |arch| if (abi == .gnu) initFmt("/lib/ld-linux-{s}.so.1", .{@tagName(arch)}) else none,
26982655
2699 // TODO: `-be` architecture support.
27002656 .csky => initFmt("/lib/ld-linux-cskyv2{s}.so.1", .{switch (abi) {
27012657 .gnueabi => "",
27022658 .gnueabihf => "-hf",
......@@ -2902,6 +2858,7 @@ pub const DynamicLinker = struct {
29022858
29032859 .@"3ds",
29042860 .wiiu,
2861 .@"switch",
29052862
29062863 .psx,
29072864 .psp,
......@@ -3467,6 +3424,14 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 {
34673424 .longlong, .ulonglong, .double, .longdouble => return 64,
34683425 },
34693426
3427 .@"switch" => switch (c_type) {
3428 .char => return 8,
3429 .short, .ushort => return 16,
3430 .int, .uint, .float => return 32,
3431 .long, .ulong, .longlong, .ulonglong, .double => return 64,
3432 .longdouble => return 128,
3433 },
3434
34703435 .psx => switch (c_type) {
34713436 .char => return 8,
34723437 .short, .ushort => return 16,
lib/std/debug.zig+1
......@@ -511,6 +511,7 @@ pub fn defaultPanic(msg: []const u8, first_trace_addr: ?usize) noreturn {
511511
512512 .@"3ds",
513513 .wiiu,
514 .@"switch",
514515
515516 .psx,
516517 .psp,
lib/std/start.zig+1
......@@ -78,6 +78,7 @@ comptime {
7878
7979 .@"3ds",
8080 .wiiu,
81 .@"switch",
8182
8283 .psx,
8384 .psp,
src/Compilation.zig+1
......@@ -6196,6 +6196,7 @@ fn addCommonCCArgs(
61966196 // Homebrew targets without LLVM support; use communities's preferred macros.
61976197 .@"3ds" => try argv.append("-D__3DS__"),
61986198 .wiiu => try argv.append("-D__WIIU__"),
6199 .@"switch" => try argv.append("-D__SWITCH__"),
61996200 .psx => try argv.append("-D__psx__"),
62006201 .psp => try argv.append("-D__PSP__"),
62016202 .vita => try argv.append("-D__vita__"),
src/codegen/llvm.zig+2-1
......@@ -239,7 +239,6 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8
239239 .vulkan => "vulkan",
240240 .managarm => "managarm",
241241
242 .@"3ds",
243242 .contiki,
244243 .freestanding,
245244 .opencl, // https://llvm.org/docs/SPIRVUsage.html#target-triples
......@@ -250,7 +249,9 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8
250249 .psp,
251250 .vita,
252251 .tios,
252 .@"3ds",
253253 .wiiu,
254 .@"switch",
254255 .ashetos,
255256 => "unknown",
256257 };
src/target.zig+7-3
......@@ -62,9 +62,13 @@ pub fn libCxxNeedsLibUnwind(target: *const std.Target) bool {
6262}
6363
6464pub fn requiresPie(target: *const std.Target, link_mode: std.lang.LinkMode) bool {
65 return target.os.tag == .fuchsia or
66 (target.abi.isAndroid() and link_mode == .dynamic) or
67 target.os.tag == .ashetos;
65 return switch (target.os.tag) {
66 .ashetos,
67 .fuchsia,
68 .@"switch",
69 => true,
70 else => target.abi.isAndroid() and link_mode == .dynamic,
71 };
6872}
6973
7074/// This function returns whether non-pic code is completely invalid on the given target.
test/llvm_targets.zig+1
......@@ -22,6 +22,7 @@ const targets = [_]std.Target.Query{
2222 .{ .cpu_arch = .aarch64, .os_tag = .openbsd, .abi = .none },
2323 .{ .cpu_arch = .aarch64, .os_tag = .rtems, .abi = .none },
2424 .{ .cpu_arch = .aarch64, .os_tag = .serenity, .abi = .none },
25 .{ .cpu_arch = .aarch64, .os_tag = .@"switch", .abi = .none },
2526 .{ .cpu_arch = .aarch64, .os_tag = .tvos, .abi = .none },
2627 .{ .cpu_arch = .aarch64, .os_tag = .tvos, .abi = .simulator },
2728 .{ .cpu_arch = .aarch64, .os_tag = .uefi, .abi = .none },