From 6d7c89cb40e3a36f99c82400084aa59df27f6573 Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 10 May 2025 11:34:19 +0100 Subject: [PATCH] build.zig: use correct module graph for compiler unit tests --- build.zig | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/build.zig b/build.zig index 00c1254f38..ecc807616a 100644 --- a/build.zig +++ b/build.zig @@ -508,11 +508,9 @@ pub fn build(b: *std.Build) !void { test_step.dependOn(unit_tests_step); const unit_tests = b.addTest(.{ - .root_module = b.createModule(.{ - .root_source_file = b.path("src/main.zig"), + .root_module = addCompilerMod(b, .{ .optimize = optimize, .target = target, - .link_libc = link_libc, .single_threaded = single_threaded, }), .filters = test_filters, @@ -520,6 +518,9 @@ pub fn build(b: *std.Build) !void { .use_lld = use_llvm, .zig_lib_dir = b.path("lib"), }); + if (link_libc) { + unit_tests.root_module.link_libc = true; + } unit_tests.root_module.addOptions("build_options", exe_options); unit_tests_step.dependOn(&b.addRunArtifact(unit_tests).step); @@ -650,7 +651,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { update_zig1_step.dependOn(©_zig_h.step); } -const AddCompilerStepOptions = struct { +const AddCompilerModOptions = struct { optimize: std.builtin.OptimizeMode, target: std.Build.ResolvedTarget, strip: ?bool = null, @@ -659,7 +660,7 @@ const AddCompilerStepOptions = struct { single_threaded: ?bool = null, }; -fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.Step.Compile { +fn addCompilerMod(b: *std.Build, options: AddCompilerModOptions) *std.Build.Module { const compiler_mod = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = options.target, @@ -682,10 +683,14 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St compiler_mod.addImport("aro", aro_mod); compiler_mod.addImport("aro_translate_c", aro_translate_c_mod); + return compiler_mod; +} + +fn addCompilerStep(b: *std.Build, options: AddCompilerModOptions) *std.Build.Step.Compile { const exe = b.addExecutable(.{ .name = "zig", .max_rss = 7_800_000_000, - .root_module = compiler_mod, + .root_module = addCompilerMod(b, options), }); exe.stack_size = stack_size;