authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-07 00:38:59-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:14-07:00
log8510f9e2bc1c1da6b3d12a07ae613cb3ca888d63
tree177ebdc9599597e171080b5cae219826ad94c774
parent263aaf0e66a1e2cdf5cebdbfc5e2761dc5a67181

std.Build: add addAnonymousDependency

This is for bypassing the package manager and directly depending on another package via the build system. For this to work the anonymous package must be found on the file system relative to the current package's build.zig.

1 files changed, 20 insertions(+), 1 deletions(-)

lib/std/Build.zig+20-1
......@@ -1457,7 +1457,26 @@ pub fn dependency(b: *Build, name: []const u8, args: anytype) *Dependency {
14571457 process.exit(1);
14581458}
14591459
1460fn dependencyInner(
1460pub fn anonymousDependency(
1461 b: *Build,
1462 /// The path to the directory containing the dependency's build.zig file,
1463 /// relative to the current package's build.zig.
1464 relative_build_root: []const u8,
1465 /// A direct `@import` of the build.zig of the dependency.
1466 comptime build_zig: type,
1467 args: anytype,
1468) *Dependency {
1469 const arena = b.allocator;
1470 const build_root = b.build_root.join(arena, &.{relative_build_root}) catch @panic("OOM");
1471 const name = arena.dupe(u8, relative_build_root) catch @panic("OOM");
1472 for (name) |*byte| switch (byte.*) {
1473 '/', '\\' => byte.* = '.',
1474 else => continue,
1475 };
1476 return dependencyInner(b, name, build_root, build_zig, args);
1477}
1478
1479pub fn dependencyInner(
14611480 b: *Build,
14621481 name: []const u8,
14631482 build_root_string: []const u8,