Skip to content

Commit

Permalink
Merge pull request #14 from extism/zig-build
Browse files Browse the repository at this point in the history
  • Loading branch information
nilslice authored Mar 12, 2024
2 parents 4a6a921 + cbdcdd1 commit 4ed53e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ zig fetch --save https://github.com/extism/zig-sdk/archive/<git-ref-here>.tar.gz

And in your `build.zig`:
```zig
const extism_module = b.dependency("extism", .{ .target = target, .optimize = optimize }).module("extism");
exe.root_module.addImport("extism", extism_module);
// TODO: make this easier to install
// add the shared library & header
exe.linkLibC();
exe.addIncludePath(.{ .path = "/usr/local/include" });
exe.addLibraryPath(.{ .path = "/usr/local/lib" });
exe.linkSystemLibrary("extism");
// to use the build script util, import extism:
const extism = @import("extism");
// inside your `build` function, after you've created tests or an executable step:
extism.addLibrary(exe, b);
```

## Getting Started
Expand Down
9 changes: 9 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ pub fn build(b: *std.Build) void {
const example_step = b.step("run_example", "Run the basic example");
example_step.dependOn(&example_run_step.step);
}

pub fn addLibrary(to: *std.Build.Step.Compile, b: *std.Build) void {
to.root_module.addImport("extism", b.dependency("extism", .{}).module("extism"));
to.linkLibC();
// TODO: switch based on platform and use platform-specific paths here
to.addIncludePath(.{ .path = "/usr/local/include" });
to.addLibraryPath(.{ .path = "/usr/local/lib" });
to.linkSystemLibrary("extism");
}

0 comments on commit 4ed53e1

Please sign in to comment.