Skip to content

Commit

Permalink
Merge pull request #21611 from alexrp/target-abi-default
Browse files Browse the repository at this point in the history
`std.Target`: Rewrite `Abi.default()` to have better defaults across the board.
  • Loading branch information
alexrp authored Oct 7, 2024
2 parents cc79cc9 + 221bd82 commit 20e03be
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 35 deletions.
129 changes: 95 additions & 34 deletions lib/std/Target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -701,50 +701,111 @@ pub const Abi = enum {
pub fn default(arch: Cpu.Arch, os: Os) Abi {
return if (arch.isWasm()) .musl else switch (os.tag) {
.freestanding,
.dragonfly,
.ps3,
.zos,
.rtems,
.aix,
.cuda,
.nvcl,
.amdhsa,
.ps4,
.ps5,
.elfiamcu,
.mesa3d,
.contiki,
.amdpal,
.hermit,
.other,
=> .eabi,
.openbsd,
.freebsd,
.fuchsia,
.netbsd,
.hurd,
.haiku,
.windows,
=> .gnu,
.uefi => .msvc,
=> switch (arch) {
// Soft float is usually a sane default for freestanding.
.arm,
.armeb,
.thumb,
.thumbeb,
.csky,
.mips,
.mipsel,
.powerpc,
.powerpcle,
=> .eabi,
else => .none,
},
.aix,
=> if (arch == .powerpc) .eabihf else .none,
.linux,
.wasi,
.emscripten,
=> .musl,
.bridgeos,
.opencl,
.opengl,
.vulkan,
.plan9, // TODO specify abi
.macos,
.rtems,
=> switch (arch) {
.arm,
.armeb,
.thumb,
.thumbeb,
.mips,
.mipsel,
=> .eabi,
.powerpc,
=> .eabihf,
else => .none,
},
.hurd,
.windows,
=> .gnu,
.freebsd,
=> switch (arch) {
.arm,
.armeb,
.thumb,
.thumbeb,
.powerpc,
=> .eabihf,
.mips,
.mipsel,
=> .eabi,
else => .none,
},
.netbsd,
=> switch (arch) {
.arm,
.armeb,
.thumb,
.thumbeb,
.powerpc,
=> .eabihf,
.mips,
.mipsel,
=> .eabi,
else => .none,
},
.openbsd,
=> switch (arch) {
.arm,
.thumb,
=> .eabi,
.powerpc,
=> .eabihf,
else => .none,
},
.ios,
=> if (arch == .x86_64) .macabi else .none,
.tvos,
.watchos,
.visionos,
=> if (arch == .x86_64) .simulator else .none,
.uefi,
=> .msvc,
.contiki,
.elfiamcu,
.fuchsia,
.hermit,
.haiku,
.plan9,
.serenity,
.zos,
.dragonfly,
.bridgeos,
.driverkit,
.solaris,
.macos,
.watchos,
.illumos,
.serenity,
.solaris,
.ps3,
.ps4,
.ps5,
.amdhsa,
.amdpal,
.cuda,
.mesa3d,
.nvcl,
.opencl,
.opengl,
.vulkan,
=> .none,
};
}
Expand Down
2 changes: 1 addition & 1 deletion test/llvm_targets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const targets = [_]std.Target.Query{
.{ .cpu_arch = .nvptx64, .os_tag = .cuda, .abi = .none },
.{ .cpu_arch = .nvptx64, .os_tag = .nvcl, .abi = .none },

.{ .cpu_arch = .powerpc, .os_tag = .aix, .abi = .eabi },
.{ .cpu_arch = .powerpc, .os_tag = .aix, .abi = .eabihf },
.{ .cpu_arch = .powerpc, .os_tag = .freebsd, .abi = .eabi },
.{ .cpu_arch = .powerpc, .os_tag = .freebsd, .abi = .eabihf },
.{ .cpu_arch = .powerpc, .os_tag = .freestanding, .abi = .eabi },
Expand Down

0 comments on commit 20e03be

Please sign in to comment.