I want to use stb truetype to process some assets inside build.zig. However, since cImport got removed now my project’s code needs the build system to run C code, but how about the build.zig itself?
I also have this problem of “how do I use c code” for small single file projects, but those are less important to me.
The way you would conventionally do this is by compiling a small Zig executable that takes input and output paths as command-line arguments, and run it as part of your build. See “Producing Assets for @embedFile” from the official docs for an example: Zig Build System ⚡ Zig Programming Language
Because it’s a normal Zig program, if it needs to use translate-c or other dependencies you can just add them to the executable like you would with any other compile step.
Thank you, that seems like in principle it should work!
Edit:
Upon further reflection, It does seem to lack the thing that I was looking for however, which is to have the struct in the build.zig, this would require me to serialize some of the metadata in some form and process them again, which sounds like more work than me doing it manually.
Note that translate-c will be relegated to an official Zig package and will removed from the compiler/build system in 0.17 (it is already gone from the master branch). If you are upgrading from @cImport you might want to upgrade to the package right away, so that you won’t need to do it when 0.17 is released.
You generally don’t want to run processing code inside your build.zig build() function. The job of the build.zig is to construct a graph of build steps, and it’s those steps that perform the actual processing when needed by a dependent step.
We can’t really offer useful help without a concrete example of what you’re currently doing that demonstrates what you want. However, I’m pretty confident that you don’t actually need to access any struct definition from your build.zig. But if you do, keep in mind that your build.zig is regular Zig code that can @import any Zig source file, in case you need to share any logic or struct definitions between the build script and the program.
The idea is that I want to take a .ttf file and create bitmaps for font sizes .{8, 12, 16, 20, 24, 28, 32}
goal is .rgba files for now, png compression can come a different date.
There are also metadata that I need like for each glyph the coordinates on the bitmap that corespond for example. I haven’t looked at stb, but I am assuming that whatever code generates them will also give me that metadata.
My vision was that by calling that code I would also get that metadata easily, then I could just make my zig struct for storing them and import that into the project.
The alternative is to use any tool to generate those bitmaps outside the build, and then for metadata figure out something.
That’s why I thought about using c from build.zig does that make sense? Of course if there’s a better way to do it that bypasses the problem completely I am all ears.