I started with the SDL example from Andrew (https://github.com/andrewrk/sdl-zig-demo/blob/master/README.md) and would like to add nfd-zig (https://github.com/fabioarnold/nfd-zig) as a project dependency. Since nfd-zig seems to be too outdated to be added as dependency in build.zig.zon, I was wondering whether I could add it as a dependency in my build.zig? I read about std.build.Pkg but this seems to be removed now. Using zig-windows-x86_64-0.12.0-dev.1486. Any hints?
#Howto include other project via build.zig?
1 messages · Page 1 of 1 (latest)
nfd was updated 3 weeks ago, why do you say its too outdated?
OK, maybe I don't get the concept about build.zig.zon yet but my understanding was that I could not add nfd-zig as a dependency in my build.zig.zon, could I?
you definitely should be able to
I tried to google a getting started on this but failed to find any helpful information. Could you provide me with a starting point?
I would at least need a link to an archive, wouldn't I?
yeah
you can use that for the current latest commit
in your build.zig.zon add
.nfd = .{
.url = "https://github.com/fabioarnold/nfd-zig/archive/4701d11cf52866828bd682c19ddddf60f8152960.tar.gz"
},
in the .dependencies field then run zig build and itll tell you what hash its expecting, put that under the url
then in build.zig you do
const nfd_dep = b.dependency("nfd", .{
.target = target,
.optimize = optimize,
});
exe.addModule("nfd", nfd_dep.module("nfd"));
exe.linkLibrary(nfd_dep.artifact("nfd"));
and that should work
then you can just @import("nfd") in your code
clicked the 4701d11 button at the end then copied the link it took me to but replaced commit with archive and added the tar.gz
just github magic lol, there might be a more intuitive way
OK, thanks for sharing some magic here 😉
so what does it take a github repo then so that I can add it to my build.zig.zon like this and it will work?
just a build.zig in the root directory of the repo?
Most git sites have this functionality btw, tho some might have a slightly different url.
depends what the library is doing, if its pure zig and not linking any C libraries you just need a build.zig that has b.addModule in it
technically you dont even need that since you can access arbitrary files from downloaded dependencies now, but adding the module is much more convenient for users of the library
a more general question as I'm new here: is this already documented somewhere or knowledge spreaded within the community?
that's pretty cool
Build system doesn't have great documentation yet, unfortunately
unfortunately its mostly just people learning from each other atm, theres some basic examples in the 0.11 release notes but its not much
its common to recommend reading the source code of other zig projects to see how they do it
OK, that basically confirms what my impression was so far. I'm lucky I finally ended up on discord. Thanks guys!
zon file is receiving a small doc here
https://github.com/ziglang/zig/blob/master/doc/build.zig.zon.md
could you please elaborate on this: "you can access arbitrary files from downloaded dependencies now"? How would I do so? Could I even add my custom build.zig as augmentation to any non-zig github?
a very simple example would be to include a header-only lib like stb_image.h
a more advanced one would build a module from a set of headers and sources
theres a path function on the b.dependency
you pass a string like "src" and get a lazypath to the src folder from a dependency
Assuming you have:
const dep = b.dependency("otherlib", .{});
You can use dep.path("path/in/pkg") to access arbitrary files from that dependency, wherever a LazyPath type is accepted as an argument.