I've got a Zig question if anyone out there happens to know.

I'm wrapping the wgpu_native library into a zig build system package like in the screenshot. This works and can be consumed by another project.

However, I want to _also_ package a file (include/webgpu/webgpu.h) along for the consuming project to be able to use. (I have another wrapped C library that uses webgpu as well that needs to include that header when building.) How would I do that?

#zig #ziglang

I've tried using lib.installHeader(...) which maybe works, but I can't figure out how to find/use it in the consuming project.
@SonnyBonds this is what I bounced off of with Zig. Lots of cool things “in flight” still and I need to wait until the dust settles on things like this.

@photex I've fought enough with build systems, both others' and my own, that I don't feel like this is a deal breaker as such. On the contrary it can do a lot of things natively that often is more of hacks in other stuff.

That said it's not very well documented, and there are not that many advanced examples available. But yeah, it's changing a lot over time so a 2 year old blog post describing something may be wrong today. I can totally understand if that puts you off.

@SonnyBonds I think (but am far from being an expert) that the way to include from another project is always via modules, and using installHeader should be the way to go. The documentation is lacking a bit, unfortunately. I mostly use https://github.com/allyourcodebase for reference and examples. The most current info I know is https://youtu.be/jy7w_7JZYyw. Is your code available somewhere?
All Your Codebase

...are belong to Ziguanas, but we'd also be delighted to give them back! - All Your Codebase

GitHub

@hauro I don't have it available right now but I could make a minimal example and put somewhere.

Asked the question and then left the house so I'll have to do it later. :)

@SonnyBonds I have profited from this exact strategy in the past. ;) Just ping me. Not sure if I can help, but I'll give it a go.
@SonnyBonds the user can just do `b.dependency("whatever").path("include/webgpu/wgpu.h")` where whatever is the name then imported your package as in build.zig.zon.

@SonnyBonds You have two main kinds of consumers: Zig and C (either directly or FFI). For the former you want to create zig modules, like you are doing in the screenshot, while for the latter you want to create libraries (b.addLibrary), which will also install headers that you specify via installHeader. Zig users don't need header files if you give them a translate-c module.

I've recently made this package that you can use as a reference https://github.com/allyourcodebase/rnnoise notice how I'm creating:

- a module that contains the full implementation (+ the translate-c output as the root file)
- a module that only contains translate-c definitions in case that the user just wants those and plans to use a system-provided dynamic library
- static and dynamic library artifacts for non-Zig consumers, which also install public header files.

The only thing that I'm missing in that package is system integration options, which I have yet to really learn how to use.

GitHub - allyourcodebase/rnnoise: https://github.com/xiph/rnnoise

https://github.com/xiph/rnnoise. Contribute to allyourcodebase/rnnoise development by creating an account on GitHub.

GitHub

@kristoff Thank you, your description sounds like I've understood it so I must've just got some detail wrong. That package sounds like basically the same kind of setup as I want so I'll have a look at that.

(I know my example had just the Zig module, but I've tried having a library in parallel. But yeah, apparently did something wrong.)

@kristoff To be exact, this is the part after that initial screenshot:

@kristoff Managed to get it working. This part was correct, it was the consuming end that did it wrong. The path I needed to grab was not the module path, but "emittedIncludeTree". Like this:

consuming_module.addIncludePath(wgpu_dep.artifact("wgpu").getEmittedIncludeTree());

@SonnyBonds usually if you're going down that path you just do `mod.linkLibrary(wgpu_dep.artifact("wgpu"))` and that also adds the include paths, but if you want only the header file that's one way. Another is to do `mod.addIncludePath(wgpu_dep.path("path/to/headers")`
@SonnyBonds correction, since in your case wgpu_lib is the upstream project, then you would have to do something along the lines of `wgpu_dep.builder.dependencies("wgpu_lib", .{})`. This is the super manual version where you reach for your dep's dependenncies. There are less invasive methods where you expose a path to consumers (similarly to how you can expose modules and artifacts) but at this point your method seems preferable (if you want only the header files, if you want the full lib you can just linkLibrary).

@kristoff linkLibrary works and definitely feels like the Way It's Meant To Be Played. I feel like I've tried that already, but the stars probably were misaligned some other way then.

Thanks for the pointers! Feels like things are like they're supposed to be now.

zig-curl/libs/curl.zig at b22007729c714936a2f85106a2fd27e0851ad567 · jiacai2050/zig-curl

Zig bindings for libcurl. Contribute to jiacai2050/zig-curl development by creating an account on GitHub.

GitHub
@liujiacai Thanks, but I'm doing this but the include files aren't in the folder the path resolves to (inside zig-cache)

@SonnyBonds
How could this be possible?

You need to install those headers into package, so other projects could use it.

@liujiacai I couldn't fit it in my post but wrote in a reply that I'd tried using "installHeader" as well. Turned out it actually did work, and I just didn't consume it properly in the receiving end. Adding it to a library that I used with linkLibrary set up the include paths properly automatically.