authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-04-18 16:38:11-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-04-18 16:38:11-07:00
log3c221463fd89caf08ee1bd24ea03d49e0c6e7f07
tree78bfd794a0ae85017b422cc1a42045d68a248607
parent544397ce6d2926858217eb013dfcfcd0a5b3e3c6
parent1b4ea80654a71324faba01da0cc04c09fb7e7f77
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #19689 from nektro/nektro-patch-29794

std: fix and add test for Build.dependencyFromBuildZig

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

lib/std/Build.zig+1-1
...@@ -1975,7 +1975,7 @@ pub fn dependencyFromBuildZig(...@@ -1975,7 +1975,7 @@ pub fn dependencyFromBuildZig(
1975 const dep_name = for (b.available_deps) |dep| {1975 const dep_name = for (b.available_deps) |dep| {
1976 if (mem.eql(u8, dep[1], pkg_hash)) break dep[1];1976 if (mem.eql(u8, dep[1], pkg_hash)) break dep[1];
1977 } else break :find_dep;1977 } else break :find_dep;
1978 return dependencyInner(b, dep_name, pkg.build_root, pkg.build_zig, pkg.deps, args);1978 return dependencyInner(b, dep_name, pkg.build_root, pkg.build_zig, pkg_hash, pkg.deps, args);
1979 }1979 }
19801980
1981 const full_path = b.pathFromRoot("build.zig.zon");1981 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+12
...@@ -0,0 +1,12 @@
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 dep2 = b.dependencyFromBuildZig(@import("other"), .{});
10
11 std.debug.assert(dep1.module("add") == dep2.module("add"));
12}
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}