Skip to content

package manager: no dependency named 'X' in 'build.zig.zon'; but it is #16354

@emidoots

Description

@emidoots

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:

zig/lib/std/Build.zig

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:

  • name is "vulkan_headers"
  • b.dep_prefix is "glfw."
  • mem.startsWith(u8, decl.name, b.dep_prefix) is false
  • mem.endsWith(u8, decl.name, name) is true
  • decl.name.len == b.dep_prefix.len + name.len is false

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_prefix need to be corrected to be "mach_glfw.glfw."? If so, how?
  • Or does b.dependency logic need to be relaxed to allow for glfw.vulkan_headers to match mach_glfw.glfw.vulkan_headers?
  • Or should dependencies.zig prefixes be corrected to contain glfw.vulkan_headers instead of mach_glfw.glfw.vulkan_headers?

Expected Behavior

dependency matching works as expected, the import succeeds

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorzig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions