# Embed binary data at compile time

**URL:** <https://ziggit.dev/t/embed-binary-data-at-compile-time/16729>\
**Category:** Help\
**Tags:** comptime, build-system\
**Created:** [July 15, 2026, 5:37pm UTC](https://ziggit.dev/t/embed-binary-data-at-compile-time/16729 "2026-07-15T17:37:43Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [July 15, 2026, 6:40pm UTC](https://ziggit.dev/t/embed-binary-data-at-compile-time/16729/2 "2026-07-15T18:40:53Z")

</div>

> [@schlyngel](#):
>
> ```zig
> try output.print(
> arena,
> "pub const Tvgs = struct {s}\n",
> .{"{"},
> );
> 
> ```

You escape braces in format strings by doubling them.

> [@schlyngel](#):
>
> So… i managed to get the following working and would like to know if there is anything bad/dirty with it and most importantly: Is there an easier way?

What I dislike about it is that it generates one big source file that encodes binary data as text (which then gets converted back into binary by the compiler), if any of the input files are changed you need to re-convert all files not just the ones that changed (depends on your use-case whether that is a problem).

* * *

But I am also unsure whether there is an easy build-cache friendly alternative for handling a folder of files that you want to transform and then embed, without re-doing unnecessary work.

If your build script walks the directory to enumerate the individual files, it could create a run-step for each individual file to convert it from svg to tvg, then you could use one `addWriteFiles` to collect all the transformed output files in one directory that should be cached by the build system and only re-run the individual conversions for input-svgs that changed. (haven’t tested this specific scenario)

That wouldn’t handle adding or removing files while using watch or incremental builds, but should allow editing existing files.

I think the resulting `wf.getDirectory()` then could be passed on to [Zig Asset Bundler](https://ziggit.dev/t/zig-asset-bundler/16586)

There is also this older related topic:

> [@Zig build : How to handle an unknown amount of files in a folder](https://ziggit.dev/t/zig-build-how-to-handle-an-unknown-amount-of-files-in-a-folder/8543):
>
> Hello everyone, I’m currently building a game using zig, and I would like to use the zig build system as an asset pipeline for this game. Such asset pipeline would require for example taking all the files with a given extension in a folder (in my case aseprite files), run a command on them (to export them to one or multiple .png + .json files), put them in another folder, and run another command on that folder to pack all the .png in a nice sprite sheet that would get installed along the game. …

* * *

Overall I would say, I don’t think your solution is ideal, or should be the go to solution long term, but if it works for you, it might be the pragmatic solution for now, until somebody shows how to handle this more simply / idiomatically.

---

_[View the full topic](https://ziggit.dev/t/embed-binary-data-at-compile-time/16729)._
