authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-09-11 09:06:54+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-09-15 17:24:44-07:00
log5d7fa5513f92a43a418e3c5c4d27f0b61db313ff
tree5cd9fe7e138f69d5e218f63df5c2791e6f0efd80
parent258236ec1bbfa72555189d87db42e57e1f74be3c

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


1 files changed, 17 insertions(+), 4 deletions(-)

lib/std/Build.zig+17-4
...@@ -89,6 +89,7 @@ dep_prefix: []const u8 = "",...@@ -89,6 +89,7 @@ dep_prefix: []const u8 = "",
89modules: std.StringArrayHashMap(*Module),89modules: std.StringArrayHashMap(*Module),
9090
91named_writefiles: std.StringArrayHashMap(*Step.WriteFile),91named_writefiles: std.StringArrayHashMap(*Step.WriteFile),
92named_lazy_paths: std.StringArrayHashMap(LazyPath),
92/// A map from build root dirs to the corresponding `*Dependency`. This is shared with all child93/// A map from build root dirs to the corresponding `*Dependency`. This is shared with all child
93/// `Build`s.94/// `Build`s.
94initialized_deps: *InitializedDepMap,95initialized_deps: *InitializedDepMap,
...@@ -300,8 +301,9 @@ pub fn create(...@@ -300,8 +301,9 @@ pub fn create(
300 .install_path = undefined,301 .install_path = undefined,
301 .args = null,302 .args = null,
302 .host = graph.host,303 .host = graph.host,
303 .modules = std.StringArrayHashMap(*Module).init(arena),304 .modules = .init(arena),
304 .named_writefiles = std.StringArrayHashMap(*Step.WriteFile).init(arena),305 .named_writefiles = .init(arena),
306 .named_lazy_paths = .init(arena),
305 .initialized_deps = initialized_deps,307 .initialized_deps = initialized_deps,
306 .pkg_hash = "",308 .pkg_hash = "",
307 .available_deps = available_deps,309 .available_deps = available_deps,
...@@ -393,8 +395,9 @@ fn createChildOnly(...@@ -393,8 +395,9 @@ fn createChildOnly(
393 .glibc_runtimes_dir = parent.glibc_runtimes_dir,395 .glibc_runtimes_dir = parent.glibc_runtimes_dir,
394 .host = parent.host,396 .host = parent.host,
395 .dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }),397 .dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }),
396 .modules = std.StringArrayHashMap(*Module).init(allocator),398 .modules = .init(allocator),
397 .named_writefiles = std.StringArrayHashMap(*Step.WriteFile).init(allocator),399 .named_writefiles = .init(allocator),
400 .named_lazy_paths = .init(allocator),
398 .initialized_deps = parent.initialized_deps,401 .initialized_deps = parent.initialized_deps,
399 .pkg_hash = pkg_hash,402 .pkg_hash = pkg_hash,
400 .available_deps = pkg_deps,403 .available_deps = pkg_deps,
...@@ -1060,6 +1063,10 @@ pub fn addNamedWriteFiles(b: *Build, name: []const u8) *Step.WriteFile {...@@ -1060,6 +1063,10 @@ pub fn addNamedWriteFiles(b: *Build, name: []const u8) *Step.WriteFile {
1060 return wf;1063 return wf;
1061}1064}
10621065
1066pub fn addNamedLazyPath(b: *Build, name: []const u8, lp: LazyPath) void {
1067 b.named_lazy_paths.put(b.dupe(name), lp.dupe(b)) catch @panic("OOM");
1068}
1069
1063pub fn addWriteFiles(b: *Build) *Step.WriteFile {1070pub fn addWriteFiles(b: *Build) *Step.WriteFile {
1064 return Step.WriteFile.create(b);1071 return Step.WriteFile.create(b);
1065}1072}
...@@ -1902,6 +1909,12 @@ pub const Dependency = struct {...@@ -1902,6 +1909,12 @@ pub const Dependency = struct {
1902 };1909 };
1903 }1910 }
19041911
1912 pub fn namedLazyPath(d: *Dependency, name: []const u8) LazyPath {
1913 return d.builder.named_lazy_paths.get(name) orelse {
1914 panic("unable to find named lazypath '{s}'", .{name});
1915 };
1916 }
1917
1905 pub fn path(d: *Dependency, sub_path: []const u8) LazyPath {1918 pub fn path(d: *Dependency, sub_path: []const u8) LazyPath {
1906 return .{1919 return .{
1907 .dependency = .{1920 .dependency = .{