Skip to content

Commit

Permalink
Merge branch 'package' into zig-0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Jan 6, 2024
2 parents b495885 + 2a0d82e commit b1a3ec3
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 126 deletions.
51 changes: 38 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,49 @@ sokol-zig ➤ zig build -Dgl=true run-clear
Backend: .sokol.gfx.Backend.GLCORE33
```

## Use as Library
## Use with the Zig package manager

Clone this repo into your project via ``git submodule add https://github.com/floooh/sokol-zig.git`` (for this example into a folder called ``lib`` within your project).
Add a build.zig.zon file to your project:

Add to your ``build.zig``:
```zig
const sokol = @import("lib/sokol-zig/build.zig");
.{
.name = "xxx",
.version = "0.1.0",
.dependencies = .{
.sokol = .{
.url = "https://github.com/floooh/sokol-zig/archive/[commit-sha].tar.gz",
.hash = "[content-hash]",
},
},
}
```

For the `[commit-sha]` just pick the latest from here: https://github.com/floooh/sokol-zig/commits/master

To find out the `[content-hash]`, just omit the `.hash` line, and run `zig build`, this will then output
the expected hash on the terminal. Copy-paste this into the build.zig.zon file.

// ...
// pub fn build(b: *std.build.Builder) void {
// ...
Next in your build.zig file, get a Dependency object like this:

const sokol_build = sokol.buildSokol(b, target, optimize, .{}, "lib/sokol-zig/");
```zig
const dep_sokol = b.dependency("sokol", .{
.target = target,
.optimize = optimize,
// optionally more options like `.gl: true`
});
```

// ...
// const exe = b.addExecutable("demo", "src/main.zig");
// ...
This dependency contains one module and one static-library artifact which can be added
to your executable CompileStep like this:

exe.addAnonymousModule("sokol", .{ .source_file = .{ .path = "lib/sokol-zig/src/sokol/sokol.zig" } });
exe.linkLibrary(sokol_build);
```zig
const exe = b.addExecutable(.{
.name = "pacman",
.target = target,
.optimize = optimize,
.root_source_file = .{ .path = "src/pacman.zig" },
});
exe.addModule("sokol", dep_sokol.module("sokol"));
exe.linkLibrary(dep_sokol.artifact("sokol"));
b.installArtifact(exe);
```
Loading

0 comments on commit b1a3ec3

Please sign in to comment.