authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-04 20:30:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:18-07:00
log8c44954bc6a91ae66f5aea92ea8380c28b50b3f0
tree561158f17f27378a0bbd7d572a347082cacc464c
parentdbdb87502d6936597424fe86842c15978ba86918

std.Target.Query: remove deprecated API

These functions have been doomed for a long time. Finally I figured out what the proper relationship between this API and std.Target is.

10 files changed, 275 insertions(+), 373 deletions(-)

deps/aro/aro/Driver.zig+6-3
......@@ -366,12 +366,15 @@ pub fn parseArgs(
366366 } else if (mem.eql(u8, arg, "-S") or mem.eql(u8, arg, "--assemble")) {
367367 d.only_preprocess_and_compile = true;
368368 } else if (option(arg, "--target=")) |triple| {
369 const cross = std.zig.CrossTarget.parse(.{ .arch_os_abi = triple }) catch {
369 const query = std.Target.Query.parse(.{ .arch_os_abi = triple }) catch {
370370 try d.comp.addDiagnostic(.{ .tag = .cli_invalid_target, .extra = .{ .str = arg } }, &.{});
371371 continue;
372372 };
373 d.comp.target = cross.toTarget(); // TODO deprecated
374 d.comp.langopts.setEmulatedCompiler(target_util.systemCompiler(d.comp.target));
373 const target = std.zig.system.resolveTargetQuery(query) catch |e| {
374 return d.fatal("unable to resolve target: {s}", .{errorDescription(e)});
375 };
376 d.comp.target = target;
377 d.comp.langopts.setEmulatedCompiler(target_util.systemCompiler(target));
375378 d.raw_target_triple = triple;
376379 } else if (mem.eql(u8, arg, "--verbose-ast")) {
377380 d.verbose_ast = true;
lib/std/Build.zig+26-110
......@@ -383,12 +383,7 @@ fn userInputOptionsFromArgs(allocator: Allocator, args: anytype) UserInputOption
383383 }) catch @panic("OOM");
384384 user_input_options.put("cpu", .{
385385 .name = "cpu",
386 .value = .{
387 .scalar = if (v.isNativeCpu())
388 "native"
389 else
390 serializeCpu(allocator, v.getCpu()) catch unreachable,
391 },
386 .value = .{ .scalar = v.serializeCpuAlloc(allocator) catch @panic("OOM") },
392387 .used = false,
393388 }) catch @panic("OOM");
394389 },
......@@ -400,12 +395,7 @@ fn userInputOptionsFromArgs(allocator: Allocator, args: anytype) UserInputOption
400395 }) catch @panic("OOM");
401396 user_input_options.put("cpu", .{
402397 .name = "cpu",
403 .value = .{
404 .scalar = if (v.query.isNativeCpu())
405 "native"
406 else
407 serializeCpu(allocator, v.target.cpu) catch unreachable,
408 },
398 .value = .{ .scalar = v.query.serializeCpuAlloc(allocator) catch @panic("OOM") },
409399 .used = false,
410400 }) catch @panic("OOM");
411401 },
......@@ -1196,7 +1186,6 @@ pub fn standardOptimizeOption(self: *Build, options: StandardOptimizeOptionOptio
11961186
11971187pub const StandardTargetOptionsArgs = struct {
11981188 whitelist: ?[]const Target.Query = null,
1199
12001189 default_target: Target.Query = .{},
12011190};
12021191
......@@ -1208,13 +1197,13 @@ pub fn standardTargetOptions(b: *Build, args: StandardTargetOptionsArgs) Resolve
12081197}
12091198
12101199/// Exposes standard `zig build` options for choosing a target.
1211pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsArgs) Target.Query {
1212 const maybe_triple = self.option(
1200pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs) Target.Query {
1201 const maybe_triple = b.option(
12131202 []const u8,
12141203 "target",
12151204 "The CPU architecture, OS, and ABI to build for",
12161205 );
1217 const mcpu = self.option([]const u8, "cpu", "Target CPU features to add or subtract");
1206 const mcpu = b.option([]const u8, "cpu", "Target CPU features to add or subtract");
12181207
12191208 if (maybe_triple == null and mcpu == null) {
12201209 return args.default_target;
......@@ -1236,7 +1225,7 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
12361225 for (diags.arch.?.allCpuModels()) |cpu| {
12371226 log.err(" {s}", .{cpu.name});
12381227 }
1239 self.markInvalidUserInput();
1228 b.markInvalidUserInput();
12401229 return args.default_target;
12411230 },
12421231 error.UnknownCpuFeature => {
......@@ -1251,7 +1240,7 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
12511240 for (diags.arch.?.allFeaturesList()) |feature| {
12521241 log.err(" {s}: {s}", .{ feature.name, feature.description });
12531242 }
1254 self.markInvalidUserInput();
1243 b.markInvalidUserInput();
12551244 return args.default_target;
12561245 },
12571246 error.UnknownOperatingSystem => {
......@@ -1263,80 +1252,35 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
12631252 inline for (std.meta.fields(Target.Os.Tag)) |field| {
12641253 log.err(" {s}", .{field.name});
12651254 }
1266 self.markInvalidUserInput();
1255 b.markInvalidUserInput();
12671256 return args.default_target;
12681257 },
12691258 else => |e| {
12701259 log.err("Unable to parse target '{s}': {s}\n", .{ triple, @errorName(e) });
1271 self.markInvalidUserInput();
1260 b.markInvalidUserInput();
12721261 return args.default_target;
12731262 },
12741263 };
12751264
1276 const selected_canonicalized_triple = selected_target.zigTriple(self.allocator) catch @panic("OOM");
1277
1278 if (args.whitelist) |list| whitelist_check: {
1279 // Make sure it's a match of one of the list.
1280 var mismatch_triple = true;
1281 var mismatch_cpu_features = true;
1282 var whitelist_item: Target.Query = .{};
1283 for (list) |t| {
1284 mismatch_cpu_features = true;
1285 mismatch_triple = true;
1286
1287 const t_triple = t.zigTriple(self.allocator) catch @panic("OOM");
1288 if (mem.eql(u8, t_triple, selected_canonicalized_triple)) {
1289 mismatch_triple = false;
1290 whitelist_item = t;
1291 if (t.getCpuFeatures().isSuperSetOf(selected_target.getCpuFeatures())) {
1292 mismatch_cpu_features = false;
1293 break :whitelist_check;
1294 } else {
1295 break;
1296 }
1297 }
1298 }
1299 if (mismatch_triple) {
1300 log.err("Chosen target '{s}' does not match one of the supported targets:", .{
1301 selected_canonicalized_triple,
1302 });
1303 for (list) |t| {
1304 const t_triple = t.zigTriple(self.allocator) catch @panic("OOM");
1305 log.err(" {s}", .{t_triple});
1306 }
1307 } else {
1308 assert(mismatch_cpu_features);
1309 const whitelist_cpu = whitelist_item.getCpu();
1310 const selected_cpu = selected_target.getCpu();
1311 log.err("Chosen CPU model '{s}' does not match one of the supported targets:", .{
1312 selected_cpu.model.name,
1313 });
1314 log.err(" Supported feature Set: ", .{});
1315 const all_features = whitelist_cpu.arch.allFeaturesList();
1316 var populated_cpu_features = whitelist_cpu.model.features;
1317 populated_cpu_features.populateDependencies(all_features);
1318 for (all_features, 0..) |feature, i_usize| {
1319 const i = @as(Target.Cpu.Feature.Set.Index, @intCast(i_usize));
1320 const in_cpu_set = populated_cpu_features.isEnabled(i);
1321 if (in_cpu_set) {
1322 log.err("{s} ", .{feature.name});
1323 }
1324 }
1325 log.err(" Remove: ", .{});
1326 for (all_features, 0..) |feature, i_usize| {
1327 const i = @as(Target.Cpu.Feature.Set.Index, @intCast(i_usize));
1328 const in_cpu_set = populated_cpu_features.isEnabled(i);
1329 const in_actual_set = selected_cpu.features.isEnabled(i);
1330 if (in_actual_set and !in_cpu_set) {
1331 log.err("{s} ", .{feature.name});
1332 }
1333 }
1334 }
1335 self.markInvalidUserInput();
1336 return args.default_target;
1265 const whitelist = args.whitelist orelse return selected_target;
1266
1267 // Make sure it's a match of one of the list.
1268 for (whitelist) |q| {
1269 if (q.eql(selected_target))
1270 return selected_target;
13371271 }
13381272
1339 return selected_target;
1273 for (whitelist) |q| {
1274 log.info("allowed target: -Dtarget={s} -Dcpu={s}", .{
1275 q.zigTriple(b.allocator) catch @panic("OOM"),
1276 q.serializeCpuAlloc(b.allocator) catch @panic("OOM"),
1277 });
1278 }
1279 log.err("chosen target '{s}' does not match one of the allowed targets", .{
1280 selected_target.zigTriple(b.allocator) catch @panic("OOM"),
1281 });
1282 b.markInvalidUserInput();
1283 return args.default_target;
13401284}
13411285
13421286pub fn addUserInputOption(self: *Build, name_raw: []const u8, value_raw: []const u8) !bool {
......@@ -2064,34 +2008,6 @@ pub const InstalledFile = struct {
20642008 }
20652009};
20662010
2067pub fn serializeCpu(allocator: Allocator, cpu: Target.Cpu) ![]const u8 {
2068 // TODO this logic can disappear if cpu model + features becomes part of the target triple
2069 const all_features = cpu.arch.allFeaturesList();
2070 var populated_cpu_features = cpu.model.features;
2071 populated_cpu_features.populateDependencies(all_features);
2072
2073 if (populated_cpu_features.eql(cpu.features)) {
2074 // The CPU name alone is sufficient.
2075 return cpu.model.name;
2076 } else {
2077 var mcpu_buffer = ArrayList(u8).init(allocator);
2078 try mcpu_buffer.appendSlice(cpu.model.name);
2079
2080 for (all_features, 0..) |feature, i_usize| {
2081 const i = @as(Target.Cpu.Feature.Set.Index, @intCast(i_usize));
2082 const in_cpu_set = populated_cpu_features.isEnabled(i);
2083 const in_actual_set = cpu.features.isEnabled(i);
2084 if (in_cpu_set and !in_actual_set) {
2085 try mcpu_buffer.writer().print("-{s}", .{feature.name});
2086 } else if (!in_cpu_set and in_actual_set) {
2087 try mcpu_buffer.writer().print("+{s}", .{feature.name});
2088 }
2089 }
2090
2091 return try mcpu_buffer.toOwnedSlice();
2092 }
2093}
2094
20952011/// This function is intended to be called in the `configure` phase only.
20962012/// It returns an absolute directory path, which is potentially going to be a
20972013/// source of API breakage in the future, so keep that in mind when using this
lib/std/Build/Module.zig+2-2
......@@ -627,12 +627,12 @@ pub fn appendZigProcessFlags(
627627 try zig_args.append(@tagName(m.code_model));
628628 }
629629
630 if (m.target) |target| {
630 if (m.target) |*target| {
631631 // Communicate the query via CLI since it's more compact.
632632 if (!target.query.isNative()) {
633633 try zig_args.appendSlice(&.{
634634 "-target", try target.query.zigTriple(b.allocator),
635 "-mcpu", try std.Build.serializeCpu(b.allocator, target.query.getCpu()),
635 "-mcpu", try target.query.serializeCpuAlloc(b.allocator),
636636 });
637637
638638 if (target.query.dynamic_linker.get()) |dynamic_linker| {
lib/std/Target.zig+11-2
......@@ -1394,7 +1394,7 @@ pub const Cpu = struct {
13941394 }
13951395};
13961396
1397pub fn zigTriple(self: Target, allocator: Allocator) ![]u8 {
1397pub fn zigTriple(self: Target, allocator: Allocator) Allocator.Error![]u8 {
13981398 return Query.fromTarget(self).zigTriple(allocator);
13991399}
14001400
......@@ -1566,11 +1566,20 @@ pub const DynamicLinker = struct {
15661566 pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void {
15671567 if (dl_or_null) |dl| {
15681568 @memcpy(self.buffer[0..dl.len], dl);
1569 self.max_byte = @as(u8, @intCast(dl.len - 1));
1569 self.max_byte = @intCast(dl.len - 1);
15701570 } else {
15711571 self.max_byte = null;
15721572 }
15731573 }
1574
1575 pub fn eql(a: DynamicLinker, b: DynamicLinker) bool {
1576 const a_m = a.max_byte orelse return b.max_byte == null;
1577 const b_m = b.max_byte orelse return false;
1578 if (a_m != b_m) return false;
1579 const a_s = a.buffer[0 .. a_m + 1];
1580 const b_s = b.buffer[0 .. a_m + 1];
1581 return std.mem.eql(u8, a_s, b_s);
1582 }
15741583};
15751584
15761585pub fn standardDynamicLinkerPath(target: Target) DynamicLinker {
lib/std/Target/Query.zig+128-206
......@@ -51,12 +51,41 @@ pub const CpuModel = union(enum) {
5151 determined_by_cpu_arch,
5252
5353 explicit: *const Target.Cpu.Model,
54
55 pub fn eql(a: CpuModel, b: CpuModel) bool {
56 const Tag = @typeInfo(CpuModel).Union.tag_type.?;
57 const a_tag: Tag = a;
58 const b_tag: Tag = b;
59 if (a_tag != b_tag) return false;
60 return switch (a) {
61 .native, .baseline, .determined_by_cpu_arch => true,
62 .explicit => |a_model| a_model == b.explicit,
63 };
64 }
5465};
5566
5667pub const OsVersion = union(enum) {
5768 none: void,
5869 semver: SemanticVersion,
5970 windows: Target.Os.WindowsVersion,
71
72 pub fn eql(a: OsVersion, b: OsVersion) bool {
73 const Tag = @typeInfo(OsVersion).Union.tag_type.?;
74 const a_tag: Tag = a;
75 const b_tag: Tag = b;
76 if (a_tag != b_tag) return false;
77 return switch (a) {
78 .none => true,
79 .semver => |a_semver| a_semver.order(b.semver) == .eq,
80 .windows => |a_windows| a_windows == b.windows,
81 };
82 }
83
84 pub fn eqlOpt(a: ?OsVersion, b: ?OsVersion) bool {
85 if (a == null and b == null) return true;
86 if (a == null or b == null) return false;
87 return OsVersion.eql(a.?, b.?);
88 }
6089};
6190
6291pub const SemanticVersion = std.SemanticVersion;
......@@ -162,16 +191,6 @@ fn updateOsVersionRange(self: *Query, os: Target.Os) void {
162191 }
163192}
164193
165/// TODO deprecated, use `std.zig.system.resolveTargetQuery`.
166pub fn toTarget(self: Query) Target {
167 return .{
168 .cpu = self.getCpu(),
169 .os = self.getOs(),
170 .abi = self.getAbi(),
171 .ofmt = self.getObjectFormat(),
172 };
173}
174
175194pub const ParseOptions = struct {
176195 /// This is sometimes called a "triple". It looks roughly like this:
177196 /// riscv64-linux-musl
......@@ -240,7 +259,7 @@ pub fn parse(args: ParseOptions) !Query {
240259 result.cpu_arch = std.meta.stringToEnum(Target.Cpu.Arch, arch_name) orelse
241260 return error.UnknownArchitecture;
242261 }
243 const arch = result.getCpuArch();
262 const arch = result.cpu_arch orelse builtin.cpu.arch;
244263 diags.arch = arch;
245264
246265 if (it.next()) |os_text| {
......@@ -259,7 +278,7 @@ pub fn parse(args: ParseOptions) !Query {
259278
260279 const abi_ver_text = abi_it.rest();
261280 if (abi_it.next() != null) {
262 if (result.isGnuLibC()) {
281 if (Target.isGnuLibC_os_tag_abi(result.os_tag orelse builtin.os.tag, abi)) {
263282 result.glibc_version = parseVersion(abi_ver_text) catch |err| switch (err) {
264283 error.Overflow => return error.InvalidAbiVersion,
265284 error.InvalidVersion => return error.InvalidAbiVersion,
......@@ -377,168 +396,6 @@ test parseVersion {
377396 try std.testing.expectError(error.InvalidVersion, parseVersion("1.2.3.4"));
378397}
379398
380/// TODO deprecated, use `std.zig.system.resolveTargetQuery`.
381pub fn getCpu(self: Query) Target.Cpu {
382 switch (self.cpu_model) {
383 .native => {
384 // This works when doing `zig build` because Zig generates a build executable using
385 // native CPU model & features. However this will not be accurate otherwise, and
386 // will need to be integrated with `std.zig.system.resolveTargetQuery`.
387 return builtin.cpu;
388 },
389 .baseline => {
390 var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch());
391 self.updateCpuFeatures(&adjusted_baseline.features);
392 return adjusted_baseline;
393 },
394 .determined_by_cpu_arch => if (self.cpu_arch == null) {
395 // This works when doing `zig build` because Zig generates a build executable using
396 // native CPU model & features. However this will not be accurate otherwise, and
397 // will need to be integrated with `std.zig.system.resolveTargetQuery`.
398 return builtin.cpu;
399 } else {
400 var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch());
401 self.updateCpuFeatures(&adjusted_baseline.features);
402 return adjusted_baseline;
403 },
404 .explicit => |model| {
405 var adjusted_model = model.toCpu(self.getCpuArch());
406 self.updateCpuFeatures(&adjusted_model.features);
407 return adjusted_model;
408 },
409 }
410}
411
412pub fn getCpuArch(self: Query) Target.Cpu.Arch {
413 return self.cpu_arch orelse builtin.cpu.arch;
414}
415
416pub fn getCpuModel(self: Query) *const Target.Cpu.Model {
417 return switch (self.cpu_model) {
418 .explicit => |cpu_model| cpu_model,
419 else => self.getCpu().model,
420 };
421}
422
423pub fn getCpuFeatures(self: Query) Target.Cpu.Feature.Set {
424 return self.getCpu().features;
425}
426
427/// TODO deprecated, use `std.zig.system.resolveTargetQuery`.
428pub fn getOs(self: Query) Target.Os {
429 // `builtin.os` works when doing `zig build` because Zig generates a build executable using
430 // native OS version range. However this will not be accurate otherwise, and
431 // will need to be integrated with `std.zig.system.resolveTargetQuery`.
432 var adjusted_os = if (self.os_tag) |os_tag| os_tag.defaultVersionRange(self.getCpuArch()) else builtin.os;
433
434 if (self.os_version_min) |min| switch (min) {
435 .none => {},
436 .semver => |semver| switch (self.getOsTag()) {
437 .linux => adjusted_os.version_range.linux.range.min = semver,
438 else => adjusted_os.version_range.semver.min = semver,
439 },
440 .windows => |win_ver| adjusted_os.version_range.windows.min = win_ver,
441 };
442
443 if (self.os_version_max) |max| switch (max) {
444 .none => {},
445 .semver => |semver| switch (self.getOsTag()) {
446 .linux => adjusted_os.version_range.linux.range.max = semver,
447 else => adjusted_os.version_range.semver.max = semver,
448 },
449 .windows => |win_ver| adjusted_os.version_range.windows.max = win_ver,
450 };
451
452 if (self.glibc_version) |glibc| {
453 assert(self.isGnuLibC());
454 adjusted_os.version_range.linux.glibc = glibc;
455 }
456
457 return adjusted_os;
458}
459
460pub fn getOsTag(self: Query) Target.Os.Tag {
461 return self.os_tag orelse builtin.os.tag;
462}
463
464/// TODO deprecated, use `std.zig.system.resolveTargetQuery`.
465pub fn getOsVersionMin(self: Query) OsVersion {
466 if (self.os_version_min) |version_min| return version_min;
467 var tmp: Query = undefined;
468 tmp.updateOsVersionRange(self.getOs());
469 return tmp.os_version_min.?;
470}
471
472/// TODO deprecated, use `std.zig.system.resolveTargetQuery`.
473pub fn getOsVersionMax(self: Query) OsVersion {
474 if (self.os_version_max) |version_max| return version_max;
475 var tmp: Query = undefined;
476 tmp.updateOsVersionRange(self.getOs());
477 return tmp.os_version_max.?;
478}
479
480/// TODO deprecated, use `std.zig.system.resolveTargetQuery`.
481pub fn getAbi(self: Query) Target.Abi {
482 if (self.abi) |abi| return abi;
483
484 if (self.os_tag == null) {
485 // This works when doing `zig build` because Zig generates a build executable using
486 // native CPU model & features. However this will not be accurate otherwise, and
487 // will need to be integrated with `std.zig.system.resolveTargetQuery`.
488 return builtin.abi;
489 }
490
491 return Target.Abi.default(self.getCpuArch(), self.getOs());
492}
493
494pub fn isFreeBSD(self: Query) bool {
495 return self.getOsTag() == .freebsd;
496}
497
498pub fn isDarwin(self: Query) bool {
499 return self.getOsTag().isDarwin();
500}
501
502pub fn isNetBSD(self: Query) bool {
503 return self.getOsTag() == .netbsd;
504}
505
506pub fn isOpenBSD(self: Query) bool {
507 return self.getOsTag() == .openbsd;
508}
509
510pub fn isUefi(self: Query) bool {
511 return self.getOsTag() == .uefi;
512}
513
514pub fn isDragonFlyBSD(self: Query) bool {
515 return self.getOsTag() == .dragonfly;
516}
517
518pub fn isLinux(self: Query) bool {
519 return self.getOsTag() == .linux;
520}
521
522pub fn isWindows(self: Query) bool {
523 return self.getOsTag() == .windows;
524}
525
526pub fn exeFileExt(self: Query) [:0]const u8 {
527 return Target.exeFileExtSimple(self.getCpuArch(), self.getOsTag());
528}
529
530pub fn staticLibSuffix(self: Query) [:0]const u8 {
531 return Target.staticLibSuffix_os_abi(self.getOsTag(), self.getAbi());
532}
533
534pub fn dynamicLibSuffix(self: Query) [:0]const u8 {
535 return self.getOsTag().dynamicLibSuffix();
536}
537
538pub fn libPrefix(self: Query) [:0]const u8 {
539 return Target.libPrefix_os_abi(self.getOsTag(), self.getAbi());
540}
541
542399pub fn isNativeCpu(self: Query) bool {
543400 return self.cpu_arch == null and
544401 (self.cpu_model == .native or self.cpu_model == .determined_by_cpu_arch) and
......@@ -568,7 +425,7 @@ fn formatVersion(version: SemanticVersion, writer: anytype) !void {
568425 }
569426}
570427
571pub fn zigTriple(self: Query, allocator: mem.Allocator) error{OutOfMemory}![]u8 {
428pub fn zigTriple(self: Query, allocator: Allocator) Allocator.Error![]u8 {
572429 if (self.isNative()) {
573430 return allocator.dupe(u8, "native");
574431 }
......@@ -583,14 +440,16 @@ pub fn zigTriple(self: Query, allocator: mem.Allocator) error{OutOfMemory}![]u8
583440
584441 // The zig target syntax does not allow specifying a max os version with no min, so
585442 // if either are present, we need the min.
586 if (self.os_version_min != null or self.os_version_max != null) {
587 switch (self.getOsVersionMin()) {
443 if (self.os_version_min) |min| {
444 switch (min) {
588445 .none => {},
589446 .semver => |v| {
590447 try result.writer().writeAll(".");
591448 try formatVersion(v, result.writer());
592449 },
593 .windows => |v| try result.writer().print("{s}", .{v}),
450 .windows => |v| {
451 try result.writer().print("{s}", .{v});
452 },
594453 }
595454 }
596455 if (self.os_version_max) |max| {
......@@ -600,48 +459,88 @@ pub fn zigTriple(self: Query, allocator: mem.Allocator) error{OutOfMemory}![]u8
600459 try result.writer().writeAll("...");
601460 try formatVersion(v, result.writer());
602461 },
603 .windows => |v| try result.writer().print("..{s}", .{v}),
462 .windows => |v| {
463 try result.writer().print("...{s}", .{v});
464 },
604465 }
605466 }
606467
607468 if (self.glibc_version) |v| {
608 try result.writer().print("-{s}.", .{@tagName(self.getAbi())});
469 const name = @tagName(self.abi orelse builtin.target.abi);
470 try result.ensureUnusedCapacity(name.len + 2);
471 result.appendAssumeCapacity('-');
472 result.appendSliceAssumeCapacity(name);
473 result.appendAssumeCapacity('.');
609474 try formatVersion(v, result.writer());
610475 } else if (self.abi) |abi| {
611 try result.writer().print("-{s}", .{@tagName(abi)});
476 const name = @tagName(abi);
477 try result.ensureUnusedCapacity(name.len + 1);
478 result.appendAssumeCapacity('-');
479 result.appendSliceAssumeCapacity(name);
612480 }
613481
614482 return result.toOwnedSlice();
615483}
616484
617pub fn allocDescription(self: Query, allocator: mem.Allocator) ![]u8 {
618 // TODO is there anything else worthy of the description that is not
619 // already captured in the triple?
620 return self.zigTriple(allocator);
621}
485/// Renders the query into a textual representation that can be parsed via the
486/// `-mcpu` flag passed to the Zig compiler.
487/// Appends the result to `buffer`.
488pub fn serializeCpu(q: Query, buffer: *std.ArrayList(u8)) Allocator.Error!void {
489 try buffer.ensureUnusedCapacity(8);
490 switch (q.cpu_model) {
491 .native => {
492 buffer.appendSliceAssumeCapacity("native");
493 },
494 .baseline => {
495 buffer.appendSliceAssumeCapacity("baseline");
496 },
497 .determined_by_cpu_arch => {
498 if (q.cpu_arch == null) {
499 buffer.appendSliceAssumeCapacity("native");
500 } else {
501 buffer.appendSliceAssumeCapacity("baseline");
502 }
503 },
504 .explicit => |model| {
505 try buffer.appendSlice(model.name);
506 },
507 }
622508
623pub fn linuxTriple(self: Query, allocator: mem.Allocator) ![]u8 {
624 return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi());
625}
509 if (q.cpu_features_add.isEmpty() and q.cpu_features_sub.isEmpty()) {
510 // The CPU name alone is sufficient.
511 return;
512 }
626513
627pub fn isGnuLibC(self: Query) bool {
628 return Target.isGnuLibC_os_tag_abi(self.getOsTag(), self.getAbi());
514 const cpu_arch = q.cpu_arch orelse builtin.cpu.arch;
515 const all_features = cpu_arch.allFeaturesList();
516
517 for (all_features, 0..) |feature, i_usize| {
518 const i: Target.Cpu.Feature.Set.Index = @intCast(i_usize);
519 try buffer.ensureUnusedCapacity(feature.name.len + 1);
520 if (q.cpu_features_sub.isEnabled(i)) {
521 buffer.appendAssumeCapacity('-');
522 buffer.appendSliceAssumeCapacity(feature.name);
523 } else if (q.cpu_features_add.isEnabled(i)) {
524 buffer.appendAssumeCapacity('+');
525 buffer.appendSliceAssumeCapacity(feature.name);
526 }
527 }
629528}
630529
631pub fn setGnuLibCVersion(self: *Query, major: u32, minor: u32, patch: u32) void {
632 assert(self.isGnuLibC());
633 self.glibc_version = SemanticVersion{ .major = major, .minor = minor, .patch = patch };
530pub fn serializeCpuAlloc(q: Query, ally: Allocator) Allocator.Error![]u8 {
531 var buffer = std.ArrayList(u8).init(ally);
532 try serializeCpu(q, &buffer);
533 return buffer.toOwnedSlice();
634534}
635535
636pub fn getObjectFormat(self: Query) Target.ObjectFormat {
637 return self.ofmt orelse Target.ObjectFormat.default(self.getOsTag(), self.getCpuArch());
536pub fn allocDescription(self: Query, allocator: Allocator) ![]u8 {
537 // TODO is there anything else worthy of the description that is not
538 // already captured in the triple?
539 return self.zigTriple(allocator);
638540}
639541
640pub fn updateCpuFeatures(self: Query, set: *Target.Cpu.Feature.Set) void {
641 set.removeFeatureSet(self.cpu_features_sub);
642 set.addFeatureSet(self.cpu_features_add);
643 set.populateDependencies(self.getCpuArch().allFeaturesList());
644 set.removeFeatureSet(self.cpu_features_sub);
542pub fn setGnuLibCVersion(self: *Query, major: u32, minor: u32, patch: u32) void {
543 self.glibc_version = SemanticVersion{ .major = major, .minor = minor, .patch = patch };
645544}
646545
647546fn parseOs(result: *Query, diags: *ParseOptions.Diagnostics, text: []const u8) !void {
......@@ -653,7 +552,7 @@ fn parseOs(result: *Query, diags: *ParseOptions.Diagnostics, text: []const u8) !
653552 result.os_tag = std.meta.stringToEnum(Target.Os.Tag, os_name) orelse
654553 return error.UnknownOperatingSystem;
655554 }
656 const tag = result.getOsTag();
555 const tag = result.os_tag orelse builtin.os.tag;
657556 diags.os_tag = tag;
658557
659558 const version_text = it.rest();
......@@ -741,12 +640,35 @@ fn parseOs(result: *Query, diags: *ParseOptions.Diagnostics, text: []const u8) !
741640 }
742641}
743642
643pub fn eql(a: Query, b: Query) bool {
644 if (a.cpu_arch != b.cpu_arch) return false;
645 if (!a.cpu_model.eql(b.cpu_model)) return false;
646 if (!a.cpu_features_add.eql(b.cpu_features_add)) return false;
647 if (!a.cpu_features_sub.eql(b.cpu_features_sub)) return false;
648 if (a.os_tag != b.os_tag) return false;
649 if (!OsVersion.eqlOpt(a.os_version_min, b.os_version_min)) return false;
650 if (!OsVersion.eqlOpt(a.os_version_max, b.os_version_max)) return false;
651 if (!versionEqualOpt(a.glibc_version, b.glibc_version)) return false;
652 if (a.abi != b.abi) return false;
653 if (!a.dynamic_linker.eql(b.dynamic_linker)) return false;
654 if (a.ofmt != b.ofmt) return false;
655
656 return true;
657}
658
659fn versionEqualOpt(a: ?SemanticVersion, b: ?SemanticVersion) bool {
660 if (a == null and b == null) return true;
661 if (a == null or b == null) return false;
662 return SemanticVersion.order(a.?, b.?) == .eq;
663}
664
744665const Query = @This();
745666const std = @import("../std.zig");
746667const builtin = @import("builtin");
747668const assert = std.debug.assert;
748669const Target = std.Target;
749670const mem = std.mem;
671const Allocator = std.mem.Allocator;
750672
751673test parse {
752674 if (builtin.target.isGnuLibC()) {
......@@ -760,7 +682,7 @@ test parse {
760682 const triple = std.fmt.bufPrint(
761683 buf[0..],
762684 "native-native-{s}.2.1.1",
763 .{@tagName(builtin.abi)},
685 .{@tagName(builtin.target.abi)},
764686 ) catch unreachable;
765687
766688 try std.testing.expectEqualSlices(u8, triple, text);
......@@ -789,7 +711,7 @@ test parse {
789711 .arch_os_abi = "x86_64-linux-gnu",
790712 .cpu_features = "x86_64-sse-sse2-avx-cx8",
791713 });
792 const target = query.toTarget();
714 const target = try std.zig.system.resolveTargetQuery(query);
793715
794716 try std.testing.expect(target.os.tag == .linux);
795717 try std.testing.expect(target.abi == .gnu);
......@@ -814,7 +736,7 @@ test parse {
814736 .arch_os_abi = "arm-linux-musleabihf",
815737 .cpu_features = "generic+v8a",
816738 });
817 const target = query.toTarget();
739 const target = try std.zig.system.resolveTargetQuery(query);
818740
819741 try std.testing.expect(target.os.tag == .linux);
820742 try std.testing.expect(target.abi == .musleabihf);
......@@ -831,7 +753,7 @@ test parse {
831753 .arch_os_abi = "aarch64-linux.3.10...4.4.1-gnu.2.27",
832754 .cpu_features = "generic+v8a",
833755 });
834 const target = query.toTarget();
756 const target = try std.zig.system.resolveTargetQuery(query);
835757
836758 try std.testing.expect(target.cpu.arch == .aarch64);
837759 try std.testing.expect(target.os.tag == .linux);
lib/std/zig.zig+42-4
......@@ -1,7 +1,4 @@
1const std = @import("std.zig");
2const tokenizer = @import("zig/tokenizer.zig");
31pub const fmt = @import("zig/fmt.zig");
4const assert = std.debug.assert;
52
63pub const ErrorBundle = @import("zig/ErrorBundle.zig");
74pub const Server = @import("zig/Server.zig");
......@@ -115,7 +112,7 @@ pub const BinNameOptions = struct {
115112};
116113
117114/// Returns the standard file system basename of a binary generated by the Zig compiler.
118pub fn binNameAlloc(allocator: std.mem.Allocator, options: BinNameOptions) error{OutOfMemory}![]u8 {
115pub fn binNameAlloc(allocator: Allocator, options: BinNameOptions) error{OutOfMemory}![]u8 {
119116 const root_name = options.root_name;
120117 const target = options.target;
121118 switch (target.ofmt) {
......@@ -281,6 +278,47 @@ pub const BuildId = union(enum) {
281278 }
282279};
283280
281/// Renders a `std.Target.Cpu` value into a textual representation that can be parsed
282/// via the `-mcpu` flag passed to the Zig compiler.
283/// Appends the result to `buffer`.
284pub fn serializeCpu(buffer: *std.ArrayList(u8), cpu: std.Target.Cpu) Allocator.Error!void {
285 const all_features = cpu.arch.allFeaturesList();
286 var populated_cpu_features = cpu.model.features;
287 populated_cpu_features.populateDependencies(all_features);
288
289 try buffer.appendSlice(cpu.model.name);
290
291 if (populated_cpu_features.eql(cpu.features)) {
292 // The CPU name alone is sufficient.
293 return;
294 }
295
296 for (all_features, 0..) |feature, i_usize| {
297 const i: std.Target.Cpu.Feature.Set.Index = @intCast(i_usize);
298 const in_cpu_set = populated_cpu_features.isEnabled(i);
299 const in_actual_set = cpu.features.isEnabled(i);
300 try buffer.ensureUnusedCapacity(feature.name.len + 1);
301 if (in_cpu_set and !in_actual_set) {
302 buffer.appendAssumeCapacity('-');
303 buffer.appendSliceAssumeCapacity(feature.name);
304 } else if (!in_cpu_set and in_actual_set) {
305 buffer.appendAssumeCapacity('+');
306 buffer.appendSliceAssumeCapacity(feature.name);
307 }
308 }
309}
310
311pub fn serializeCpuAlloc(ally: Allocator, cpu: std.Target.Cpu) Allocator.Error![]u8 {
312 var buffer = std.ArrayList(u8).init(ally);
313 try serializeCpu(&buffer, cpu);
314 return buffer.toOwnedSlice();
315}
316
317const std = @import("std.zig");
318const tokenizer = @import("zig/tokenizer.zig");
319const assert = std.debug.assert;
320const Allocator = std.mem.Allocator;
321
284322test {
285323 @import("std").testing.refAllDecls(@This());
286324}
lib/std/zig/system.zig+23-6
......@@ -163,7 +163,8 @@ pub const DetectError = error{
163163/// components by detecting the native system, and then resolves
164164/// standard/default parts relative to that.
165165pub fn resolveTargetQuery(query: Target.Query) DetectError!Target {
166 var os = query.getOsTag().defaultVersionRange(query.getCpuArch());
166 const query_os_tag = query.os_tag orelse builtin.os.tag;
167 var os = query_os_tag.defaultVersionRange(query.cpu_arch orelse builtin.cpu.arch);
167168 if (query.os_tag == null) {
168169 switch (builtin.target.os.tag) {
169170 .linux => {
......@@ -292,7 +293,7 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target {
292293
293294 if (query.os_version_min) |min| switch (min) {
294295 .none => {},
295 .semver => |semver| switch (query.getOsTag()) {
296 .semver => |semver| switch (os.tag) {
296297 .linux => os.version_range.linux.range.min = semver,
297298 else => os.version_range.semver.min = semver,
298299 },
......@@ -301,7 +302,7 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target {
301302
302303 if (query.os_version_max) |max| switch (max) {
303304 .none => {},
304 .semver => |semver| switch (query.getOsTag()) {
305 .semver => |semver| switch (os.tag) {
305306 .linux => os.version_range.linux.range.max = semver,
306307 else => os.version_range.semver.max = semver,
307308 },
......@@ -309,13 +310,12 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target {
309310 };
310311
311312 if (query.glibc_version) |glibc| {
312 assert(query.isGnuLibC());
313313 os.version_range.linux.glibc = glibc;
314314 }
315315
316316 // Until https://github.com/ziglang/zig/issues/4592 is implemented (support detecting the
317317 // native CPU architecture as being different than the current target), we use this:
318 const cpu_arch = query.getCpuArch();
318 const cpu_arch = query.cpu_arch orelse builtin.cpu.arch;
319319
320320 const cpu = switch (query.cpu_model) {
321321 .native => detectNativeCpuAndFeatures(cpu_arch, os, query),
......@@ -361,10 +361,27 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target {
361361 },
362362 else => {},
363363 }
364 query.updateCpuFeatures(&result.cpu.features);
364 updateCpuFeatures(
365 &result.cpu.features,
366 cpu_arch.allFeaturesList(),
367 query.cpu_features_add,
368 query.cpu_features_sub,
369 );
365370 return result;
366371}
367372
373fn updateCpuFeatures(
374 set: *Target.Cpu.Feature.Set,
375 all_features_list: []const Target.Cpu.Feature,
376 add_set: Target.Cpu.Feature.Set,
377 sub_set: Target.Cpu.Feature.Set,
378) void {
379 set.removeFeatureSet(sub_set);
380 set.addFeatureSet(add_set);
381 set.populateDependencies(all_features_list);
382 set.removeFeatureSet(sub_set);
383}
384
368385fn detectNativeCpuAndFeatures(cpu_arch: Target.Cpu.Arch, os: Target.Os, query: Target.Query) ?Target.Cpu {
369386 // Here we switch on a comptime value rather than `cpu_arch`. This is valid because `cpu_arch`,
370387 // although it is a runtime value, is guaranteed to be one of the architectures in the set
src/libc_installation.zig+6-7
......@@ -41,7 +41,7 @@ pub const LibCInstallation = struct {
4141 pub fn parse(
4242 allocator: Allocator,
4343 libc_file: []const u8,
44 target: std.Target.Query,
44 target: std.Target,
4545 ) !LibCInstallation {
4646 var self: LibCInstallation = .{};
4747
......@@ -95,24 +95,23 @@ pub const LibCInstallation = struct {
9595 return error.ParseError;
9696 }
9797
98 const os_tag = target.getOsTag();
98 const os_tag = target.os.tag;
9999 if (self.crt_dir == null and !target.isDarwin()) {
100100 log.err("crt_dir may not be empty for {s}\n", .{@tagName(os_tag)});
101101 return error.ParseError;
102102 }
103103
104 const abi = target.getAbi();
105 if (self.msvc_lib_dir == null and target.isWindows() and abi == .msvc) {
104 if (self.msvc_lib_dir == null and os_tag == .windows and target.abi == .msvc) {
106105 log.err("msvc_lib_dir may not be empty for {s}-{s}\n", .{
107106 @tagName(os_tag),
108 @tagName(abi),
107 @tagName(target.abi),
109108 });
110109 return error.ParseError;
111110 }
112 if (self.kernel32_lib_dir == null and target.isWindows() and abi == .msvc) {
111 if (self.kernel32_lib_dir == null and os_tag == .windows and target.abi == .msvc) {
113112 log.err("kernel32_lib_dir may not be empty for {s}-{s}\n", .{
114113 @tagName(os_tag),
115 @tagName(abi),
114 @tagName(target.abi),
116115 });
117116 return error.ParseError;
118117 }
src/main.zig+8-8
......@@ -2696,13 +2696,13 @@ fn buildOutputType(
26962696 }
26972697
26982698 if (use_lld) |opt| {
2699 if (opt and target_query.isDarwin()) {
2699 if (opt and target.isDarwin()) {
27002700 fatal("LLD requested with Mach-O object format. Only the self-hosted linker is supported for this target.", .{});
27012701 }
27022702 }
27032703
27042704 if (want_lto) |opt| {
2705 if (opt and target_query.isDarwin()) {
2705 if (opt and target.isDarwin()) {
27062706 fatal("LTO is not yet supported with the Mach-O object format. More details: https://github.com/ziglang/zig/issues/8680", .{});
27072707 }
27082708 }
......@@ -2772,7 +2772,7 @@ fn buildOutputType(
27722772
27732773 var libc_installation: ?LibCInstallation = null;
27742774 if (libc_paths_file) |paths_file| {
2775 libc_installation = LibCInstallation.parse(arena, paths_file, target_query) catch |err| {
2775 libc_installation = LibCInstallation.parse(arena, paths_file, target) catch |err| {
27762776 fatal("unable to parse libc paths file at path {s}: {s}", .{ paths_file, @errorName(err) });
27772777 };
27782778 }
......@@ -2865,7 +2865,7 @@ fn buildOutputType(
28652865 libc_installation = try LibCInstallation.findNative(.{
28662866 .allocator = arena,
28672867 .verbose = true,
2868 .target = target_query.toTarget(),
2868 .target = target,
28692869 });
28702870
28712871 try lib_dirs.appendSlice(&.{ libc_installation.?.msvc_lib_dir.?, libc_installation.?.kernel32_lib_dir.? });
......@@ -4755,6 +4755,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
47554755 const target_query = try parseTargetQueryOrReportFatalError(gpa, .{
47564756 .arch_os_abi = target_arch_os_abi,
47574757 });
4758 const target = try std.zig.system.resolveTargetQuery(target_query);
47584759
47594760 if (print_includes) {
47604761 var arena_state = std.heap.ArenaAllocator.init(gpa);
......@@ -4764,7 +4765,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
47644765 const libc_installation: ?*LibCInstallation = libc: {
47654766 if (input_file) |libc_file| {
47664767 const libc = try arena.create(LibCInstallation);
4767 libc.* = LibCInstallation.parse(arena, libc_file, target_query) catch |err| {
4768 libc.* = LibCInstallation.parse(arena, libc_file, target) catch |err| {
47684769 fatal("unable to parse libc file at path {s}: {s}", .{ libc_file, @errorName(err) });
47694770 };
47704771 break :libc libc;
......@@ -4779,7 +4780,6 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
47794780 };
47804781 defer zig_lib_directory.handle.close();
47814782
4782 const target = target_query.toTarget();
47834783 const is_native_abi = target_query.isNativeAbi();
47844784
47854785 const libc_dirs = Compilation.detectLibCIncludeDirs(
......@@ -4810,7 +4810,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
48104810 }
48114811
48124812 if (input_file) |libc_file| {
4813 var libc = LibCInstallation.parse(gpa, libc_file, target_query) catch |err| {
4813 var libc = LibCInstallation.parse(gpa, libc_file, target) catch |err| {
48144814 fatal("unable to parse libc file at path {s}: {s}", .{ libc_file, @errorName(err) });
48154815 };
48164816 defer libc.deinit(gpa);
......@@ -4821,7 +4821,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
48214821 var libc = LibCInstallation.findNative(.{
48224822 .allocator = gpa,
48234823 .verbose = true,
4824 .target = try std.zig.system.resolveTargetQuery(target_query),
4824 .target = target,
48254825 }) catch |err| {
48264826 fatal("unable to detect native libc: {s}", .{@errorName(err)});
48274827 };
test/tests.zig+23-25
......@@ -1036,14 +1036,17 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
10361036
10371037 for (test_targets) |test_target| {
10381038 const is_native = test_target.target.isNative() or
1039 (test_target.target.getOsTag() == builtin.os.tag and
1040 test_target.target.getCpuArch() == builtin.cpu.arch);
1039 (test_target.target.os_tag == builtin.os.tag and
1040 test_target.target.cpu_arch == builtin.cpu.arch);
10411041
10421042 if (options.skip_non_native and !is_native)
10431043 continue;
10441044
1045 const resolved_target = b.resolveTargetQuery(test_target.target);
1046 const target = resolved_target.target;
1047
10451048 if (options.skip_cross_glibc and !test_target.target.isNative() and
1046 test_target.target.isGnuLibC() and test_target.link_libc == true)
1049 target.isGnuLibC() and test_target.link_libc == true)
10471050 continue;
10481051
10491052 if (options.skip_libc and test_target.link_libc == true)
......@@ -1053,35 +1056,30 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
10531056 continue;
10541057
10551058 // TODO get compiler-rt tests passing for self-hosted backends.
1056 if ((test_target.target.getCpuArch() != .x86_64 or
1057 test_target.target.getObjectFormat() != .elf) and
1059 if ((target.cpu.arch != .x86_64 or target.ofmt != .elf) and
10581060 test_target.use_llvm == false and mem.eql(u8, options.name, "compiler-rt"))
10591061 continue;
10601062
10611063 // TODO get compiler-rt tests passing for wasm32-wasi
10621064 // currently causes "LLVM ERROR: Unable to expand fixed point multiplication."
1063 if (test_target.target.getCpuArch() == .wasm32 and
1064 test_target.target.getOsTag() == .wasi and
1065 if (target.cpu.arch == .wasm32 and target.os.tag == .wasi and
10651066 mem.eql(u8, options.name, "compiler-rt"))
10661067 {
10671068 continue;
10681069 }
10691070
10701071 // TODO get universal-libc tests passing for other self-hosted backends.
1071 if (test_target.target.getCpuArch() != .x86_64 and
1072 if (target.cpu.arch != .x86_64 and
10721073 test_target.use_llvm == false and mem.eql(u8, options.name, "universal-libc"))
10731074 continue;
10741075
10751076 // TODO get std lib tests passing for other self-hosted backends.
1076 if ((test_target.target.getCpuArch() != .x86_64 or
1077 test_target.target.getOsTag() != .linux) and
1077 if ((target.cpu.arch != .x86_64 or target.os.tag != .linux) and
10781078 test_target.use_llvm == false and mem.eql(u8, options.name, "std"))
10791079 continue;
10801080
1081 if (test_target.target.getCpuArch() == .x86_64 and
1082 test_target.target.getOsTag() == .windows and
1083 test_target.target.cpu_arch == null and
1084 test_target.optimize_mode != .Debug and
1081 if (target.cpu.arch == .x86_64 and target.os.tag == .windows and
1082 test_target.target.cpu_arch == null and test_target.optimize_mode != .Debug and
10851083 mem.eql(u8, options.name, "std"))
10861084 {
10871085 // https://github.com/ziglang/zig/issues/17902
......@@ -1094,11 +1092,11 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
10941092 if (!want_this_mode) continue;
10951093
10961094 const libc_suffix = if (test_target.link_libc == true) "-libc" else "";
1097 const triple_txt = test_target.target.zigTriple(b.allocator) catch @panic("OOM");
1098 const model_txt = test_target.target.getCpuModel().name;
1095 const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM");
1096 const model_txt = target.cpu.model.name;
10991097
11001098 // wasm32-wasi builds need more RAM, idk why
1101 const max_rss = if (test_target.target.getOs().tag == .wasi)
1099 const max_rss = if (target.os.tag == .wasi)
11021100 options.max_rss * 2
11031101 else
11041102 options.max_rss;
......@@ -1106,7 +1104,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
11061104 const these_tests = b.addTest(.{
11071105 .root_source_file = .{ .path = options.root_src },
11081106 .optimize = test_target.optimize_mode,
1109 .target = b.resolveTargetQuery(test_target.target),
1107 .target = resolved_target,
11101108 .max_rss = max_rss,
11111109 .filter = options.test_filter,
11121110 .link_libc = test_target.link_libc,
......@@ -1120,7 +1118,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
11201118 const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else "";
11211119 const backend_suffix = if (test_target.use_llvm == true)
11221120 "-llvm"
1123 else if (test_target.target.ofmt == std.Target.ObjectFormat.c)
1121 else if (target.ofmt == std.Target.ObjectFormat.c)
11241122 "-cbe"
11251123 else if (test_target.use_llvm == false)
11261124 "-selfhosted"
......@@ -1131,7 +1129,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
11311129
11321130 these_tests.addIncludePath(.{ .path = "test" });
11331131
1134 if (test_target.target.getOs().tag == .wasi) {
1132 if (target.os.tag == .wasi) {
11351133 // WASI's default stack size can be too small for some big tests.
11361134 these_tests.stack_size = 2 * 1024 * 1024;
11371135 }
......@@ -1148,14 +1146,14 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
11481146 use_pic,
11491147 });
11501148
1151 if (test_target.target.ofmt == std.Target.ObjectFormat.c) {
1152 var altered_target = test_target.target;
1153 altered_target.ofmt = null;
1149 if (target.ofmt == std.Target.ObjectFormat.c) {
1150 var altered_query = test_target.target;
1151 altered_query.ofmt = null;
11541152
11551153 const compile_c = b.addExecutable(.{
11561154 .name = qualified_name,
11571155 .link_libc = test_target.link_libc,
1158 .target = b.resolveTargetQuery(altered_target),
1156 .target = b.resolveTargetQuery(altered_query),
11591157 .zig_lib_dir = .{ .path = "lib" },
11601158 });
11611159 compile_c.addCSourceFile(.{
......@@ -1179,7 +1177,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
11791177 },
11801178 });
11811179 compile_c.addIncludePath(.{ .path = "lib" }); // for zig.h
1182 if (test_target.target.getOsTag() == .windows) {
1180 if (target.os.tag == .windows) {
11831181 if (true) {
11841182 // Unfortunately this requires about 8G of RAM for clang to compile
11851183 // and our Windows CI runners do not have this much.