From faafeb51afb9edf5a1f11cb3ab1f9091f07344c7 Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 18 Jun 2024 19:53:55 +0500 Subject: [PATCH] std.Build.Step.Compile: change `root_module` field type to `*Module` This commit changes the `root_module` field of `std.Build.Step.Compile` to be a `*Module` rather than a `Module`. This is a breaking change, but an incredibly minor one (the full potential extent of the breakage can be seen in the modified standalone test). This change will be necessary for an upcoming improvement, so it was convenient to make it here. --- lib/std/Build/Module.zig | 2 +- lib/std/Build/Step/Compile.zig | 8 +++++--- lib/std/Build/Step/Run.zig | 2 +- test/standalone/depend_on_main_mod/build.zig | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig index 0e421280f0..cc7c5a65c0 100644 --- a/lib/std/Build/Module.zig +++ b/lib/std/Build/Module.zig @@ -430,7 +430,7 @@ pub const DependencyIterator = struct { if (!it.chase_dyn_libs and compile.isDynamicLibrary()) continue; it.set.put(it.allocator, .{ - .module = &compile.root_module, + .module = compile.root_module, .compile = compile, }, "root") catch @panic("OOM"); }, diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index a85a67bd9b..cdb0ddeb0c 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -22,7 +22,7 @@ const Path = std.Build.Cache.Path; pub const base_id: Step.Id = .compile; step: Step, -root_module: Module, +root_module: *Module, name: []const u8, linker_script: ?LazyPath = null, @@ -432,7 +432,9 @@ pub fn create(owner: *std.Build, options: Options) *Compile { .zig_process = null, }; - compile.root_module.init(owner, options.root_module, compile); + const root_module = owner.allocator.create(Module) catch @panic("OOM"); + root_module.init(owner, options.root_module, compile); + compile.root_module = root_module; if (options.zig_lib_dir) |lp| { compile.zig_lib_dir = lp.dupe(compile.step.owner); @@ -1089,7 +1091,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 { } } - var cli_named_modules = try CliNamedModules.init(arena, &compile.root_module); + var cli_named_modules = try CliNamedModules.init(arena, compile.root_module); // For this loop, don't chase dynamic libraries because their link // objects are already linked. diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index 270090d07c..5408bb287b 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -1722,7 +1722,7 @@ fn addPathForDynLibs(run: *Run, artifact: *Step.Compile) void { var it = artifact.root_module.iterateDependencies(artifact, true); while (it.next()) |item| { const other = item.compile.?; - if (item.module == &other.root_module) { + if (item.module == other.root_module) { if (item.module.resolved_target.?.result.os.tag == .windows and other.isDynamicLibrary()) { diff --git a/test/standalone/depend_on_main_mod/build.zig b/test/standalone/depend_on_main_mod/build.zig index 42e96e0aa0..ae1dc8fb75 100644 --- a/test/standalone/depend_on_main_mod/build.zig +++ b/test/standalone/depend_on_main_mod/build.zig @@ -18,7 +18,7 @@ pub fn build(b: *std.Build) void { .root_source_file = b.path("src/foo.zig"), }); - foo_module.addImport("root2", &exe.root_module); + foo_module.addImport("root2", exe.root_module); exe.root_module.addImport("foo", foo_module); const run_cmd = b.addRunArtifact(exe);