Repository navigation
Closed
Description
Update zig to 0.17
Not much changed in 0.17 and the current state of zig integration should
work without any changes. However, zig 0.17 deprecates the built in
translate c functionality[0] in favor of an external package[1] (also
maintained by the zig team).
[0]: https://ziglang.org/download/0.17.0/release-notes.html#toc-C-Translation-Moving-to-External-Package
[1]: https://codeberg.org/ziglang/translate-c
Diff
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 512def3..7075a60 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -271,7 +271,7 @@ jobs:
- name: Setup zig
uses: mlugg/setup-zig@v2
with:
- version: 0.16.0
+ version: 0.17.0
- name: Build
run: zig build -Dunit_tests=true -Doptimize=ReleaseFast
diff --git a/build.zig b/build.zig
index 7acd932..ce5f354 100644
--- a/build.zig
+++ b/build.zig
@@ -5,13 +5,7 @@ const ResolvedTarget = Build.ResolvedTarget;
const OptimizeMode = std.builtin.OptimizeMode;
const builtin = @import("builtin");
-const min_supported_ver = "0.15.1";
-comptime {
- const order = std.SemanticVersion.order;
- const parse = std.SemanticVersion.parse;
- if (order(builtin.zig_version, parse(min_supported_ver) catch unreachable) == .lt)
- @compileError("Box2d requires zig version " ++ min_supported_ver);
-}
+const Translator = @import("translate_c").Translator;
pub const Options = struct {
shared: bool,
@@ -53,14 +47,20 @@ pub fn build(b: *Build) !void {
const lib = try compileBox2d(b, target, optimize, options);
// Translate the box2d headers and export them as a module
- const translate_c = b.addTranslateC(.{
- .root_source_file = b.path("include/box2d/box2d.h"),
+ const translate_c = b.dependency("translate_c", .{});
+ const translator: Translator = .init(translate_c, .{
+ .name = "translate_box2d",
+ .c_source_file = b.path("include/box2d/box2d.h"),
.target = target,
.optimize = optimize,
});
- translate_c.addIncludePath(b.path("include"));
- const translate_module = translate_c.addModule("box2d");
- translate_module.linkLibrary(lib);
+ translator.addIncludePath(b.path("include"));
+
+ const module = b.addModule("box2d", .{
+ .root_source_file = translator.output_file,
+ });
+
+ module.linkLibrary(lib);
b.installArtifact(lib);
diff --git a/build.zig.zon b/build.zig.zon
index b7244da..6a3a65f 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -1,7 +1,13 @@
.{
.name = .box2d,
.version = "3.2.0",
- .minimum_zig_version = "0.16.0",
+ .dependencies = .{
+ .translate_c = .{
+ .url = "git+https://codeberg.org/ziglang/translate-c#875969d3493e245e01bf5d7860f792d8f3eb9ef5",
+ .hash = "translate_c-0.0.0-Q_BUWoFOBwAhz77Zd15HCVuhTKzdUKc94kezmCeJ7IC_",
+ },
+ },
+ .minimum_zig_version = "0.17.0",
.fingerprint = 0xbbd8fcbd18ea5e0b,
.paths = .{
"build.zig",Metadata
Metadata
Assignees
Labels
No labels
Activity
erincatto commentedon Oct 8, 2026
Please make a Box2D fork that demonstrates this working in CI.
Avokadoen commentedon Oct 12, 2026
Passing CI: https://github.com/Avokadoen/box2d/actions/runs/38228780516
erincatto commentedon Oct 12, 2026
Thanks, I'll take a look.
erincatto commentedon Oct 18, 2026
I don't know much about zig so I had an LLM review. This is what it says:
Avokadoen commentedon Oct 18, 2026
I don't have access to my PC the coming days, but I'll fix it during the week
Lazy dependency is valid.Lazy dependency seems non trivial for translate_c. It is not very well documented API atm either so it is hard to figure out how to use it in this context. Given that zig users will ALWAYS need translate_c and CI will always need it as well not that there is a zig test I thought it makes sense to not go this route anyways. The build script also got a bit more convoluted as we must handle not having translate_c when compiling zig tests (by emitting an error). It could be beneficial to c users that want to use zig build (there are dusins of us!), but if someone complains I might reconsider
Avokadoen commentedon Oct 20, 2026
Passing CI: https://github.com/Avokadoen/box2d/actions/runs/39489993890
Commit message:
Update zig to 0.17 Not much changed in 0.17 and the current state of zig integration should work without changes. However, zig 0.17 deprecates the built in translate c functionality[0] in favor of a external package[1] (also maintained by the zig team). There is also a new unit test that is written in zig to ensure that translate_c is working as intended. [0]: https://ziglang.org/download/0.17.0/release-notes.html#toc-C-Translation-Moving-to-External-Package [1]: https://codeberg.org/ziglang/translate-cZig update (#1125)
erincatto commentedon Oct 20, 2026
Thanks for the updates. Implemented in #1125