authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-07-01 14:02:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-07-01 14:02:31-07:00
logca948d62d0a5762c2438da0a0a59034dc0a16cdb
tree4bf79510fe7cfa20c38c0bd436ce3809fc91ad4d
parenta30f029d53b5080351ce531b10535bb37776854e

std.Build: deprecate lazyDependency and dependency

in favor of dependencyLazy which has a different function signature and will be eventually renamed to dependency migrating to all dependencies being potentially lazy by setting the flag in build.zig.zon and embracing error.LazyDependencyNeeded propagation as the way to deal with discovered needed dependencies. solves the problem that handling the `null` case from `lazyDependency` was annoying.

1 files changed, 21 insertions(+), 11 deletions(-)

lib/std/Build.zig+21-11
......@@ -2109,21 +2109,29 @@ fn markNeededLazyDep(b: *Build, pkg_hash: []const u8) void {
21092109 b.graph.needed_lazy_dependencies.put(b.graph.arena, pkg_hash, {}) catch @panic("OOM");
21102110}
21112111
2112/// Deprecated in favor of `dependencyLazy`.
2113pub fn lazyDependency(b: *Build, name: []const u8, args: anytype) ?*Dependency {
2114 return dependencyLazy(b, name, args) catch |err| switch (err) {
2115 error.LazyDependencyNeeded => null,
2116 };
2117}
2118
21122119/// When this function is called, it means that the current build does, in
21132120/// fact, require this dependency. If the dependency is already fetched, it is
21142121/// returned. However if the dependency is not yet fetched, then when the build
2115/// script is finished running, the build will not proceed to the make phase.
2122/// script is finished running, the toolchain will not proceed to the make phase.
21162123/// Instead, the parent process will additionally fetch all the lazy
21172124/// dependencies that were actually required by running the build script,
2118/// rebuild the build script, and then run it again. In other words, if this
2119/// function returns `null` it means that the only purpose of completing the
2120/// configure phase is to find out all the other lazy dependencies that are
2121/// also required.
2125/// recompile the build script, and then run it again. In other words, if this
2126/// function returns `error.LazyDependencyNeeded` it means that the only
2127/// purpose of completing the configure phase is to find out all the other lazy
2128/// dependencies that are also required. In this case, one must propagate the
2129/// error all the way up and return it from the main build function.
21222130///
2123/// It is allowed to use this function for non-lazy dependencies, in which case
2124/// it will never return `null`. This allows toggling laziness via
2125/// build.zig.zon without changing build.zig logic.
2126pub fn lazyDependency(b: *Build, name: []const u8, args: anytype) ?*Dependency {
2131/// For non-lazy dependencies, this always succeeds.
2132///
2133/// This function will be eventually renamed to `dependency`.
2134pub fn dependencyLazy(b: *Build, name: []const u8, args: anytype) error{LazyDependencyNeeded}!*Dependency {
21272135 const build_runner = @import("root");
21282136 const deps = build_runner.dependencies;
21292137 const pkg_hash = findPkgHashOrFatal(b, name);
......@@ -2134,15 +2142,17 @@ pub fn lazyDependency(b: *Build, name: []const u8, args: anytype) ?*Dependency {
21342142 const available = !@hasDecl(pkg, "available") or pkg.available;
21352143 if (!available) {
21362144 markNeededLazyDep(b, pkg_hash);
2137 return null;
2145 return error.LazyDependencyNeeded;
21382146 }
21392147 return dependencyInner(b, name, pkg.build_root, if (@hasDecl(pkg, "build_zig")) pkg.build_zig else null, pkg_hash, pkg.deps, args);
21402148 }
21412149 }
21422150
2143 unreachable; // Bad @dependencies source
2151 unreachable; // bad @dependencies source
21442152}
21452153
2154/// Deprecated in favor of `dependencyLazy`. To get the same behavior as before, use `try` to propagate
2155/// the potential `error.LazyDependencyNeeded` all the way out of your main build function.
21462156pub fn dependency(b: *Build, name: []const u8, args: anytype) *Dependency {
21472157 const build_runner = @import("root");
21482158 const deps = build_runner.dependencies;