diff --git a/build.zig b/build.zig index f57080a5c9..a6285c85f1 100644 --- a/build.zig +++ b/build.zig @@ -442,7 +442,7 @@ pub fn build(b: *std.Build) !void { test_step.dependOn(check_fmt); const test_cases_step = b.step("test-cases", "Run the main compiler test cases"); - try tests.addCases(b, test_cases_step, test_filters, target, .{ + try tests.addCases(b, test_cases_step, test_filters, test_target_filters, target, .{ .skip_translate_c = skip_translate_c, .skip_run_translated_c = skip_run_translated_c, }, .{ diff --git a/test/src/Cases.zig b/test/src/Cases.zig index 9314b5677b..bc5e2c25bc 100644 --- a/test/src/Cases.zig +++ b/test/src/Cases.zig @@ -539,13 +539,14 @@ pub fn lowerToTranslateCSteps( b: *std.Build, parent_step: *std.Build.Step, test_filters: []const []const u8, + test_target_filters: []const []const u8, target: std.Build.ResolvedTarget, translate_c_options: TranslateCOptions, ) void { const tests = @import("../tests.zig"); const test_translate_c_step = b.step("test-translate-c", "Run the C translation tests"); if (!translate_c_options.skip_translate_c) { - tests.addTranslateCTests(b, test_translate_c_step, test_filters); + tests.addTranslateCTests(b, test_translate_c_step, test_filters, test_target_filters); parent_step.dependOn(test_translate_c_step); } @@ -620,6 +621,7 @@ pub fn lowerToBuildSteps( b: *std.Build, parent_step: *std.Build.Step, test_filters: []const []const u8, + test_target_filters: []const []const u8, ) void { const host = std.zig.system.resolveTargetQuery(.{}) catch |err| std.debug.panic("unable to detect native host: {s}\n", .{@errorName(err)}); @@ -648,6 +650,14 @@ 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"); + + if (test_target_filters.len > 0) { + for (test_target_filters) |filter| { + if (std.mem.indexOf(u8, triple_txt, filter) != null) break; + } else continue; + } + const writefiles = b.addWriteFiles(); var file_sources = std.StringHashMap(std.Build.LazyPath).init(b.allocator); defer file_sources.deinit(); @@ -740,7 +750,7 @@ pub fn lowerToBuildSteps( "--", "-lc", "-target", - case.target.result.zigTriple(b.allocator) catch @panic("OOM"), + triple_txt, }); run_c.addArtifactArg(artifact); break :run_step run_c; diff --git a/test/src/TranslateC.zig b/test/src/TranslateC.zig index c4cadcef5b..18d5e1ce50 100644 --- a/test/src/TranslateC.zig +++ b/test/src/TranslateC.zig @@ -2,6 +2,7 @@ b: *std.Build, step: *std.Build.Step, test_index: usize, test_filters: []const []const u8, +test_target_filters: []const []const u8, const TestCase = struct { name: []const u8, @@ -92,6 +93,16 @@ pub fn addCase(self: *TranslateCContext, case: *const TestCase) void { if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; } else if (self.test_filters.len > 0) return; + const target = b.resolveTargetQuery(case.target); + + if (self.test_target_filters.len > 0) { + const triple_txt = target.result.zigTriple(b.allocator) catch @panic("OOM"); + + for (self.test_target_filters) |filter| { + if (std.mem.indexOf(u8, triple_txt, filter) != null) break; + } else return; + } + const write_src = b.addWriteFiles(); const first_src = case.sources.items[0]; const root_source_file = write_src.add(first_src.filename, first_src.source); @@ -101,7 +112,7 @@ pub fn addCase(self: *TranslateCContext, case: *const TestCase) void { const translate_c = b.addTranslateC(.{ .root_source_file = root_source_file, - .target = b.resolveTargetQuery(case.target), + .target = target, .optimize = .Debug, }); diff --git a/test/tests.zig b/test/tests.zig index 666c5a115d..ac23bac754 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -1237,18 +1237,22 @@ pub fn addAssembleAndLinkTests(b: *std.Build, test_filters: []const []const u8, return cases.step; } -pub fn addTranslateCTests(b: *std.Build, parent_step: *std.Build.Step, test_filters: []const []const u8) void { +pub fn addTranslateCTests( + b: *std.Build, + parent_step: *std.Build.Step, + test_filters: []const []const u8, + test_target_filters: []const []const u8, +) void { const cases = b.allocator.create(TranslateCContext) catch @panic("OOM"); cases.* = TranslateCContext{ .b = b, .step = parent_step, .test_index = 0, .test_filters = test_filters, + .test_target_filters = test_target_filters, }; translate_c.addCases(cases); - - return; } pub fn addRunTranslatedCTests( @@ -1267,8 +1271,6 @@ pub fn addRunTranslatedCTests( }; run_translated_c.addCases(cases); - - return; } const ModuleTestOptions = struct { @@ -1565,6 +1567,7 @@ pub fn addCases( b: *std.Build, parent_step: *Step, test_filters: []const []const u8, + test_target_filters: []const []const u8, target: std.Build.ResolvedTarget, translate_c_options: @import("src/Cases.zig").TranslateCOptions, build_options: @import("cases.zig").BuildOptions, @@ -1580,12 +1583,13 @@ pub fn addCases( cases.addFromDir(dir, b); try @import("cases.zig").addCases(&cases, build_options, b); - cases.lowerToTranslateCSteps(b, parent_step, test_filters, target, translate_c_options); + cases.lowerToTranslateCSteps(b, parent_step, test_filters, test_target_filters, target, translate_c_options); cases.lowerToBuildSteps( b, parent_step, test_filters, + test_target_filters, ); }