{"id":23424303,"url":"https://github.com/ringtailsoftware/zig-embeddir","last_synced_at":"2025-04-12T16:34:59.363Z","repository":{"id":136877114,"uuid":"601313714","full_name":"ringtailsoftware/zig-embeddir","owner":"ringtailsoftware","description":"Example showing how to embed a directory of files in a zig executable","archived":false,"fork":false,"pushed_at":"2025-01-02T00:08:51.000Z","size":389,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T22:40:50.399Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ringtailsoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-13T20:06:21.000Z","updated_at":"2025-02-03T02:06:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"bf74d8ad-7862-469b-8696-7bb9768a923d","html_url":"https://github.com/ringtailsoftware/zig-embeddir","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringtailsoftware%2Fzig-embeddir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringtailsoftware%2Fzig-embeddir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringtailsoftware%2Fzig-embeddir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringtailsoftware%2Fzig-embeddir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ringtailsoftware","download_url":"https://codeload.github.com/ringtailsoftware/zig-embeddir/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248596983,"owners_count":21130796,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-23T04:16:36.674Z","updated_at":"2025-04-12T16:34:59.351Z","avatar_url":"https://github.com/ringtailsoftware.png","language":"Zig","readme":"# embeddir\n\nAn example of using the zig build system to aid in embeddeding multiple files in an executable.\n\nToby Jaffey, https://mastodon.me.uk/@tobyjaffey\n\nZig has `@embedFile` (https://ziglang.org/documentation/master/#embedFile) which embeds the contents of a file in the executable at compile time. In some situations, it's useful to embed all files from a directory without hardcoding their names into the source code.\n\n# How does it work?\n\nIn `build.zig`, we add a custom function `addAssetsOption()`. This opens the `assets` directory, lists files and passes the list to the main program in a module called `assets` in a field called `files`.\n\n    ...\n        options.addOption([]const []const u8, \"files\", files.items);\n        exe.step.dependOn(\u0026options.step);\n\n        const assets = b.createModule(.{\n            .source_file = options.getSource(),\n            .dependencies = \u0026.{},\n        });\n        exe.addModule(\"assets\", assets);\n    ...\n\nIn `src/main`, we build a `ComptimeStringMap` using `assets.files` as the keys and the result of `@embedFile()` on each key as the value.\n\nAt runtime, the data can then be accessed by filename using:\n\n    const data = embeddedFilesMap.get(filename).?;\n\nThe list of files can be found in `assets.files`\n\n\n\n","funding_links":[],"categories":["Zig"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fringtailsoftware%2Fzig-embeddir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fringtailsoftware%2Fzig-embeddir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fringtailsoftware%2Fzig-embeddir/lists"}