| ... | ... | @@ -1947,6 +1947,32 @@ pub inline fn lazyImport( |
| 1947 | 1947 | comptime unreachable; // Bad @dependencies source |
| 1948 | 1948 | } |
| 1949 | 1949 | |
| 1950 | pub fn dependencyFromBuildZig( |
| 1951 | b: *Build, |
| 1952 | /// The build.zig struct of the dependency, normally obtained by `@import` of the dependency. |
| 1953 | /// If called from the build.zig file itself, use `@This` to obtain a reference to the struct. |
| 1954 | comptime build_zig: type, |
| 1955 | args: anytype, |
| 1956 | ) *Dependency { |
| 1957 | const build_runner = @import("root"); |
| 1958 | const deps = build_runner.dependencies; |
| 1959 | |
| 1960 | find_dep: { |
| 1961 | const pkg, const pkg_hash = inline for (@typeInfo(deps.packages).Struct.decls) |decl| { |
| 1962 | const pkg_hash = decl.name; |
| 1963 | const pkg = @field(deps.packages, pkg_hash); |
| 1964 | if (@hasDecl(pkg, "build_zig") and pkg.build_zig == build_zig) break .{ pkg, pkg_hash }; |
| 1965 | } else break :find_dep; |
| 1966 | const dep_name = for (b.available_deps) |dep| { |
| 1967 | if (mem.eql(u8, dep[1], pkg_hash)) break dep[1]; |
| 1968 | } else break :find_dep; |
| 1969 | return dependencyInner(b, dep_name, pkg.build_root, pkg.build_zig, pkg.deps, args); |
| 1970 | } |
| 1971 | |
| 1972 | const full_path = b.pathFromRoot("build.zig.zon"); |
| 1973 | debug.panic("'{}' is not a build.zig struct of a dependecy in '{s}'", .{ build_zig, full_path }); |
| 1974 | } |
| 1975 | |
| 1950 | 1976 | pub fn anonymousDependency( |
| 1951 | 1977 | b: *Build, |
| 1952 | 1978 | /// The path to the directory containing the dependency's build.zig file, |