Skip to content

Commit

Permalink
add instructions to readme how to use as a package
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Aug 6, 2023
1 parent 24a47f1 commit ae51b3b
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,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 lib_sokol = sokol.buildLibSokol(b, "lib/sokol-zig/", .{
.target = ...,
.optimize = ...,
...
});
```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.addPackagePath("sokol", "lib/sokol-zig/src/sokol/sokol.zig");
exe.linkLibrary(lib_sokol);
```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);
```

0 comments on commit ae51b3b

Please sign in to comment.