Skip to content

Commit

Permalink
Build: add namedWriteFiles to Build
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoff-it authored and andrewrk committed Jan 17, 2024
1 parent fd43baa commit 4ace1f5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ host: ResolvedTarget,
dep_prefix: []const u8 = "",

modules: std.StringArrayHashMap(*Module),

named_writefiles: std.StringArrayHashMap(*Step.WriteFile),
/// 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 @@ -273,6 +275,7 @@ pub fn create(
.args = null,
.host = host,
.modules = std.StringArrayHashMap(*Module).init(allocator),
.named_writefiles = std.StringArrayHashMap(*Step.WriteFile).init(allocator),
.initialized_deps = initialized_deps,
.available_deps = available_deps,
};
Expand Down Expand Up @@ -360,6 +363,7 @@ fn createChildOnly(parent: *Build, dep_name: []const u8, build_root: Cache.Direc
.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),
.initialized_deps = parent.initialized_deps,
.available_deps = pkg_deps,
};
Expand Down Expand Up @@ -981,6 +985,12 @@ pub fn addWriteFile(self: *Build, file_path: []const u8, data: []const u8) *Step
return write_file_step;
}

pub fn addNamedWriteFiles(b: *Build, name: []const u8) *Step.WriteFile {
const wf = Step.WriteFile.create(b);
b.named_writefiles.put(b.dupe(name), wf) catch @panic("OOM");
return wf;
}

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

pub fn namedWriteFiles(d: *Dependency, name: []const u8) *Step.WriteFile {
return d.builder.named_writefiles.get(name) orelse {
panic("unable to find named writefiles '{s}'", .{name});
};
}

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

0 comments on commit 4ace1f5

Please sign in to comment.