https://github.com/allyourcodebase/box2d
Box2D packaged for the Zig build system
https://github.com/allyourcodebase/box2d
Last synced: 8 months ago
JSON representation
Box2D packaged for the Zig build system
- Host: GitHub
- URL: https://github.com/allyourcodebase/box2d
- Owner: allyourcodebase
- License: mit
- Created: 2025-01-07T04:36:32.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-07T06:07:33.000Z (about 1 year ago)
- Last Synced: 2025-06-30T00:54:45.807Z (8 months ago)
- Language: Zig
- Size: 4.88 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Box2D
This is the [Box2D](https://box2d.org/) physics engine packaged for the Zig build system.
## Usage
Add the dependency to your build.zig.zon:
```shell
zig fetch --save git+https://github.com/allyourcodebase/box2d#main
```
Use the dependency in your build.zig:
```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:
```zig
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:
```shell
zig build -Dtest run
```