Include paths / build paths of a dependency from a url

Hi there,
I have a c-library called htslib and Im trying to use zig cc to build it, and then be able to import the library into a zig project using the package manager. The project is called zights and is online at GitHub - kcleal/zights: Import htslib as a module in zig

When I set eveyrthing up locally, it seems to work. So assume I have an example zig project, I can use zights by adding this to the build.zig file:

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

    const zights = b.dependency("zights", .{
        .target = target,
    });

    exe.addIncludePath(zights.path("htslib/htslib"));
    exe.addIncludePath(zights.path("htslib/cram"));
    exe.linkLibrary(zights.artifact("hts"));

In build.zig.zon I list zights using the path parameter .path = "../zights" and everything seems to work.

However, if I try and use the GitHub repo, instead adding this:

.zights = .{
            .url = "https://github.com/kcleal/zights/archive/refs/tags/v0.0.1a.tar.gz",
            .hash = "1220bdf5b2bc887e2523381ccb95db034651623aae4aae7c680d52215dbe6e52fa58",

Then I get FileNotFound errors relating to zights (it doesn’t appear to exists in the build_root directory). Ive run zig fetch url and it states that everything is up to date. I think I am probably using the wrong include path, but how do I get the correct path, I can’t see the downloaded package anywhere? Im guessing it has something to do with these lines in example/build.zig:

const zights = b.dependency("zights", .{
        .target = target,
    });

    exe.addIncludePath(zights.path("htslib/htslib"));
    exe.addIncludePath(zights.path("htslib/cram"));
    exe.linkLibrary(zights.artifact("hts"));

Thanks for any pointers!

You must add the “src” and “htslib” as paths in build.zig.zon

Thanks @dimdin,
Do you know of an example I can copy? I’m still not quite understanding what needs to be done

Does src refer to where htslib will be installed, or where it gets downloaded to. Sorry I’m a bit confused

The build.zig.zon documentation is: zig/doc/build.zig.zon.md at master · ziglang/zig · GitHub

zights build.zig.zon includes only “build.zig” and “build.zig.zon” in the package.
Simply add in the paths all the subfolders:

.paths = .{
        "build.zig",
        "build.zig.zon",
        "src",
        "htslib",
    },
2 Likes