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.
This commit is contained in:
Jacob Young 2025-06-13 05:46:15 -04:00
parent f5a327cd36
commit df4068cabd
9 changed files with 31 additions and 21 deletions

View File

@ -1164,7 +1164,14 @@ pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run {
// It doesn't have to be native. We catch that if you actually try to run it.
// Consider that this is declarative; the run step may not be run unless a user
// option is supplied.
const run_step = Step.Run.create(b, b.fmt("run {s}", .{exe.name}));
// Avoid the common case of the step name looking like "run test test".
const step_name = if (exe.kind.isTest() and mem.eql(u8, exe.name, "test"))
b.fmt("run {s}", .{@tagName(exe.kind)})
else
b.fmt("run {s} {s}", .{ @tagName(exe.kind), exe.name });
const run_step = Step.Run.create(b, step_name);
run_step.producer = exe;
if (exe.kind == .@"test") {
if (exe.exec_cmd_args) |exec_cmd_args| {

View File

@ -292,6 +292,13 @@ pub const Kind = enum {
obj,
@"test",
test_obj,
pub fn isTest(kind: Kind) bool {
return switch (kind) {
.exe, .lib, .obj => false,
.@"test", .test_obj => true,
};
}
};
pub const HeaderInstallation = union(enum) {
@ -368,19 +375,16 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
}
// Avoid the common case of the step name looking like "zig test test".
const name_adjusted = if ((options.kind == .@"test" or options.kind == .test_obj) and mem.eql(u8, name, "test"))
""
else
owner.fmt("{s} ", .{name});
const resolved_target = options.root_module.resolved_target orelse
@panic("the root Module of a Compile step must be created with a known 'target' field");
const target = resolved_target.result;
const step_name = owner.fmt("compile {s} {s}{s} {s}", .{
@tagName(options.kind),
name_adjusted,
const step_name = owner.fmt("compile {s} {s} {s}", .{
// Avoid the common case of the step name looking like "compile test test".
if (options.kind.isTest() and mem.eql(u8, name, "test"))
@tagName(options.kind)
else
owner.fmt("{s} {s}", .{ @tagName(options.kind), name }),
@tagName(options.root_module.optimize orelse .Debug),
resolved_target.query.zigTriple(owner.allocator) catch @panic("OOM"),
});

View File

@ -115,6 +115,7 @@ pub fn build(b: *std.Build) void {
},
}) |query| {
const target = b.resolveTargetQuery(query);
const triple = query.zigTriple(b.allocator) catch @panic("OOM");
const cpu = query.serializeCpuAlloc(b.allocator) catch @panic("OOM");
for ([_][]const u8{
"access.zig",
@ -133,16 +134,14 @@ pub fn build(b: *std.Build) void {
.use_lld = false,
.root_module = test_mod,
});
test_exe.step.name = b.fmt("{s} {s}", .{ test_exe.step.name, cpu });
if (!target.result.cpu.has(.x86, .sse2)) {
test_exe.bundle_compiler_rt = false;
test_mod.linkLibrary(compiler_rt_lib);
}
const test_run = b.addRunArtifact(test_exe);
test_run.step.name = b.fmt("{s} {s} {s}", .{ test_run.step.name, triple, cpu });
b.default_step.dependOn(&test_run.step);
for ([_]*std.Build.Step{
&test_exe.step,
&test_run.step,
}) |step| step.name = b.fmt("{s} {s}", .{ step.name, cpu });
}
}
}

View File

@ -13,7 +13,7 @@ pub const Options = struct {
};
pub fn addTestStep(b: *Build, prefix: []const u8, opts: Options) *Step {
const target = opts.target.result.zigTriple(b.allocator) catch @panic("OOM");
const target = opts.target.query.zigTriple(b.allocator) catch @panic("OOM");
const optimize = @tagName(opts.optimize);
const use_llvm = if (opts.use_llvm) "llvm" else "no-llvm";
const use_lld = if (opts.use_lld) "lld" else "no-lld";

View File

@ -610,7 +610,7 @@ pub fn lowerToBuildSteps(
if (std.mem.indexOf(u8, case.name, test_filter)) |_| break;
} else if (test_filters.len > 0) continue;
const triple_txt = case.target.result.zigTriple(b.allocator) catch @panic("OOM");
const triple_txt = case.target.query.zigTriple(b.allocator) catch @panic("OOM");
if (test_target_filters.len > 0) {
for (test_target_filters) |filter| {

View File

@ -2447,7 +2447,7 @@ fn addTest(
} else return;
}
if (db.options.test_target_filters.len > 0) {
const triple_txt = target.resolved.result.zigTriple(db.b.allocator) catch @panic("OOM");
const triple_txt = target.resolved.query.zigTriple(db.b.allocator) catch @panic("OOM");
for (db.options.test_target_filters) |filter| {
if (std.mem.indexOf(u8, triple_txt, filter) != null) break;
} else return;

View File

@ -75,7 +75,7 @@ pub fn addExact(
pub fn addCase(self: *LlvmIr, case: TestCase) void {
const target = self.b.resolveTargetQuery(case.params.target);
if (self.options.test_target_filters.len > 0) {
const triple_txt = target.result.zigTriple(self.b.allocator) catch @panic("OOM");
const triple_txt = target.query.zigTriple(self.b.allocator) catch @panic("OOM");
for (self.options.test_target_filters) |filter| {
if (std.mem.indexOf(u8, triple_txt, filter) != null) break;
} else return;

View File

@ -96,7 +96,7 @@ pub fn addCase(self: *TranslateCContext, case: *const TestCase) void {
const target = b.resolveTargetQuery(case.target);
if (self.test_target_filters.len > 0) {
const triple_txt = target.result.zigTriple(b.allocator) catch @panic("OOM");
const triple_txt = target.query.zigTriple(b.allocator) catch @panic("OOM");
for (self.test_target_filters) |filter| {
if (std.mem.indexOf(u8, triple_txt, filter) != null) break;

View File

@ -2310,8 +2310,8 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
if (options.skip_llvm and would_use_llvm) continue;
const resolved_target = b.resolveTargetQuery(test_target.target);
const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
const target = resolved_target.result;
const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM");
if (options.test_target_filters.len > 0) {
for (options.test_target_filters) |filter| {
@ -2556,8 +2556,8 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
if (options.skip_llvm and would_use_llvm) continue;
const resolved_target = b.resolveTargetQuery(c_abi_target.target);
const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
const target = resolved_target.result;
const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM");
if (options.test_target_filters.len > 0) {
for (options.test_target_filters) |filter| {