| ... | ... | @@ -2109,21 +2109,29 @@ fn markNeededLazyDep(b: *Build, pkg_hash: []const u8) void { |
| 2109 | 2109 | b.graph.needed_lazy_dependencies.put(b.graph.arena, pkg_hash, {}) catch @panic("OOM"); |
| 2110 | 2110 | } |
| 2111 | 2111 | |
| 2112 | /// Deprecated in favor of `dependencyLazy`. |
| 2113 | pub 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 | |
| 2112 | 2119 | /// When this function is called, it means that the current build does, in |
| 2113 | 2120 | /// fact, require this dependency. If the dependency is already fetched, it is |
| 2114 | 2121 | /// 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. |
| 2116 | 2123 | /// Instead, the parent process will additionally fetch all the lazy |
| 2117 | 2124 | /// 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. |
| 2122 | 2130 | /// |
| 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. |
| 2126 | | pub 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`. |
| 2134 | pub fn dependencyLazy(b: *Build, name: []const u8, args: anytype) error{LazyDependencyNeeded}!*Dependency { |
| 2127 | 2135 | const build_runner = @import("root"); |
| 2128 | 2136 | const deps = build_runner.dependencies; |
| 2129 | 2137 | const pkg_hash = findPkgHashOrFatal(b, name); |
| ... | ... | @@ -2134,15 +2142,17 @@ pub fn lazyDependency(b: *Build, name: []const u8, args: anytype) ?*Dependency { |
| 2134 | 2142 | const available = !@hasDecl(pkg, "available") or pkg.available; |
| 2135 | 2143 | if (!available) { |
| 2136 | 2144 | markNeededLazyDep(b, pkg_hash); |
| 2137 | | return null; |
| 2145 | return error.LazyDependencyNeeded; |
| 2138 | 2146 | } |
| 2139 | 2147 | return dependencyInner(b, name, pkg.build_root, if (@hasDecl(pkg, "build_zig")) pkg.build_zig else null, pkg_hash, pkg.deps, args); |
| 2140 | 2148 | } |
| 2141 | 2149 | } |
| 2142 | 2150 | |
| 2143 | | unreachable; // Bad @dependencies source |
| 2151 | unreachable; // bad @dependencies source |
| 2144 | 2152 | } |
| 2145 | 2153 | |
| 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. |
| 2146 | 2156 | pub fn dependency(b: *Build, name: []const u8, args: anytype) *Dependency { |
| 2147 | 2157 | const build_runner = @import("root"); |
| 2148 | 2158 | const deps = build_runner.dependencies; |