commit 2b11859a1049910a2bd8031e53c24beea305ae10 (tree)
parent 3e6bebbbca2acdcde7578c12e618cbcea233dc49
Author: Andrew Kelley <andrew@ziglang.org>
Date: Mon, 16 Feb 2026 16:16:23 -0800
configure runner: implement builderToPackage
Diffstat:
2 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/lib/compiler/configure_runner.zig b/lib/compiler/configure_runner.zig
@@ -524,7 +524,7 @@ fn addModule(
.link_libcpp = .init(m.strip),
.no_builtin = .init(m.strip),
},
- .owner = builderToPackage(m.owner),
+ .owner = try builderToPackage(wc, m.owner),
.root_source_file = try addOptionalLazyPath(wc, m.root_source_file),
.import_table = import_table,
.resolved_target = try addOptionalResolvedTarget(wc, m.resolved_target),
@@ -555,7 +555,7 @@ fn addOptionalLazyPath(wc: *Configuration.Wip, lp: ?std.Build.LazyPath) !Configu
const sub_path = try wc.addString(src_path.sub_path);
break :i try wc.addExtra(@as(Configuration.LazyPath.SourcePath, .{
.flags = .{},
- .owner = builderToPackage(src_path.owner),
+ .owner = try builderToPackage(wc, src_path.owner),
.sub_path = sub_path,
}));
},
@@ -577,16 +577,16 @@ fn addOptionalLazyPath(wc: *Configuration.Wip, lp: ?std.Build.LazyPath) !Configu
const sub_path = try wc.addString(dependency.sub_path);
break :i try wc.addExtra(@as(Configuration.LazyPath.SourcePath, .{
.flags = .{},
- .owner = builderToPackage(dependency.dependency.builder),
+ .owner = try builderToPackage(wc, dependency.dependency.builder),
.sub_path = sub_path,
}));
},
});
}
-fn builderToPackage(b: *std.Build) Configuration.Package.Index {
- _ = b;
- @panic("TODO");
+fn builderToPackage(wc: *Configuration.Wip, b: *std.Build) !Configuration.Package {
+ if (b.pkg_hash.len == 0) return .root;
+ return .fromHash(try wc.addString(b.pkg_hash));
}
fn addInstallDir(wc: *Configuration.Wip, install_dir: ?std.Build.InstallDir) !Configuration.InstallDir {
diff --git a/lib/std/zig/Configuration.zig b/lib/std/zig/Configuration.zig
@@ -786,7 +786,7 @@ pub const LazyPath = enum(u32) {
pub const SourcePath = struct {
flags: Flags,
- owner: Package.Index,
+ owner: Package,
sub_path: String,
pub const Flags = packed struct(u32) {
@@ -822,14 +822,16 @@ pub const LazyPath = enum(u32) {
};
};
-pub const Package = extern struct {
- hash: String,
- build_root: OptionalString,
+/// It's an OptionalString which points to the package hash.
+pub const Package = enum(u32) {
+ root = maxInt(u32),
+ _,
- pub const Index = enum(u32) {
- root = maxInt(u32),
- _,
- };
+ pub fn fromHash(hash: String) Package {
+ const result: Package = @enumFromInt(@intFromEnum(hash));
+ assert(result != .root);
+ return result;
+ }
};
/// Trailing:
@@ -843,7 +845,7 @@ pub const Package = extern struct {
pub const Module = struct {
flags: Flags,
flags2: Flags2,
- owner: Package.Index,
+ owner: Package,
root_source_file: OptionalLazyPath,
import_table: ImportTable,
resolved_target: ResolvedTarget.OptionalIndex,