authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-06-13 05:46:15-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-06-19 11:45:06-04:00
logdf4068cabd9af96d0aca1f435b985d1c103976da
treee4bb7429476548679a3ed9138bd25aac60681364
parentf5a327cd366348a739a282f380acd627815183b5

Build: change how the target is printed in step names

e.g. `x86_64-windows.win10...win11_dt-gnu` -> `x86_64-windows-gnu` When the OS version is the default this is redundant with checking the default in the standard library.

9 files changed, 31 insertions(+), 21 deletions(-)

lib/std/Build.zig+8-1
......@@ -1164,7 +1164,14 @@ pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run {
11641164 // It doesn't have to be native. We catch that if you actually try to run it.
11651165 // Consider that this is declarative; the run step may not be run unless a user
11661166 // option is supplied.
1167 const run_step = Step.Run.create(b, b.fmt("run {s}", .{exe.name}));
1167
1168 // Avoid the common case of the step name looking like "run test test".
1169 const step_name = if (exe.kind.isTest() and mem.eql(u8, exe.name, "test"))
1170 b.fmt("run {s}", .{@tagName(exe.kind)})
1171 else
1172 b.fmt("run {s} {s}", .{ @tagName(exe.kind), exe.name });
1173
1174 const run_step = Step.Run.create(b, step_name);
11681175 run_step.producer = exe;
11691176 if (exe.kind == .@"test") {
11701177 if (exe.exec_cmd_args) |exec_cmd_args| {
lib/std/Build/Step/Compile.zig+13-9
......@@ -292,6 +292,13 @@ pub const Kind = enum {
292292 obj,
293293 @"test",
294294 test_obj,
295
296 pub fn isTest(kind: Kind) bool {
297 return switch (kind) {
298 .exe, .lib, .obj => false,
299 .@"test", .test_obj => true,
300 };
301 }
295302};
296303
297304pub const HeaderInstallation = union(enum) {
......@@ -368,19 +375,16 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
368375 panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
369376 }
370377
371 // Avoid the common case of the step name looking like "zig test test".
372 const name_adjusted = if ((options.kind == .@"test" or options.kind == .test_obj) and mem.eql(u8, name, "test"))
373 ""
374 else
375 owner.fmt("{s} ", .{name});
376
377378 const resolved_target = options.root_module.resolved_target orelse
378379 @panic("the root Module of a Compile step must be created with a known 'target' field");
379380 const target = resolved_target.result;
380381
381 const step_name = owner.fmt("compile {s} {s}{s} {s}", .{
382 @tagName(options.kind),
383 name_adjusted,
382 const step_name = owner.fmt("compile {s} {s} {s}", .{
383 // Avoid the common case of the step name looking like "compile test test".
384 if (options.kind.isTest() and mem.eql(u8, name, "test"))
385 @tagName(options.kind)
386 else
387 owner.fmt("{s} {s}", .{ @tagName(options.kind), name }),
384388 @tagName(options.root_module.optimize orelse .Debug),
385389 resolved_target.query.zigTriple(owner.allocator) catch @panic("OOM"),
386390 });
test/behavior/x86_64/build.zig+3-4
......@@ -115,6 +115,7 @@ pub fn build(b: *std.Build) void {
115115 },
116116 }) |query| {
117117 const target = b.resolveTargetQuery(query);
118 const triple = query.zigTriple(b.allocator) catch @panic("OOM");
118119 const cpu = query.serializeCpuAlloc(b.allocator) catch @panic("OOM");
119120 for ([_][]const u8{
120121 "access.zig",
......@@ -133,16 +134,14 @@ pub fn build(b: *std.Build) void {
133134 .use_lld = false,
134135 .root_module = test_mod,
135136 });
137 test_exe.step.name = b.fmt("{s} {s}", .{ test_exe.step.name, cpu });
136138 if (!target.result.cpu.has(.x86, .sse2)) {
137139 test_exe.bundle_compiler_rt = false;
138140 test_mod.linkLibrary(compiler_rt_lib);
139141 }
140142 const test_run = b.addRunArtifact(test_exe);
143 test_run.step.name = b.fmt("{s} {s} {s}", .{ test_run.step.name, triple, cpu });
141144 b.default_step.dependOn(&test_run.step);
142 for ([_]*std.Build.Step{
143 &test_exe.step,
144 &test_run.step,
145 }) |step| step.name = b.fmt("{s} {s}", .{ step.name, cpu });
146145 }
147146 }
148147}
test/link/link.zig+1-1
......@@ -13,7 +13,7 @@ pub const Options = struct {
1313};
1414
1515pub fn addTestStep(b: *Build, prefix: []const u8, opts: Options) *Step {
16 const target = opts.target.result.zigTriple(b.allocator) catch @panic("OOM");
16 const target = opts.target.query.zigTriple(b.allocator) catch @panic("OOM");
1717 const optimize = @tagName(opts.optimize);
1818 const use_llvm = if (opts.use_llvm) "llvm" else "no-llvm";
1919 const use_lld = if (opts.use_lld) "lld" else "no-lld";
test/src/Cases.zig+1-1
......@@ -610,7 +610,7 @@ pub fn lowerToBuildSteps(
610610 if (std.mem.indexOf(u8, case.name, test_filter)) |_| break;
611611 } else if (test_filters.len > 0) continue;
612612
613 const triple_txt = case.target.result.zigTriple(b.allocator) catch @panic("OOM");
613 const triple_txt = case.target.query.zigTriple(b.allocator) catch @panic("OOM");
614614
615615 if (test_target_filters.len > 0) {
616616 for (test_target_filters) |filter| {
test/src/Debugger.zig+1-1
......@@ -2447,7 +2447,7 @@ fn addTest(
24472447 } else return;
24482448 }
24492449 if (db.options.test_target_filters.len > 0) {
2450 const triple_txt = target.resolved.result.zigTriple(db.b.allocator) catch @panic("OOM");
2450 const triple_txt = target.resolved.query.zigTriple(db.b.allocator) catch @panic("OOM");
24512451 for (db.options.test_target_filters) |filter| {
24522452 if (std.mem.indexOf(u8, triple_txt, filter) != null) break;
24532453 } else return;
test/src/LlvmIr.zig+1-1
......@@ -75,7 +75,7 @@ pub fn addExact(
7575pub fn addCase(self: *LlvmIr, case: TestCase) void {
7676 const target = self.b.resolveTargetQuery(case.params.target);
7777 if (self.options.test_target_filters.len > 0) {
78 const triple_txt = target.result.zigTriple(self.b.allocator) catch @panic("OOM");
78 const triple_txt = target.query.zigTriple(self.b.allocator) catch @panic("OOM");
7979 for (self.options.test_target_filters) |filter| {
8080 if (std.mem.indexOf(u8, triple_txt, filter) != null) break;
8181 } else return;
test/src/TranslateC.zig+1-1
......@@ -96,7 +96,7 @@ pub fn addCase(self: *TranslateCContext, case: *const TestCase) void {
9696 const target = b.resolveTargetQuery(case.target);
9797
9898 if (self.test_target_filters.len > 0) {
99 const triple_txt = target.result.zigTriple(b.allocator) catch @panic("OOM");
99 const triple_txt = target.query.zigTriple(b.allocator) catch @panic("OOM");
100100
101101 for (self.test_target_filters) |filter| {
102102 if (std.mem.indexOf(u8, triple_txt, filter) != null) break;
test/tests.zig+2-2
......@@ -2310,8 +2310,8 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
23102310 if (options.skip_llvm and would_use_llvm) continue;
23112311
23122312 const resolved_target = b.resolveTargetQuery(test_target.target);
2313 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
23132314 const target = resolved_target.result;
2314 const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM");
23152315
23162316 if (options.test_target_filters.len > 0) {
23172317 for (options.test_target_filters) |filter| {
......@@ -2556,8 +2556,8 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
25562556 if (options.skip_llvm and would_use_llvm) continue;
25572557
25582558 const resolved_target = b.resolveTargetQuery(c_abi_target.target);
2559 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
25592560 const target = resolved_target.result;
2560 const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM");
25612561
25622562 if (options.test_target_filters.len > 0) {
25632563 for (options.test_target_filters) |filter| {