{"id":13805651,"url":"https://github.com/aherrmann/rules_zig","last_synced_at":"2025-03-02T22:18:35.645Z","repository":{"id":172836099,"uuid":"587201170","full_name":"aherrmann/rules_zig","owner":"aherrmann","description":"Bazel build rules for Zig","archived":false,"fork":false,"pushed_at":"2024-10-29T08:34:25.000Z","size":874,"stargazers_count":44,"open_issues_count":39,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-29T09:25:25.770Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aherrmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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},"funding":{"open_collective":"bazel-rules-authors-sig"}},"created_at":"2023-01-10T07:38:13.000Z","updated_at":"2024-10-29T08:34:28.000Z","dependencies_parsed_at":"2024-03-02T22:20:12.961Z","dependency_job_id":"c022c55f-5262-4ce7-addb-faedcead5756","html_url":"https://github.com/aherrmann/rules_zig","commit_stats":null,"previous_names":["aherrmann/rules_zig"],"tags_count":6,"template":false,"template_full_name":"bazel-contrib/rules-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aherrmann%2Frules_zig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aherrmann%2Frules_zig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aherrmann%2Frules_zig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aherrmann%2Frules_zig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aherrmann","download_url":"https://codeload.github.com/aherrmann/rules_zig/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241577189,"owners_count":19984951,"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-08-04T01:01:03.451Z","updated_at":"2025-03-02T22:18:35.621Z","avatar_url":"https://github.com/aherrmann.png","language":"Starlark","funding_links":["https://opencollective.com/bazel-rules-authors-sig"],"categories":["Starlark"],"sub_categories":[],"readme":"# Bazel build rules for Zig\n\nBuild [Zig code][zig] with the [Bazel build system][bazel].\n\n[zig]: https://ziglang.org/\n[bazel]: https://bazel.build/\n\n## Status\n\nTake a look at the [planned functionality][planned-functionality] tracking\nissue to get a picture of which functionality is already implemented and what\nis still missing.\n\n[planned-functionality]: https://github.com/aherrmann/rules_zig/issues/1\n\n## Motivation\n\nWhy would you use Bazel to build Zig code,\nwhen Zig comes with its own perfectly fine [build system][zig-build]?\n\nThese Bazel rules are not meant as competition to the Zig build system.\nIf your project fits well within the scope of Zig's build system,\nin particular, it only uses Zig code and perhaps C/C++ code,\nthen Zig's build system will probably work very well for your use-case.\n\nBazel is useful for polyglot, monorepo projects,\nespecially if they are very large.\nIf your project involves multiple programming languages\nand if some of them are not supported by Zig's build system,\nor if your project involves complex code-generation steps\nor requires a lot of [custom build steps][zig-build-command-step],\nthen Bazel may be a good choice.\nIf your project is already a Bazel project\nand you want to add Zig code to it\nthen this rule set is for you.\n\nBazel has builtin support for [cross-compilation][bazel-platforms]\nand [build configuration][bazel-configurations],\nmeaning it can support Zig's cross-compilation\nand build configuration features well.\n\n[zig-build]: https://ziglang.org/documentation/master/#Zig-Build-System\n[zig-build-command-step]: https://ikrima.dev/dev-notes/zig/zig-build/#run-commands-as-build-steps\n[bazel-platforms]: https://bazel.build/extending/platforms\n[bazel-configurations]: https://bazel.build/extending/config\n\n## Installation\n\nThe instructions assume basic familiarity with the Bazel build system.\nTake a look at [Bazel's documentation][bazel-intro] if you are unfamiliar.\n\nConsider the [_Additional Setup_](#additional-setup) section as well.\n\n[bazel-intro]: https://bazel.build/about/intro\n\n### Using Bzlmod with Bazel \u003e=7\n\nBzlmod is Bazel's new dependency manager. You can read more about it in the\n[Bazel documentation][bzlmod-doc]. If you use bzlmod, then you can skip the\nWORKSPACE section below. Take a look at [Bazel's migration\nguide][bzlmod-migration] if you are switching from WORKSPACE to bzlmod.\n\n[bzlmod-doc]: https://bazel.build/external/overview#bzlmod\n[bzlmod-migration]: https://bazel.build/external/migration\n\nTo install a [release version of rules_zig][rules-zig-releases] follow the\ninstallation instructions given in the corresponding release notes.\n\n[rules-zig-releases]: https://github.com/aherrmann/rules_zig/releases\n\nTo install a development version add the following to your MODULE.bazel file:\n\n```bzl\nbazel_dep(name = \"rules_zig\")\narchive_override(\n    module_name = \"rules_zig\",\n    integrity = \"sha256-$SHA256\",\n    strip_prefix = \"rules_zig-$COMMIT\",\n    urls = [\"https://github.com/aherrmann/rules_zig/archive/$COMMIT.tar.gz\"],\n)\n```\n\nNote, `$SHA256` and `$COMMIT` are placeholders that you need to fill in. Take a\nlook at the [Bazel documentation][archive-override-doc] for further\ninformation.\n\n[archive-override-doc]: https://bazel.build/versions/7.0.0/rules/lib/globals/module#archive_override\n\n### Using WORKSPACE\n\nThe old way of managing external dependencies with Bazel is to declare them in\nyour WORKSPACE file. You can read more about it in the [Bazel\ndocumentation][workspace-doc]. If you use the WORKSPACE approach, then you can\nskip the bzlmod section above.\n\n[workspace-doc]: https://bazel.build/external/overview#workspace-system\n\nTo install a [release version of rules_zig][rules-zig-releases] follow the\ninstallation instructions given in the corresponding release notes.\n\nTo install a development version add the following to your WORKSPACE file:\n\n```bzl\nload(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")\n\nhttp_archive(\n    name = \"rules_zig\",\n    sha256 = \"$SHA256\",\n    strip_prefix = \"rules_zig-$COMMIT\",\n    urls = [\"https://github.com/aherrmann/rules_zig/archive/$COMMIT.tar.gz\"],\n)\n\nload(\n    \"@rules_zig//zig:repositories.bzl\",\n    \"rules_zig_dependencies\",\n    \"zig_register_toolchains\",\n)\n\nrules_zig_dependencies()\n\nzig_register_toolchains(\n    name = \"zig\",\n    zig_version = \"0.13.0\",\n)\n```\n\nNote, `$SHA256` and `$COMMIT` are placeholders that you need to fill in. Take a\nlook at the [Bazel documentation][http-archive-doc] for further\ninformation.\n\n[http-archive-doc]: https://bazel.build/rules/lib/repo/http#http_archive\n\n\u003c!-- TODO[AH] Write a user-guide\n  https://github.com/aherrmann/rules_zig/issues/59\n\n## User Guide Documentation\n\n--\u003e\n\n### Additional Setup\n\n#### Zig Cache\n\nThe Zig compiler caches intermediate outputs on disk. This cache is shared and\npersisted between Bazel builds and build actions. You can configure the cache\ndirectory using the following set of environment variables, you can configure\nthem through Bazel by using the `--repo_env` flag.\n\n- `RULES_ZIG_CACHE_PREFIX_LINUX`: Cache directory on Linux, default `/tmp/zig-cache`.\n- `RULES_ZIG_CACHE_PREFIX_MACOS`: Cache directory on MacOS, default `/var/tmp/zig-cache`.\n- `RULES_ZIG_CACHE_PREFIX_WINDOWS`: Cache directory on Windows, default `C:\\Temp\\zig-cache`.\n- `RULES_ZIG_CACHE_PREFIX`: Cache directory fall-back for all platforms, default `/tmp/zig-cache`.\n\n\u003e [!Note]\n\u003e On Bazel 7 and above you need to explicitly allow persistence in the sandbox.\n\u003e You can use the following `.bazelrc` snippet, adjust the paths depending on\n\u003e your cache configuration.\n\u003e\n\u003e ```\n\u003e common --enable_platform_specific_config\n\u003e # You can configure `/tmp/zig-cache`, or similar, specifically,\n\u003e # if you can ensure that the directory exists before the build.\n\u003e build:linux --sandbox_add_mount_pair=/tmp\n\u003e build:macos --sandbox_add_mount_pair=/var/tmp\n\u003e build:windows --sandbox_add_mount_pair=C:\\Temp\n\u003e ```\n\n## Usage Examples\n\n\u003c!-- TODO[AH] Create an instructive example.\n  https://github.com/aherrmann/rules_zig/issues/58\n--\u003e\n\nExamples can be found among the end-to-end tests under\n[`./e2e/workspace`](./e2e/workspace).\n\n## Reference Documentation\n\nGenerated API documentation for the provided rules is available in\n[`./docs/rules.md`](./docs/rules.md).\n\n## Runfiles Library Documentation\n\nDocumentation for the Zig runfiles library can be found in\n[`./zig/runfiles/guide.md`](./zig/runfiles/guide.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faherrmann%2Frules_zig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faherrmann%2Frules_zig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faherrmann%2Frules_zig/lists"}