authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-04-18 03:07:44-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-04-18 03:07:44-07:00
log0820aa4a46ee346282269f2a273f1059418e8702
tree11eaf6e2e476f1e56abd280ee10c5d3481ae5669
parent21a6a1b0f2d7241594a9aa123e48cf2e3ebaccb9

std: fix and add test for Build.dependencyFromBuildZig


7 files changed, 46 insertions(+), 1 deletions(-)

lib/std/Build.zig+1-1
...@@ -1974,7 +1974,7 @@ pub fn dependencyFromBuildZig(...@@ -1974,7 +1974,7 @@ pub fn dependencyFromBuildZig(
1974 const dep_name = for (b.available_deps) |dep| {1974 const dep_name = for (b.available_deps) |dep| {
1975 if (mem.eql(u8, dep[1], pkg_hash)) break dep[1];1975 if (mem.eql(u8, dep[1], pkg_hash)) break dep[1];
1976 } else break :find_dep;1976 } else break :find_dep;
1977 return dependencyInner(b, dep_name, pkg.build_root, pkg.build_zig, pkg.deps, args);1977 return dependencyInner(b, dep_name, pkg.build_root, pkg.build_zig, pkg_hash, pkg.deps, args);
1978 }1978 }
19791979
1980 const full_path = b.pathFromRoot("build.zig.zon");1980 const full_path = b.pathFromRoot("build.zig.zon");
test/standalone/build.zig.zon+3
...@@ -158,6 +158,9 @@...@@ -158,6 +158,9 @@
158 .install_headers = .{158 .install_headers = .{
159 .path = "install_headers",159 .path = "install_headers",
160 },160 },
161 .dependencyFromBuildZig = .{
162 .path = "dependencyFromBuildZig",
163 },
161 },164 },
162 .paths = .{165 .paths = .{
163 "build.zig",166 "build.zig",
test/standalone/dependencyFromBuildZig/build.zig created+16
...@@ -0,0 +1,16 @@
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const test_step = b.step("test", "Test it");
5 b.default_step = test_step;
6
7 const dep1 = b.dependency("other", .{});
8
9 const build_runner = @import("root");
10 const deps = build_runner.dependencies;
11 const zon_decls = @typeInfo(deps.packages).Struct.decls;
12 const pkg = @field(deps.packages, zon_decls[0].name);
13 const dep2 = b.dependencyFromBuildZig(pkg.build_zig, .{});
14
15 std.debug.assert(dep1.module("add") == dep2.module("add"));
16}
test/standalone/dependencyFromBuildZig/build.zig.zon created+10
...@@ -0,0 +1,10 @@
1.{
2 .name = "dependencyFromBuildZig",
3 .version = "0.0.0",
4 .dependencies = .{
5 .other = .{
6 .path = "other",
7 },
8 },
9 .paths = .{""},
10}
test/standalone/dependencyFromBuildZig/other/add.zig created+3
...@@ -0,0 +1,3 @@
1pub fn add(x: u32, y: u32) u32 {
2 return x + y;
3}
test/standalone/dependencyFromBuildZig/other/build.zig created+7
...@@ -0,0 +1,7 @@
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 _ = b.addModule("add", .{
5 .root_source_file = b.path("add.add.zig"),
6 });
7}
test/standalone/dependencyFromBuildZig/other/build.zig.zon created+6
...@@ -0,0 +1,6 @@
1.{
2 .name = "other",
3 .version = "0.0.0",
4 .dependencies = .{},
5 .paths = .{""},
6}