zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 5d7fa5513f92a43a418e3c5c4d27f0b61db313ff (tree)
parent 258236ec1bbfa72555189d87db42e57e1f74be3c
Author: mlugg <mlugg@mlugg.co.uk>
Date:   Wed, 11 Sep 2024 09:06:54 +0100

std.Build: allow packages to expose arbitrary LazyPaths by name

Diffstat:
Mlib/std/Build.zig | 21+++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/lib/std/Build.zig b/lib/std/Build.zig @@ -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, @@ -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, @@ -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, @@ -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); } @@ -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 = .{