mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.Build: add dependencyFromBuildZig
This commit is contained in:
parent
e204a6edb8
commit
05126fc4c5
1 changed files with 26 additions and 0 deletions
|
|
@ -1947,6 +1947,32 @@ pub inline fn lazyImport(
|
||||||
comptime unreachable; // Bad @dependencies source
|
comptime unreachable; // Bad @dependencies source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dependencyFromBuildZig(
|
||||||
|
b: *Build,
|
||||||
|
/// The build.zig struct of the dependency, normally obtained by `@import` of the dependency.
|
||||||
|
/// If called from the build.zig file itself, use `@This` to obtain a reference to the struct.
|
||||||
|
comptime build_zig: type,
|
||||||
|
args: anytype,
|
||||||
|
) *Dependency {
|
||||||
|
const build_runner = @import("root");
|
||||||
|
const deps = build_runner.dependencies;
|
||||||
|
|
||||||
|
find_dep: {
|
||||||
|
const pkg, const pkg_hash = inline for (@typeInfo(deps.packages).Struct.decls) |decl| {
|
||||||
|
const pkg_hash = decl.name;
|
||||||
|
const pkg = @field(deps.packages, pkg_hash);
|
||||||
|
if (@hasDecl(pkg, "build_zig") and pkg.build_zig == build_zig) break .{ pkg, pkg_hash };
|
||||||
|
} else break :find_dep;
|
||||||
|
const dep_name = for (b.available_deps) |dep| {
|
||||||
|
if (mem.eql(u8, dep[1], pkg_hash)) break dep[1];
|
||||||
|
} else break :find_dep;
|
||||||
|
return dependencyInner(b, dep_name, pkg.build_root, pkg.build_zig, pkg.deps, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
const full_path = b.pathFromRoot("build.zig.zon");
|
||||||
|
debug.panic("'{}' is not a build.zig struct of a dependecy in '{s}'", .{ build_zig, full_path });
|
||||||
|
}
|
||||||
|
|
||||||
pub fn anonymousDependency(
|
pub fn anonymousDependency(
|
||||||
b: *Build,
|
b: *Build,
|
||||||
/// The path to the directory containing the dependency's build.zig file,
|
/// The path to the directory containing the dependency's build.zig file,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue