Skip to content

Commit b732070

Browse files
authored
Merge pull request #22589 from alexrp/target-changes
Some miscellaneous target and calling convention changes
2 parents 55c4687 + faccd79 commit b732070

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+764
-747
lines changed

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ fn addCmakeCfgOptionsToExe(
742742
const mod = exe.root_module;
743743
const target = mod.resolved_target.?.result;
744744

745-
if (target.isDarwin()) {
745+
if (target.os.tag.isDarwin()) {
746746
// useful for package maintainers
747747
exe.headerpad_max_install_names = true;
748748
}

lib/compiler/aro/aro/Compilation.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void {
308308
),
309309
else => {},
310310
}
311-
if (comp.target.isAndroid()) {
311+
if (comp.target.abi.isAndroid()) {
312312
try w.writeAll("#define __ANDROID__ 1\n");
313313
}
314314

@@ -734,7 +734,7 @@ pub fn float80Type(comp: *const Compilation) ?Type {
734734

735735
/// Smallest integer type with at least N bits
736736
pub fn intLeastN(comp: *const Compilation, bits: usize, signedness: std.builtin.Signedness) Type {
737-
if (bits == 64 and (comp.target.isDarwin() or comp.target.isWasm())) {
737+
if (bits == 64 and (comp.target.os.tag.isDarwin() or comp.target.cpu.arch.isWasm())) {
738738
// WebAssembly and Darwin use `long long` for `int_least64_t` and `int_fast64_t`.
739739
return .{ .specifier = if (signedness == .signed) .long_long else .ulong_long };
740740
}

lib/compiler/aro/aro/Driver/GCCDetector.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn collectLibDirsAndTriples(
183183
// TODO
184184
return;
185185
}
186-
if (target.isAndroid()) {
186+
if (target.abi.isAndroid()) {
187187
const AArch64AndroidTriples: [1][]const u8 = .{"aarch64-linux-android"};
188188
const ARMAndroidTriples: [1][]const u8 = .{"arm-linux-androideabi"};
189189
const MIPSELAndroidTriples: [1][]const u8 = .{"mipsel-linux-android"};

lib/compiler/aro/aro/Toolchain.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {
161161
} else {
162162
var linker_name = try std.ArrayList(u8).initCapacity(tc.driver.comp.gpa, 5 + use_linker.len); // "ld64." ++ use_linker
163163
defer linker_name.deinit();
164-
if (tc.getTarget().isDarwin()) {
164+
if (tc.getTarget().os.tag.isDarwin()) {
165165
linker_name.appendSliceAssumeCapacity("ld64.");
166166
} else {
167167
linker_name.appendSliceAssumeCapacity("ld.");
@@ -343,7 +343,7 @@ pub fn buildLinkerArgs(tc: *Toolchain, argv: *std.ArrayList([]const u8)) !void {
343343
}
344344

345345
fn getDefaultRuntimeLibKind(tc: *const Toolchain) RuntimeLibKind {
346-
if (tc.getTarget().isAndroid()) {
346+
if (tc.getTarget().abi.isAndroid()) {
347347
return .compiler_rt;
348348
}
349349
return .libgcc;
@@ -369,7 +369,7 @@ pub fn getCompilerRt(tc: *const Toolchain, component: []const u8, file_kind: Fil
369369

370370
fn getLibGCCKind(tc: *const Toolchain) LibGCCKind {
371371
const target = tc.getTarget();
372-
if (tc.driver.static_libgcc or tc.driver.static or tc.driver.static_pie or target.isAndroid()) {
372+
if (tc.driver.static_libgcc or tc.driver.static or tc.driver.static_pie or target.abi.isAndroid()) {
373373
return .static;
374374
}
375375
if (tc.driver.shared_libgcc) {
@@ -384,7 +384,7 @@ fn getUnwindLibKind(tc: *const Toolchain) !UnwindLibKind {
384384
switch (tc.getRuntimeLibKind()) {
385385
.compiler_rt => {
386386
const target = tc.getTarget();
387-
if (target.isAndroid() or target.os.tag == .aix) {
387+
if (target.abi.isAndroid() or target.os.tag == .aix) {
388388
return .compiler_rt;
389389
} else {
390390
return .none;
@@ -417,14 +417,14 @@ fn getAsNeededOption(is_solaris: bool, needed: bool) []const u8 {
417417
fn addUnwindLibrary(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
418418
const unw = try tc.getUnwindLibKind();
419419
const target = tc.getTarget();
420-
if ((target.isAndroid() and unw == .libgcc) or
420+
if ((target.abi.isAndroid() and unw == .libgcc) or
421421
target.os.tag == .elfiamcu or
422422
target.ofmt == .wasm or
423423
target_util.isWindowsMSVCEnvironment(target) or
424424
unw == .none) return;
425425

426426
const lgk = tc.getLibGCCKind();
427-
const as_needed = lgk == .unspecified and !target.isAndroid() and !target_util.isCygwinMinGW(target) and target.os.tag != .aix;
427+
const as_needed = lgk == .unspecified and !target.abi.isAndroid() and !target_util.isCygwinMinGW(target) and target.os.tag != .aix;
428428
if (as_needed) {
429429
try argv.append(getAsNeededOption(target.os.tag == .solaris, true));
430430
}
@@ -483,7 +483,7 @@ pub fn addRuntimeLibs(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !v
483483
},
484484
}
485485

486-
if (target.isAndroid() and !tc.driver.static and !tc.driver.static_pie) {
486+
if (target.abi.isAndroid() and !tc.driver.static and !tc.driver.static_pie) {
487487
try argv.append("-ldl");
488488
}
489489
}

lib/compiler/aro/aro/Type.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ pub fn alignof(ty: Type, comp: *const Compilation) u29 {
11021102
.double => comp.target.cTypeAlignment(.double),
11031103
.long_double => comp.target.cTypeAlignment(.longdouble),
11041104

1105-
.int128, .uint128 => if (comp.target.cpu.arch == .s390x and comp.target.os.tag == .linux and comp.target.isGnu()) 8 else 16,
1105+
.int128, .uint128 => if (comp.target.cpu.arch == .s390x and comp.target.os.tag == .linux and comp.target.abi.isGnu()) 8 else 16,
11061106
.fp16, .float16 => 2,
11071107

11081108
.float128 => 16,

lib/compiler/aro/aro/target.zig

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ pub fn int64Type(target: std.Target) Type {
117117

118118
.sparc64 => return intMaxType(target),
119119

120-
.x86, .x86_64 => if (!target.isDarwin()) return intMaxType(target),
121-
.aarch64, .aarch64_be => if (!target.isDarwin() and target.os.tag != .openbsd and target.os.tag != .windows) return .{ .specifier = .long },
120+
.x86, .x86_64 => if (!target.os.tag.isDarwin()) return intMaxType(target),
121+
.aarch64, .aarch64_be => if (!target.os.tag.isDarwin() and target.os.tag != .openbsd and target.os.tag != .windows) return .{ .specifier = .long },
122122
else => {},
123123
}
124124
return .{ .specifier = .long_long };
@@ -144,7 +144,7 @@ pub fn defaultFunctionAlignment(target: std.Target) u8 {
144144
}
145145

146146
pub fn isTlsSupported(target: std.Target) bool {
147-
if (target.isDarwin()) {
147+
if (target.os.tag.isDarwin()) {
148148
var supported = false;
149149
switch (target.os.tag) {
150150
.macos => supported = !(target.os.isAtLeast(.macos, .{ .major = 10, .minor = 7, .patch = 0 }) orelse false),
@@ -199,7 +199,7 @@ pub fn minZeroWidthBitfieldAlignment(target: std.Target) ?u29 {
199199
pub fn unnamedFieldAffectsAlignment(target: std.Target) bool {
200200
switch (target.cpu.arch) {
201201
.aarch64 => {
202-
if (target.isDarwin() or target.os.tag == .windows) return false;
202+
if (target.os.tag.isDarwin() or target.os.tag == .windows) return false;
203203
return true;
204204
},
205205
.armeb => {
@@ -229,7 +229,7 @@ pub fn packAllEnums(target: std.Target) bool {
229229
pub fn defaultAlignment(target: std.Target) u29 {
230230
switch (target.cpu.arch) {
231231
.avr => return 1,
232-
.arm => if (target.isAndroid() or target.os.tag == .ios) return 16 else return 8,
232+
.arm => if (target.abi.isAndroid() or target.os.tag == .ios) return 16 else return 8,
233233
.sparc => if (std.Target.sparc.featureSetHas(target.cpu.features, .v9)) return 16 else return 8,
234234
.mips, .mipsel => switch (target.abi) {
235235
.none, .gnuabi64 => return 16,
@@ -242,9 +242,8 @@ pub fn defaultAlignment(target: std.Target) u29 {
242242
pub fn systemCompiler(target: std.Target) LangOpts.Compiler {
243243
// Android is linux but not gcc, so these checks go first
244244
// the rest for documentation as fn returns .clang
245-
if (target.isDarwin() or
246-
target.isAndroid() or
247-
target.isBSD() or
245+
if (target.abi.isAndroid() or
246+
target.os.tag.isBSD() or
248247
target.os.tag == .fuchsia or
249248
target.os.tag == .solaris or
250249
target.os.tag == .haiku or
@@ -268,7 +267,7 @@ pub fn systemCompiler(target: std.Target) LangOpts.Compiler {
268267

269268
pub fn hasFloat128(target: std.Target) bool {
270269
if (target.cpu.arch.isWasm()) return true;
271-
if (target.isDarwin()) return false;
270+
if (target.os.tag.isDarwin()) return false;
272271
if (target.cpu.arch.isPowerPC()) return std.Target.powerpc.featureSetHas(target.cpu.features, .float128);
273272
return switch (target.os.tag) {
274273
.dragonfly,
@@ -461,7 +460,6 @@ pub fn get32BitArchVariant(target: std.Target) ?std.Target {
461460
.amdgcn,
462461
.avr,
463462
.msp430,
464-
.spu_2,
465463
.ve,
466464
.bpfel,
467465
.bpfeb,
@@ -522,7 +520,6 @@ pub fn get64BitArchVariant(target: std.Target) ?std.Target {
522520
.lanai,
523521
.m68k,
524522
.msp430,
525-
.spu_2,
526523
.xcore,
527524
.xtensa,
528525
=> return null,
@@ -620,8 +617,6 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
620617
.wasm32 => "wasm32",
621618
.wasm64 => "wasm64",
622619
.ve => "ve",
623-
// Note: spu_2 is not supported in LLVM; this is the Zig arch name
624-
.spu_2 => "spu_2",
625620
};
626621
writer.writeAll(llvm_arch) catch unreachable;
627622
writer.writeByte('-') catch unreachable;

lib/compiler/aro/aro/toolchains/Linux.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn discover(self: *Linux, tc: *Toolchain) !void {
2727
fn buildExtraOpts(self: *Linux, tc: *const Toolchain) !void {
2828
const gpa = tc.driver.comp.gpa;
2929
const target = tc.getTarget();
30-
const is_android = target.isAndroid();
30+
const is_android = target.abi.isAndroid();
3131
if (self.distro.isAlpine() or is_android) {
3232
try self.extra_opts.ensureUnusedCapacity(gpa, 2);
3333
self.extra_opts.appendAssumeCapacity("-z");
@@ -113,7 +113,7 @@ fn findPaths(self: *Linux, tc: *Toolchain) !void {
113113
try tc.addPathIfExists(&.{ sysroot, "/lib", multiarch_triple }, .file);
114114
try tc.addPathIfExists(&.{ sysroot, "/lib", "..", os_lib_dir }, .file);
115115

116-
if (target.isAndroid()) {
116+
if (target.abi.isAndroid()) {
117117
// TODO
118118
}
119119
try tc.addPathIfExists(&.{ sysroot, "/usr", "lib", multiarch_triple }, .file);
@@ -156,7 +156,7 @@ fn getStatic(self: *const Linux, d: *const Driver) bool {
156156

157157
pub fn getDefaultLinker(self: *const Linux, target: std.Target) []const u8 {
158158
_ = self;
159-
if (target.isAndroid()) {
159+
if (target.abi.isAndroid()) {
160160
return "ld.lld";
161161
}
162162
return "ld";
@@ -169,7 +169,7 @@ pub fn buildLinkerArgs(self: *const Linux, tc: *const Toolchain, argv: *std.Arra
169169
const is_pie = self.getPIE(d);
170170
const is_static_pie = try self.getStaticPIE(d);
171171
const is_static = self.getStatic(d);
172-
const is_android = target.isAndroid();
172+
const is_android = target.abi.isAndroid();
173173
const is_iamcu = target.os.tag == .elfiamcu;
174174
const is_ve = target.cpu.arch == .ve;
175175
const has_crt_begin_end_files = target.abi != .none; // TODO: clang checks for MIPS vendor
@@ -326,7 +326,7 @@ pub fn buildLinkerArgs(self: *const Linux, tc: *const Toolchain, argv: *std.Arra
326326
}
327327

328328
fn getMultiarchTriple(target: std.Target) ?[]const u8 {
329-
const is_android = target.isAndroid();
329+
const is_android = target.abi.isAndroid();
330330
const is_mips_r6 = std.Target.mips.featureSetHas(target.cpu.features, .mips32r6);
331331
return switch (target.cpu.arch) {
332332
.arm, .thumb => if (is_android) "arm-linux-androideabi" else if (target.abi == .gnueabihf) "arm-linux-gnueabihf" else "arm-linux-gnueabi",
@@ -380,7 +380,7 @@ pub fn defineSystemIncludes(self: *const Linux, tc: *const Toolchain) !void {
380380

381381
// musl prefers /usr/include before builtin includes, so musl targets will add builtins
382382
// at the end of this function (unless disabled with nostdlibinc)
383-
if (!tc.driver.nobuiltininc and (!target.isMusl() or tc.driver.nostdlibinc)) {
383+
if (!tc.driver.nobuiltininc and (!target.abi.isMusl() or tc.driver.nostdlibinc)) {
384384
try comp.addBuiltinIncludeDir(tc.driver.aro_name);
385385
}
386386

@@ -411,7 +411,7 @@ pub fn defineSystemIncludes(self: *const Linux, tc: *const Toolchain) !void {
411411
try comp.addSystemIncludeDir("/usr/include");
412412

413413
std.debug.assert(!tc.driver.nostdlibinc);
414-
if (!tc.driver.nobuiltininc and target.isMusl()) {
414+
if (!tc.driver.nobuiltininc and target.abi.isMusl()) {
415415
try comp.addBuiltinIncludeDir(tc.driver.aro_name);
416416
}
417417
}

lib/compiler_rt/common.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ else
1414
/// For WebAssembly this allows the symbol to be resolved to other modules, but will not
1515
/// export it to the host runtime.
1616
pub const visibility: std.builtin.SymbolVisibility =
17-
if (builtin.target.isWasm() and linkage != .internal) .hidden else .default;
17+
if (builtin.target.cpu.arch.isWasm() and linkage != .internal) .hidden else .default;
1818

1919
pub const want_aeabi = switch (builtin.abi) {
2020
.eabi,
@@ -92,15 +92,15 @@ pub const panic = if (builtin.is_test) std.debug.FullPanic(std.debug.defaultPani
9292
pub fn F16T(comptime OtherType: type) type {
9393
return switch (builtin.cpu.arch) {
9494
.arm, .armeb, .thumb, .thumbeb => if (std.Target.arm.featureSetHas(builtin.cpu.features, .has_v8))
95-
switch (builtin.abi.floatAbi()) {
95+
switch (builtin.abi.float()) {
9696
.soft => u16,
9797
.hard => f16,
9898
}
9999
else
100100
u16,
101101
.aarch64, .aarch64_be => f16,
102102
.riscv32, .riscv64 => f16,
103-
.x86, .x86_64 => if (builtin.target.isDarwin()) switch (OtherType) {
103+
.x86, .x86_64 => if (builtin.target.os.tag.isDarwin()) switch (OtherType) {
104104
// Starting with LLVM 16, Darwin uses different abi for f16
105105
// depending on the type of the other return/argument..???
106106
f32, f64 => u16,

lib/std/Build/Step/Compile.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
465465
if (compile.linkage != null and compile.linkage.? == .static) {
466466
compile.out_lib_filename = compile.out_filename;
467467
} else if (compile.version) |version| {
468-
if (target.isDarwin()) {
468+
if (target.os.tag.isDarwin()) {
469469
compile.major_only_filename = owner.fmt("lib{s}.{d}.dylib", .{
470470
compile.name,
471471
version.major,
@@ -480,7 +480,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
480480
compile.out_lib_filename = compile.out_filename;
481481
}
482482
} else {
483-
if (target.isDarwin()) {
483+
if (target.os.tag.isDarwin()) {
484484
compile.out_lib_filename = compile.out_filename;
485485
} else if (target.os.tag == .windows) {
486486
compile.out_lib_filename = owner.fmt("{s}.lib", .{compile.name});
@@ -1524,7 +1524,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
15241524
try zig_args.append(b.fmt("{}", .{version}));
15251525
}
15261526

1527-
if (compile.rootModuleTarget().isDarwin()) {
1527+
if (compile.rootModuleTarget().os.tag.isDarwin()) {
15281528
const install_name = compile.install_name orelse b.fmt("@rpath/{s}{s}{s}", .{
15291529
compile.rootModuleTarget().libPrefix(),
15301530
compile.name,

0 commit comments

Comments
 (0)