Unable to find artifact of dependency

I’m trying to build a pre-existing c library with build.zig and then import it into a zig project allyourcodebase style. The build seems to work fine for the library, but when building the zig project using it, I get “unable to find artifact”.

Here’s the build.zig for the c library. I tried to follow allyourcodebase/zlib as an example: build.zig · 0.0.3 · Carson B / ngnk · GitLab

Running zig build in this repo seems to produce libk.a in zig-out/lib/ successfully.

Here’s the build.zig.zon and build.zig for the project using this dependency:

.{
    .name = "embedtest",
    .version = "0.0.0",
    .dependencies = .{
        .ngnk = .{
            .url = "https://gitlab.com/bbro/ngnk/-/archive/0.0.3/ngnk-0.0.3.tar.gz",
            .hash = "1220eb86201b5b0bacd449bde311372a99696a976a0ae432d7964eedcb706735774f",
        },
    },
    .paths = .{
        "build.zig",
        "build.zig.zon",
        "src",
    },
}
const std = @import("std");
pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "embedtest",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });

    const k = b.dependency("ngnk", .{
        .target = target,
        .optimize = optimize,
    });

    exe.linkLibrary(k.artifact("k"));

    b.installArtifact(exe);
}

running zig build gives the error panic: unable to find artifact 'k' with a stacktrace

You have not included build.zig and build.zig.zon in your paths:

When fetching a package, the package manager will delete all files not matched by paths, which in this case downgrades your package from a fully featured Zig package with a build function to a “dumb” tarball package that only exposes files. So unless you explicitly want this behavior, you should make sure build.zig and build.zig.zon are included in paths.

2 Likes

Thanks :pray: that worked. I thought the paths was just for the hash.