diff --git a/lib/std/Build/Configuration.zig b/lib/std/Build/Configuration.zig index 031d7dc36e9b8456f8ee5609c4a881bd85c37ce0..f860fef0f5ad4d46435e0d7af01fb2e2980fe161 100644 --- a/lib/std/Build/Configuration.zig +++ b/lib/std/Build/Configuration.zig @@ -2618,6 +2618,7 @@ pub const TargetQuery = struct { uefi, @"3ds", wiiu, + @"switch", psx, ps3, ps4, @@ -2669,6 +2670,7 @@ pub const TargetQuery = struct { .uefi => .uefi, .@"3ds" => .@"3ds", .wiiu => .wiiu, + .@"switch" => .@"switch", .psx => .psx, .ps3 => .ps3, .ps4 => .ps4, @@ -2720,6 +2722,7 @@ pub const TargetQuery = struct { .uefi => .uefi, .@"3ds" => .@"3ds", .wiiu => .wiiu, + .@"switch" => .@"switch", .psx => .psx, .ps3 => .ps3, .ps4 => .ps4, diff --git a/lib/std/Target.zig b/lib/std/Target.zig index c12239aef1b1c06c21ebb0061c9c32fea0e12ff1..387f96d04b75c647832e946bfe1d2cacc5c78e15 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -50,6 +50,7 @@ pub const Os = struct { @"3ds", wiiu, + @"switch", psx, ps3, @@ -74,14 +75,6 @@ pub const Os = struct { ashetos, - // LLVM tags deliberately omitted: - // - bridgeos - // - cheriotrtos - // - darwin - // - kfreebsd - // - nacl - // - shadermodel - pub inline fn isDarwin(tag: Tag) bool { return switch (tag) { .driverkit, @@ -204,6 +197,7 @@ pub const Os = struct { .@"3ds", .wiiu, + .@"switch", .psp, .vita, @@ -640,6 +634,13 @@ pub const Os = struct { }, }, + .@"switch" => .{ + .semver = .{ + .min = .{ .major = 1, .minor = 0, .patch = 0 }, + .max = .{ .major = 22, .minor = 5, .patch = 0 }, + }, + }, + .psp => .{ .semver = .{ // https://www.psdevwiki.com/psp/Official_Firmware_(OFW)#1.XX_Kernel @@ -825,33 +826,6 @@ pub const Abi = enum { ohoseabi, call0, - // LLVM tags deliberately omitted: - // - amplification - // - anyhit - // - callable - // - closesthit - // - compute - // - coreclr - // - domain - // - geometry - // - gnueabit64 - // - gnueabihft64 - // - gnuf64 - // - gnut64 - // - hull - // - intersection - // - library - // - llvm - // - mesh - // - miss - // - mlibc - // - mtia - // - pauthtest - // - pixel - // - raygeneration - // - rootsignature - // - vertex - pub fn default(arch: Cpu.Arch, os_tag: Os.Tag) Abi { return switch (os_tag) { .freestanding, .other => switch (arch) { @@ -979,6 +953,7 @@ pub const Abi = enum { .tvos, .visionos, .watchos, + .@"switch", .ps3, .ps4, .ps5, @@ -1079,9 +1054,6 @@ pub const ObjectFormat = enum { /// The WebAssembly binary format. wasm, - // LLVM tags deliberately omitted: - // - dxcontainer - pub fn fileExt(of: ObjectFormat, arch: Cpu.Arch) [:0]const u8 { return switch (of) { .c => ".c", @@ -1439,24 +1411,6 @@ pub const Cpu = struct { xtensa, xtensaeb, - // LLVM tags deliberately omitted: - // - aarch64_32 - // - amdil - // - amdil64 - // - dxil - // - r600 - // - hsail - // - hsail64 - // - renderscript32 - // - renderscript64 - // - shave - // - sparcel - // - spir - // - spir64 - // - spirv - // - tce - // - tcele - /// An architecture family can encompass multiple architectures as represented by `Arch`. /// For a given family tag, it is guaranteed that an `std.Target.` namespace exists /// containing CPU model and feature data. @@ -2096,6 +2050,7 @@ pub const Cpu = struct { .ios, .tvos => &aarch64.cpu.apple_a7, .visionos => &aarch64.cpu.apple_m2, .watchos => &aarch64.cpu.apple_s4, + .@"switch" => &aarch64.cpu.cortex_a57, else => generic(arch), }, .avr => &avr.cpu.avr2, @@ -2327,8 +2282,9 @@ pub fn requiresLibC(target: *const Target) bool { .plan9, .other, .@"3ds", - .tios, .wiiu, + .@"switch", + .tios, .ashetos, => false, }; @@ -2477,6 +2433,7 @@ pub const DynamicLinker = struct { .@"3ds", .wiiu, + .@"switch", .emscripten, .wasi, @@ -2696,7 +2653,6 @@ pub const DynamicLinker = struct { .or1k, => |arch| if (abi == .gnu) initFmt("/lib/ld-linux-{s}.so.1", .{@tagName(arch)}) else none, - // TODO: `-be` architecture support. .csky => initFmt("/lib/ld-linux-cskyv2{s}.so.1", .{switch (abi) { .gnueabi => "", .gnueabihf => "-hf", @@ -2902,6 +2858,7 @@ pub const DynamicLinker = struct { .@"3ds", .wiiu, + .@"switch", .psx, .psp, @@ -3467,6 +3424,14 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 { .longlong, .ulonglong, .double, .longdouble => return 64, }, + .@"switch" => switch (c_type) { + .char => return 8, + .short, .ushort => return 16, + .int, .uint, .float => return 32, + .long, .ulong, .longlong, .ulonglong, .double => return 64, + .longdouble => return 128, + }, + .psx => switch (c_type) { .char => return 8, .short, .ushort => return 16, diff --git a/lib/std/debug.zig b/lib/std/debug.zig index a8475fdd456a1e604ada80e7f90157e05375cc88..819360ec28f296518e7eddc06d6f5f7a97c4c97a 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -511,6 +511,7 @@ pub fn defaultPanic(msg: []const u8, first_trace_addr: ?usize) noreturn { .@"3ds", .wiiu, + .@"switch", .psx, .psp, diff --git a/lib/std/start.zig b/lib/std/start.zig index 68785b47aed7f36f2bf9dcea941eb12657c7c203..bb1ed6c3962d384fc5271b15973adf3702b3eb2a 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -78,6 +78,7 @@ comptime { .@"3ds", .wiiu, + .@"switch", .psx, .psp, diff --git a/src/Compilation.zig b/src/Compilation.zig index b12ca8debea3793c0c019c95f4b4e4f902576782..3e3658021438b7aa518282c77c3d04bba3d269b9 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -6196,6 +6196,7 @@ fn addCommonCCArgs( // Homebrew targets without LLVM support; use communities's preferred macros. .@"3ds" => try argv.append("-D__3DS__"), .wiiu => try argv.append("-D__WIIU__"), + .@"switch" => try argv.append("-D__SWITCH__"), .psx => try argv.append("-D__psx__"), .psp => try argv.append("-D__PSP__"), .vita => try argv.append("-D__vita__"), diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index c485b15ede656e04bdb0908902452f310b5943e8..a93ac0853f5d579e053207a1bd535a178a6a6a88 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -239,7 +239,6 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8 .vulkan => "vulkan", .managarm => "managarm", - .@"3ds", .contiki, .freestanding, .opencl, // https://llvm.org/docs/SPIRVUsage.html#target-triples @@ -250,7 +249,9 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8 .psp, .vita, .tios, + .@"3ds", .wiiu, + .@"switch", .ashetos, => "unknown", }; diff --git a/src/target.zig b/src/target.zig index 08ac102764c104518d79119251b494ebaf09c5ea..f7e9e5581b34accbceaffc94ed5ef16ecf7bdd0d 100644 --- a/src/target.zig +++ b/src/target.zig @@ -62,9 +62,13 @@ pub fn libCxxNeedsLibUnwind(target: *const std.Target) bool { } pub fn requiresPie(target: *const std.Target, link_mode: std.lang.LinkMode) bool { - return target.os.tag == .fuchsia or - (target.abi.isAndroid() and link_mode == .dynamic) or - target.os.tag == .ashetos; + return switch (target.os.tag) { + .ashetos, + .fuchsia, + .@"switch", + => true, + else => target.abi.isAndroid() and link_mode == .dynamic, + }; } /// This function returns whether non-pic code is completely invalid on the given target. diff --git a/test/llvm_targets.zig b/test/llvm_targets.zig index cbbf4aff7d01adeb6cfbd22a51402f35759b1ea4..480adbcdafe6031de71b9ee42b8d9899c1faf72d 100644 --- a/test/llvm_targets.zig +++ b/test/llvm_targets.zig @@ -22,6 +22,7 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .aarch64, .os_tag = .openbsd, .abi = .none }, .{ .cpu_arch = .aarch64, .os_tag = .rtems, .abi = .none }, .{ .cpu_arch = .aarch64, .os_tag = .serenity, .abi = .none }, + .{ .cpu_arch = .aarch64, .os_tag = .@"switch", .abi = .none }, .{ .cpu_arch = .aarch64, .os_tag = .tvos, .abi = .none }, .{ .cpu_arch = .aarch64, .os_tag = .tvos, .abi = .simulator }, .{ .cpu_arch = .aarch64, .os_tag = .uefi, .abi = .none },