authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-05-10 11:34:19+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-05-18 17:10:04+01:00
log6d7c89cb40e3a36f99c82400084aa59df27f6573
tree9674c4ab45a5c1c2e984e5528cd23e7e5dc35239
parente26c326996c315a6ed912a2d5fbe7a4f04982c69
signature Commit is signed but in an unrecognized format.

build.zig: use correct module graph for compiler unit tests


1 files changed, 11 insertions(+), 6 deletions(-)

build.zig+11-6
...@@ -508,11 +508,9 @@ pub fn build(b: *std.Build) !void {...@@ -508,11 +508,9 @@ pub fn build(b: *std.Build) !void {
508 test_step.dependOn(unit_tests_step);508 test_step.dependOn(unit_tests_step);
509509
510 const unit_tests = b.addTest(.{510 const unit_tests = b.addTest(.{
511 .root_module = b.createModule(.{511 .root_module = addCompilerMod(b, .{
512 .root_source_file = b.path("src/main.zig"),
513 .optimize = optimize,512 .optimize = optimize,
514 .target = target,513 .target = target,
515 .link_libc = link_libc,
516 .single_threaded = single_threaded,514 .single_threaded = single_threaded,
517 }),515 }),
518 .filters = test_filters,516 .filters = test_filters,
...@@ -520,6 +518,9 @@ pub fn build(b: *std.Build) !void {...@@ -520,6 +518,9 @@ pub fn build(b: *std.Build) !void {
520 .use_lld = use_llvm,518 .use_lld = use_llvm,
521 .zig_lib_dir = b.path("lib"),519 .zig_lib_dir = b.path("lib"),
522 });520 });
521 if (link_libc) {
522 unit_tests.root_module.link_libc = true;
523 }
523 unit_tests.root_module.addOptions("build_options", exe_options);524 unit_tests.root_module.addOptions("build_options", exe_options);
524 unit_tests_step.dependOn(&b.addRunArtifact(unit_tests).step);525 unit_tests_step.dependOn(&b.addRunArtifact(unit_tests).step);
525526
...@@ -650,7 +651,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {...@@ -650,7 +651,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
650 update_zig1_step.dependOn(&copy_zig_h.step);651 update_zig1_step.dependOn(&copy_zig_h.step);
651}652}
652653
653const AddCompilerStepOptions = struct {654const AddCompilerModOptions = struct {
654 optimize: std.builtin.OptimizeMode,655 optimize: std.builtin.OptimizeMode,
655 target: std.Build.ResolvedTarget,656 target: std.Build.ResolvedTarget,
656 strip: ?bool = null,657 strip: ?bool = null,
...@@ -659,7 +660,7 @@ const AddCompilerStepOptions = struct {...@@ -659,7 +660,7 @@ const AddCompilerStepOptions = struct {
659 single_threaded: ?bool = null,660 single_threaded: ?bool = null,
660};661};
661662
662fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.Step.Compile {663fn addCompilerMod(b: *std.Build, options: AddCompilerModOptions) *std.Build.Module {
663 const compiler_mod = b.createModule(.{664 const compiler_mod = b.createModule(.{
664 .root_source_file = b.path("src/main.zig"),665 .root_source_file = b.path("src/main.zig"),
665 .target = options.target,666 .target = options.target,
...@@ -682,10 +683,14 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St...@@ -682,10 +683,14 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St
682 compiler_mod.addImport("aro", aro_mod);683 compiler_mod.addImport("aro", aro_mod);
683 compiler_mod.addImport("aro_translate_c", aro_translate_c_mod);684 compiler_mod.addImport("aro_translate_c", aro_translate_c_mod);
684685
686 return compiler_mod;
687}
688
689fn addCompilerStep(b: *std.Build, options: AddCompilerModOptions) *std.Build.Step.Compile {
685 const exe = b.addExecutable(.{690 const exe = b.addExecutable(.{
686 .name = "zig",691 .name = "zig",
687 .max_rss = 7_800_000_000,692 .max_rss = 7_800_000_000,
688 .root_module = compiler_mod,693 .root_module = addCompilerMod(b, options),
689 });694 });
690 exe.stack_size = stack_size;695 exe.stack_size = stack_size;
691696