Box2D packaged for the Zig build system
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Stevie Hryciw 0482245bf5
Merge pull request #4 from yzrmn/main
Fix build and update library to 3.1.1
2025-11-02 17:12:20 -06:00
.gitignore init 2025-01-06 20:52:51 -08:00
build.zig Link QuartzCore framework for macOS target 2025-10-26 20:53:10 +01:00
build.zig.zon Remove system_sdk package 2025-10-26 20:51:49 +01:00
LICENSE init 2025-01-06 20:52:51 -08:00
README.md Even lazier 2025-01-06 22:07:30 -08:00

Box2D

This is the Box2D physics engine packaged for the Zig build system.

Usage

Add the dependency to your build.zig.zon:

zig fetch --save git+https://github.com/allyourcodebase/box2d#main

Use the dependency in your build.zig:

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const box2d = b.dependency("box2d", .{
        .target = target,
        .optimize = optimize,
    });

    const exe = b.addExecutable(.{
        // ...
    });
    exe.addIncludePath(box2d.path("."));
    exe.linkLibrary(box2d.artifact("box2d"));

    // ...
}

Import and use the C library:

const c = @cImport({
    @cInclude("box2d/box2d.h");
});

pub fn main() void {
    const world_def = c.b2DefaultWorldDef();
    const world = c.b2CreateWorld(&world_def);
    // ...
}

Examples

This build script can also run the official examples. From this repository run:

zig build -Dtest run