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.
This commit is contained in:
mlugg 2024-06-18 19:53:55 +05:00 committed by Eric Joldasov
parent 3d393dba6f
commit faafeb51af
No known key found for this signature in database
GPG Key ID: 5C9C69060686B588
4 changed files with 8 additions and 6 deletions

View File

@ -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");
},

View File

@ -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.

View File

@ -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())
{

View File

@ -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);