Skip to content

Commit

Permalink
std.Build: allow packages to expose arbitrary LazyPaths by name
Browse files Browse the repository at this point in the history
  • Loading branch information
mlugg authored and andrewrk committed Sep 16, 2024
1 parent 258236e commit 5d7fa55
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ dep_prefix: []const u8 = "",
modules: std.StringArrayHashMap(*Module),

named_writefiles: std.StringArrayHashMap(*Step.WriteFile),
named_lazy_paths: std.StringArrayHashMap(LazyPath),
/// A map from build root dirs to the corresponding `*Dependency`. This is shared with all child
/// `Build`s.
initialized_deps: *InitializedDepMap,
Expand Down Expand Up @@ -300,8 +301,9 @@ pub fn create(
.install_path = undefined,
.args = null,
.host = graph.host,
.modules = std.StringArrayHashMap(*Module).init(arena),
.named_writefiles = std.StringArrayHashMap(*Step.WriteFile).init(arena),
.modules = .init(arena),
.named_writefiles = .init(arena),
.named_lazy_paths = .init(arena),
.initialized_deps = initialized_deps,
.pkg_hash = "",
.available_deps = available_deps,
Expand Down Expand Up @@ -393,8 +395,9 @@ fn createChildOnly(
.glibc_runtimes_dir = parent.glibc_runtimes_dir,
.host = parent.host,
.dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }),
.modules = std.StringArrayHashMap(*Module).init(allocator),
.named_writefiles = std.StringArrayHashMap(*Step.WriteFile).init(allocator),
.modules = .init(allocator),
.named_writefiles = .init(allocator),
.named_lazy_paths = .init(allocator),
.initialized_deps = parent.initialized_deps,
.pkg_hash = pkg_hash,
.available_deps = pkg_deps,
Expand Down Expand Up @@ -1060,6 +1063,10 @@ pub fn addNamedWriteFiles(b: *Build, name: []const u8) *Step.WriteFile {
return wf;
}

pub fn addNamedLazyPath(b: *Build, name: []const u8, lp: LazyPath) void {
b.named_lazy_paths.put(b.dupe(name), lp.dupe(b)) catch @panic("OOM");
}

pub fn addWriteFiles(b: *Build) *Step.WriteFile {
return Step.WriteFile.create(b);
}
Expand Down Expand Up @@ -1902,6 +1909,12 @@ pub const Dependency = struct {
};
}

pub fn namedLazyPath(d: *Dependency, name: []const u8) LazyPath {
return d.builder.named_lazy_paths.get(name) orelse {
panic("unable to find named lazypath '{s}'", .{name});
};
}

pub fn path(d: *Dependency, sub_path: []const u8) LazyPath {
return .{
.dependency = .{
Expand Down

0 comments on commit 5d7fa55

Please sign in to comment.