authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-18 19:53:55+05:00
committergravatar for bratishkaerik@landless-city.netEric Joldasov <bratishkaerik@landless-city.net> 2024-12-18 01:47:50+05:00
logfaafeb51afb9edf5a1f11cb3ab1f9091f07344c7
treebc6c51c3e6f5311847f7830c7175f06be9d384a3
parent3d393dba6fc06cea3508aaa3db9d49042663367e
signaturelock-open Commit is signed but in an unrecognized format.

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.

4 files changed, 8 insertions(+), 6 deletions(-)

lib/std/Build/Module.zig+1-1
...@@ -430,7 +430,7 @@ pub const DependencyIterator = struct {...@@ -430,7 +430,7 @@ pub const DependencyIterator = struct {
430 if (!it.chase_dyn_libs and compile.isDynamicLibrary()) continue;430 if (!it.chase_dyn_libs and compile.isDynamicLibrary()) continue;
431431
432 it.set.put(it.allocator, .{432 it.set.put(it.allocator, .{
433 .module = &compile.root_module,433 .module = compile.root_module,
434 .compile = compile,434 .compile = compile,
435 }, "root") catch @panic("OOM");435 }, "root") catch @panic("OOM");
436 },436 },
lib/std/Build/Step/Compile.zig+5-3
...@@ -22,7 +22,7 @@ const Path = std.Build.Cache.Path;...@@ -22,7 +22,7 @@ const Path = std.Build.Cache.Path;
22pub const base_id: Step.Id = .compile;22pub const base_id: Step.Id = .compile;
2323
24step: Step,24step: Step,
25root_module: Module,25root_module: *Module,
2626
27name: []const u8,27name: []const u8,
28linker_script: ?LazyPath = null,28linker_script: ?LazyPath = null,
...@@ -432,7 +432,9 @@ pub fn create(owner: *std.Build, options: Options) *Compile {...@@ -432,7 +432,9 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
432 .zig_process = null,432 .zig_process = null,
433 };433 };
434434
435 compile.root_module.init(owner, options.root_module, compile);435 const root_module = owner.allocator.create(Module) catch @panic("OOM");
436 root_module.init(owner, options.root_module, compile);
437 compile.root_module = root_module;
436438
437 if (options.zig_lib_dir) |lp| {439 if (options.zig_lib_dir) |lp| {
438 compile.zig_lib_dir = lp.dupe(compile.step.owner);440 compile.zig_lib_dir = lp.dupe(compile.step.owner);
...@@ -1089,7 +1091,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {...@@ -1089,7 +1091,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
1089 }1091 }
1090 }1092 }
10911093
1092 var cli_named_modules = try CliNamedModules.init(arena, &compile.root_module);1094 var cli_named_modules = try CliNamedModules.init(arena, compile.root_module);
10931095
1094 // For this loop, don't chase dynamic libraries because their link1096 // For this loop, don't chase dynamic libraries because their link
1095 // objects are already linked.1097 // objects are already linked.
lib/std/Build/Step/Run.zig+1-1
...@@ -1722,7 +1722,7 @@ fn addPathForDynLibs(run: *Run, artifact: *Step.Compile) void {...@@ -1722,7 +1722,7 @@ fn addPathForDynLibs(run: *Run, artifact: *Step.Compile) void {
1722 var it = artifact.root_module.iterateDependencies(artifact, true);1722 var it = artifact.root_module.iterateDependencies(artifact, true);
1723 while (it.next()) |item| {1723 while (it.next()) |item| {
1724 const other = item.compile.?;1724 const other = item.compile.?;
1725 if (item.module == &other.root_module) {1725 if (item.module == other.root_module) {
1726 if (item.module.resolved_target.?.result.os.tag == .windows and1726 if (item.module.resolved_target.?.result.os.tag == .windows and
1727 other.isDynamicLibrary())1727 other.isDynamicLibrary())
1728 {1728 {
test/standalone/depend_on_main_mod/build.zig+1-1
...@@ -18,7 +18,7 @@ pub fn build(b: *std.Build) void {...@@ -18,7 +18,7 @@ pub fn build(b: *std.Build) void {
18 .root_source_file = b.path("src/foo.zig"),18 .root_source_file = b.path("src/foo.zig"),
19 });19 });
2020
21 foo_module.addImport("root2", &exe.root_module);21 foo_module.addImport("root2", exe.root_module);
22 exe.root_module.addImport("foo", foo_module);22 exe.root_module.addImport("foo", foo_module);
2323
24 const run_cmd = b.addRunArtifact(exe);24 const run_cmd = b.addRunArtifact(exe);