Repository navigation
Description
Zig Version
0.11.0-dev.3886+0c1bfe271
Steps to Reproduce and Observed Behavior
I'm encountering an issue where we get this error:
no dependency named 'vulkan_headers' in '/Users/slimsag/.cache/zig/p/12200a907165afc4c099d4d19e2f7ce9923a72116006d8f5f5af3a9a071fa66171d2/build.zig.zon'. All packages used in build.zig must be declared in this file.
The .cache/zig/.../build.zig.zon file in the error message has these contents:
.{
.name = "glfw",
.version = "0.0.0",
.dependencies = .{
.vulkan_headers = .{
.url = "https://github.com/hexops/vulkan-headers/archive/e1b061ff624531e82a7daea5dbd56c07e08bf0be.tar.gz",
.hash = "12204967f9d07fda3af6a21d6ab71fb832da2186176c530a7a14aa96043537399e6b",
},
.wayland_headers = .{
.url = "https://github.com/hexops/wayland-headers/archive/7bf46f3d60edab2171643ff85770c392ef62704d.tar.gz",
.hash = "1220689912c40c0880b094f748199c490810d4fa4c58ce1ef9058ce97f46ee28496a",
},
.x11_headers = .{
.url = "https://github.com/hexops/x11-headers/archive/1db4df130531c6889df664541bc62161510b9189.tar.gz",
.hash = "12208b3ccaec785e9344472c08bada6137d60666f0d52fc8cf62aae4251056db7737",
},
},
}
My project has a package dependency tree which looks like this (I've excluded some deps for brevity):
-> mach_gpu_dawn
-> vulkan_headers
-> mach_glfw
-> glfw
-> vulkan_headers
When I build the mach_glfw package, I do not encounter this error. Only when building the mach_gpu_dawn package does this error occur.
The generated `dependencies.zig` in `zig-cache` is this
pub const imports = struct {
pub const @"mach_glfw.glfw.vulkan_headers" = @import("12204967f9d07fda3af6a21d6ab71fb832da2186176c530a7a14aa96043537399e6b");
pub const @"mach_glfw.glfw.wayland_headers" = @import("1220689912c40c0880b094f748199c490810d4fa4c58ce1ef9058ce97f46ee28496a");
pub const @"mach_glfw.glfw.x11_headers" = @import("12208b3ccaec785e9344472c08bada6137d60666f0d52fc8cf62aae4251056db7737");
pub const @"mach_glfw.glfw" = @import("12200a907165afc4c099d4d19e2f7ce9923a72116006d8f5f5af3a9a071fa66171d2");
pub const @"mach_glfw.direct3d_headers" = @import("12200d2155216c5eb5f111282cd355b5433cad6a68fd040294e695149cba329f7c12");
pub const @"mach_glfw.vulkan_headers" = @import("12204967f9d07fda3af6a21d6ab71fb832da2186176c530a7a14aa96043537399e6b");
pub const @"mach_glfw.wayland_headers" = @import("1220689912c40c0880b094f748199c490810d4fa4c58ce1ef9058ce97f46ee28496a");
pub const @"mach_glfw.x11_headers" = @import("1220e6bd3186841c1da38d862d52ba88dec9633d24f409eda27627321937419a0ddb");
pub const mach_glfw = @import("122017075bd50eebd5ee79655ffae799eb5d5193ff06e610c4de5c45752fa127b0fa");
pub const glfw = @import("12200a907165afc4c099d4d19e2f7ce9923a72116006d8f5f5af3a9a071fa66171d2");
pub const direct3d_headers = @import("12200d2155216c5eb5f111282cd355b5433cad6a68fd040294e695149cba329f7c12");
pub const vulkan_headers = @import("12204967f9d07fda3af6a21d6ab71fb832da2186176c530a7a14aa96043537399e6b");
pub const wayland_headers = @import("1220689912c40c0880b094f748199c490810d4fa4c58ce1ef9058ce97f46ee28496a");
pub const x11_headers = @import("1220e6bd3186841c1da38d862d52ba88dec9633d24f409eda27627321937419a0ddb");
};
pub const build_root = struct {
pub const mach_glfw = "/Users/slimsag/.cache/zig/p/122017075bd50eebd5ee79655ffae799eb5d5193ff06e610c4de5c45752fa127b0fa";
pub const @"mach_glfw.glfw" = "/Users/slimsag/.cache/zig/p/12200a907165afc4c099d4d19e2f7ce9923a72116006d8f5f5af3a9a071fa66171d2";
pub const @"mach_glfw.glfw.vulkan_headers" = "/Users/slimsag/.cache/zig/p/12204967f9d07fda3af6a21d6ab71fb832da2186176c530a7a14aa96043537399e6b";
pub const @"mach_glfw.glfw.wayland_headers" = "/Users/slimsag/.cache/zig/p/1220689912c40c0880b094f748199c490810d4fa4c58ce1ef9058ce97f46ee28496a";
pub const @"mach_glfw.glfw.x11_headers" = "/Users/slimsag/.cache/zig/p/12208b3ccaec785e9344472c08bada6137d60666f0d52fc8cf62aae4251056db7737";
pub const @"mach_glfw.direct3d_headers" = "/Users/slimsag/.cache/zig/p/12200d2155216c5eb5f111282cd355b5433cad6a68fd040294e695149cba329f7c12";
pub const @"mach_glfw.vulkan_headers" = "/Users/slimsag/.cache/zig/p/12204967f9d07fda3af6a21d6ab71fb832da2186176c530a7a14aa96043537399e6b";
pub const @"mach_glfw.wayland_headers" = "/Users/slimsag/.cache/zig/p/1220689912c40c0880b094f748199c490810d4fa4c58ce1ef9058ce97f46ee28496a";
pub const @"mach_glfw.x11_headers" = "/Users/slimsag/.cache/zig/p/1220e6bd3186841c1da38d862d52ba88dec9633d24f409eda27627321937419a0ddb";
pub const glfw = "/Users/slimsag/.cache/zig/p/12200a907165afc4c099d4d19e2f7ce9923a72116006d8f5f5af3a9a071fa66171d2";
pub const direct3d_headers = "/Users/slimsag/.cache/zig/p/12200d2155216c5eb5f111282cd355b5433cad6a68fd040294e695149cba329f7c12";
pub const vulkan_headers = "/Users/slimsag/.cache/zig/p/12204967f9d07fda3af6a21d6ab71fb832da2186176c530a7a14aa96043537399e6b";
pub const wayland_headers = "/Users/slimsag/.cache/zig/p/1220689912c40c0880b094f748199c490810d4fa4c58ce1ef9058ce97f46ee28496a";
pub const x11_headers = "/Users/slimsag/.cache/zig/p/1220e6bd3186841c1da38d862d52ba88dec9633d24f409eda27627321937419a0ddb";
};Notably, we can see in the above that the dependency is there:
pub const @"mach_glfw.glfw.vulkan_headers" = @import("12204967f9d07fda3af6a21d6ab71fb832da2186176c530a7a14aa96043537399e6b");I modified this code in std.Build to help debug this:
Lines 1523 to 1541 in b9fc0d2
| pub fn dependency(b: *Build, name: []const u8, args: anytype) *Dependency { | |
| const build_runner = @import("root"); | |
| const deps = build_runner.dependencies; | |
| inline for (@typeInfo(deps.imports).Struct.decls) |decl| { | |
| if (mem.startsWith(u8, decl.name, b.dep_prefix) and | |
| mem.endsWith(u8, decl.name, name) and | |
| decl.name.len == b.dep_prefix.len + name.len) | |
| { | |
| const build_zig = @field(deps.imports, decl.name); | |
| const build_root = @field(deps.build_root, decl.name); | |
| return dependencyInner(b, name, build_root, build_zig, args); | |
| } | |
| } | |
| const full_path = b.pathFromRoot("build.zig.zon"); | |
| std.debug.print("no dependency named '{s}' in '{s}'. All packages used in build.zig must be declared in this file.\n", .{ name, full_path }); | |
| process.exit(1); | |
| } |
I printed the decl.name for each dependency, and we can see it ends up there:
mach_glfw.glfw.vulkan_headers <-- should match, but doesn't
mach_glfw.glfw.wayland_headers
mach_glfw.glfw.x11_headers
mach_glfw.glfw
mach_glfw.direct3d_headers
mach_glfw.vulkan_headers
mach_glfw.wayland_headers
mach_glfw.x11_headers
mach_glfw
glfw
direct3d_headers
vulkan_headers
wayland_headers
x11_headers
In short, it's looking for glfw.vulkan_headers but mach_glfw.glfw.vulkan_headers is what should be matching:
nameis"vulkan_headers"b.dep_prefixis"glfw."mem.startsWith(u8, decl.name, b.dep_prefix)isfalsemem.endsWith(u8, decl.name, name)istruedecl.name.len == b.dep_prefix.len + name.lenisfalse
But this is where my knowledge falls apart; I can see the problem clearly, but I'm not sure what to do about it:
- Does
b.dep_prefixneed to be corrected to be"mach_glfw.glfw."? If so, how? - Or does
b.dependencylogic need to be relaxed to allow forglfw.vulkan_headersto matchmach_glfw.glfw.vulkan_headers? - Or should
dependencies.zigprefixes be corrected to containglfw.vulkan_headersinstead ofmach_glfw.glfw.vulkan_headers?
Expected Behavior
dependency matching works as expected, the import succeeds
Activity
emidoots commentedon Jul 8, 2023
Apologies, I think I know why this is happening now and believe it's my own fault. I'm confirming now.
andrewrk commentedon Jul 8, 2023
Even if it ends up being ultimately on your end, feel free to suggest an enhancement to the zig toolchain that could have helped you diagnose the problem more easily 🙂
emidoots commentedon Jul 9, 2023
Confirmed, this was my fault / not a bug in Zig. Here's the summary:
build.zig.zon, it is possible to import that dependency'sbuild.zigfile. For example,.mach_glfw = .{}can be imported as@import("mach_glfw")giving you access tomach_glfw'sbuild.zigfile.build.zigfile, if that file then usesb.dependency("foo")thenb.dep_prefixdoesn't reflect the dependency's prefix, but rather the parent packages' prefix. It's no longer a well-defined value.Ultimately I think this is caused by abusing (1), which is probably unintended behavior of the package manager, and there should instead be a different/better way for a package to expose build-time code.
andrewrk commentedon Jul 9, 2023
Ability to import directly the dependency in build.zig (and have the import root be the package's build.zig file) is intentional behavior, and it sounds like it's useful given that several projects have already discovered it and started using it.
I'm not sure I understand your second point - where would
bcome from? I was thinking that the package would providepubdeclarations inside build.zig which are potentially useful to use in a build script. If your goal is to call thebuildfunction on a dependency in this manner, that is precisely whatb.dependency()does (and making sure to create a proper*Buildobject for the dependency package, so that stuff likeb.dep_prefixwill work correctly).linkpy commentedon Jul 9, 2023
I do think there is a bug with how dependencies are discovered (or replicated when the same dependency is present multiple time within a project dependency tree).
I'm trying to build mach-gpu, https://github.com/hexops/mach-gpu/tree/1266bd935c20d539d74390380364ec566be4eec9 this commit exactly but changed to use mach_gpu as a zig dependency instead of a git submodule. Thus, this was added in the
build.zig.zon:By modifying
std/Build.zigto get more debug info, I found out that for the packageglfw(https://github.com/hexops/glfw/tree/06bd1276fb05c8bc999e104cf21c76788386f263 this commit exactly) doesnt have its dependencies properly created in@import("@dependencies"). It searches for the dependencymach_glfw.glfw.vulkan_headerswhich exists in the build.zig.zon (pointing to https://github.com/hexops/vulkan-headers/tree/e1b061ff624531e82a7daea5dbd56c07e08bf0be exactly) and yet,build_runner.dependencies.importsdoesnt contain it :.{ .{.name = "mach_gpu_dawn.mach_glfw.glfw.vulkan_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.glfw.wayland_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.glfw.x11_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.glfw", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.direct3d_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.vulkan_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.wayland_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.x11_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw", .is_pub = true}, .{.name = "mach_gpu_dawn.glfw", .is_pub = true}, .{.name = "mach_gpu_dawn.direct3d_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.vulkan_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.wayland_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.x11_headers", .is_pub = true}, .{.name = "mach_gpu_dawn", .is_pub = true}, .{.name = "mach_glfw.glfw", .is_pub = true}, .{.name = "mach_glfw.direct3d_headers", .is_pub = true}, .{.name = "mach_glfw.vulkan_headers", .is_pub = true}, .{.name = "mach_glfw.wayland_headers", .is_pub = true}, .{.name = "mach_glfw.x11_headers", .is_pub = true}, .{.name = "mach_glfw", .is_pub = true}, .{.name = "glfw.vulkan_headers", .is_pub = true}, .{.name = "glfw.wayland_headers", .is_pub = true}, .{.name = "glfw.x11_headers", .is_pub = true}, .{.name = "glfw", .is_pub = true}, .{.name = "direct3d_headers", .is_pub = true}, .{.name = "vulkan_headers", .is_pub = true}, .{.name = "wayland_headers", .is_pub = true}, .{.name = "x11_headers", .is_pub = true} }(result of
@compileLog(@typeInfo(build_runner.dependencies.imports).Struct.decls))Since the "dependency resolution" seemed to have worked fine in
mach_gpu_dawnforglfw(as u can see at the top,mach_gpu_dawn.mach_glfw.glfw.vulkan_headersis present), could it be that once that process have been done once on a package, it is not repeated afterward even if used elsewhere?Or maybe that the result is not replicated when the
dep_prefixis different? I am not really sure where that process takes place in the code (seems to be done directly within the compiler), so on my end I can't really tell.The issue with my idea is that, even if the dependencies werent duplicated for
glfw, it was correctly done formach_glfw:.{ .{.name = "mach_gpu_dawn.mach_glfw.glfw.vulkan_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.glfw.wayland_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.glfw.x11_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.glfw", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.direct3d_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.vulkan_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.wayland_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw.x11_headers", .is_pub = true}, .{.name = "mach_gpu_dawn.mach_glfw", .is_pub = true}, [...] .{.name = "mach_glfw.glfw", .is_pub = true}, .{.name = "mach_glfw.direct3d_headers", .is_pub = true}, .{.name = "mach_glfw.vulkan_headers", .is_pub = true}, .{.name = "mach_glfw.wayland_headers", .is_pub = true}, .{.name = "mach_glfw.x11_headers", .is_pub = true}, .{.name = "mach_glfw", .is_pub = true}, [...] }Edit: I thought that maybe it was an issue with the commit/hash of the packages, so I went around and ensured that all of the commits and hashs of each package in every build.zig.zon files matched, but the issue still happens.
mlugg commentedon Jul 9, 2023
Ah, yes, looking at the code, there is a bug there. I have no idea why it worked for
mach_glfw, but in general, we'll only recurse intofetchAndAddDependenciesfor a given package one time, so we only recurse into its children for the first FQN-path encountered.Fixing this leads to a design question for @andrewrk: should recursive dependencies between packages be allowed? (If so, we'll need to move away from the FQN thing, since
a.b.a.b.a.b.a.b...would be a valid name.) I have no strong opinion on this.emidoots commentedon Jul 9, 2023
You're right, I didn't think this through enough before drawing my conclusion.
Yes, I'm not sure either - but the behavior did change when I stopped importing the
build.zig. It's probably not useful to continue discussing Mach code here, if needed I can put together a smaller reproduction case of the issue - but it sounds like @mlugg sees the issue so I'll hold off.mitchellh commentedon Aug 4, 2023
I don't have a reproduction, but this issue is blocking me from being able to update to use the package manager.
I have multiple triangle-shaped dependencies. Concretely, this is what it looks like. All of the transitive dependencies (i.e. zlib) currently match exact hashes in all repositories. More info below the code block.
zlib, it was okay.libpng, it was okay.freetype, I got:And the
build.zig.zonlinked is thelibpngone.So it seems: once you have two dependencies that share a transitive dependency grandchild-level deep, something breaks. I can't find a workaround for this scenario. @slimsag shared a workaround with me that works for the mach dependency (I hit the original issue too) but it doesn't work for my freetype scenario.
mitchellh commentedon Aug 4, 2023
I've found a workaround based on what @slimsag suggested and it looks like this. Yikes!
What I'd rather do which probably is correct once this bug is fixed:
It's possible as I continue going further down the transitive path here that I may not be able to work around it. I'll update this if so.
dcov commentedon Aug 21, 2023
I am running into this as well when trying to build
mach-freetype.IntegratedQuantum commentedon Aug 22, 2023
Same here. The weird thing is that
mach-freetypeseemed to have worked for some people.Here is a small example project, that produces the error.
Luckily a workaround was found, but this appears to be an annoying issue for complicated dependency trees.
jmrico01 commentedon Aug 23, 2023
I'm seeing this issue in a slightly different context, when using
anonymousDependency. I'm using zig-0.11.0 on Windows 10 x86-64.This is roughly what my project looks like:
deps/commonis a library for all my common Zig code, wheredeps/common/build.zig.zonlooks like this:.{ .name = "common", .version = "0.1.0", .dependencies = .{ .httpz = .{ .url = "https://github.com/karlseguin/http.zig/archive/3b15f2034f7b412b168c7d623bcd1a11d95ee6c6.tar.gz", .hash = "12204d254505fd33404d95da79024bcac378bfd558987a8f04bd2920af53e7aed768", }, .zigimg = .{ .url = "https://github.com/zigimg/zigimg/archive/40ddb16fd246174545b7327a12dce7f0889ada7a.tar.gz", .hash = "12208c69b00540fe3f38893800fb6c89a9fe27b4a687de5d0462e498a43db4caeec0", }, }, }In
deps/common/build.zig, I define a modulecommon-applike this:Then in my top-level
build.zig, I pull my library as follows:For most cases, I would probably pull this library from a URL with a top-level
build.zig.zon, and I've confirmed that way works correctly. However, currently I find myself frequently having to change code in my library and build/test it with the calling code, so I care about theanonymousDependencyoption. I get the following error:package manager: write deps in a flat format, eliminating the FQN con…
package manager: write deps in a flat format, eliminating the FQN con…
package manager: write deps in a flat format, eliminating the FQN con…
package manager: write deps in a flat format, eliminating the FQN con…
package manager: write deps in a flat format, eliminating the FQN con…