Skip to content

fix: build #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: Zig CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
zig:
name: Zig CI
runs-on: ubuntu-latest
strategy:
matrix:
zig_version: ["0.13.0"] # eventually use multiple versions once stable
zig_version: ["0.14.0"] # eventually use multiple versions once stable
rust:
- stable
steps:
Expand All @@ -21,9 +21,9 @@ jobs:
- uses: ./.github/actions/libextism
- name: Setup Zig env
uses: goto-bus-stop/setup-zig@v2
with:
with:
version: ${{ matrix.zig_version }}
- name: Test Zig Host SDK
run: |
zig version
LD_LIBRARY_PATH=/usr/local/lib zig build test
zig build test
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
# Cheers!
# -andrewrk

zig-cache/
.zig-cache/
zig-out/
/release/
/debug/
/build/
/build-*/
/docgen_tmp/
*.log
*.log
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const extism = @import("extism");
const std = @import("std");

const wasm_url = extism.manifest.WasmUrl{ .url = "https://github.com/extism/plugins/releases/latest/download/count_vowels.wasm" };
const manifest = .{ .wasm = &[_]extism.manifest.Wasm{.{ .wasm_url= wasm_url }} };
const manifest = extism.manifest.Manifest{ .wasm = &[_]extism.manifest.Wasm{.{ .wasm_url= wasm_url }} };

var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer std.debug.assert(gpa.deinit() == .ok);
Expand Down Expand Up @@ -121,7 +121,7 @@ Let's load the manifest like usual but load up this `count_vowels_kvstore` plug-

```zig
const wasm_url = extism.manifest.WasmUrl{ .url = "https://github.com/extism/plugins/releases/latest/download/count_vowels_kvstore.wasm" };
const manifest = .{ .wasm = &[_]extism.manifest.Wasm{.{ .wasm_url= wasm_url }} };
const manifest = extism.manifest.Manifest{ .wasm = &[_]extism.manifest.Wasm{.{ .wasm_url= wasm_url }} };
```

> *Note*: The source code for this is [here](https://github.com/extism/plugins/blob/main/count_vowels_kvstore/src/lib.rs) and is written in rust, but it could be written in any of our PDK languages.
Expand Down
11 changes: 3 additions & 8 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const builtin = @import("builtin");
pub fn build(b: *std.Build) void {
comptime {
const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse("0.13.0-dev.230+50a141945") catch unreachable; // build system changes: ziglang/zig#19597
const min_zig = std.SemanticVersion.parse("0.14.0") catch unreachable; // https://ziglang.org/download/0.14.0/release-notes.html
if (current_zig.order(min_zig) == .lt) {
@compileError(std.fmt.comptimePrint("Your Zig version v{} does not meet the minimum build requirement of v{}", .{ current_zig, min_zig }));
}
Expand All @@ -16,6 +16,8 @@ pub fn build(b: *std.Build) void {
const extism_module = b.addModule("extism", .{
.root_source_file = b.path("src/main.zig"),
});
extism_module.addIncludePath(.{ .cwd_relative = "/usr/local/include" });
extism_module.addLibraryPath(.{ .cwd_relative = "/usr/local/lib" });

var tests = b.addTest(.{
.name = "Library Tests",
Expand All @@ -26,8 +28,6 @@ pub fn build(b: *std.Build) void {

tests.root_module.addImport("extism", extism_module);
tests.linkLibC();
tests.addIncludePath(.{ .cwd_relative = "/usr/local/include" });
tests.addLibraryPath(.{ .cwd_relative = "/usr/local/lib" });
tests.linkSystemLibrary("extism");
const tests_run_step = b.addRunArtifact(tests);

Expand All @@ -43,8 +43,6 @@ pub fn build(b: *std.Build) void {

example.root_module.addImport("extism", extism_module);
example.linkLibC();
example.addIncludePath(.{ .cwd_relative = "/usr/local/include" });
example.addLibraryPath(.{ .cwd_relative = "/usr/local/lib" });
example.linkSystemLibrary("extism");
const example_run_step = b.addRunArtifact(example);

Expand All @@ -55,8 +53,5 @@ pub fn build(b: *std.Build) void {
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(.{ .cwd_relative = "/usr/local/include" });
to.addLibraryPath(.{ .cwd_relative = "/usr/local/lib" });
to.linkSystemLibrary("extism");
}
6 changes: 4 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.{
.name = "extism",
.version = "1.0.0-rc2",
.name = .extism,
.version = "1.0.0-rc3",
.minimum_zig_version = "0.14.0",
.fingerprint = 0xb41364f00afbe9db,
.paths = .{""},
}
6 changes: 2 additions & 4 deletions src/compiled_plugin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ pub fn init(allocator: std.mem.Allocator, data: []const u8, functions: []const F
var plugin: ?*c.ExtismCompiledPlugin = null;
var errmsg: [*c]u8 = null;
if (functions.len > 0) {
var funcPtrs = try allocator.alloc(?*c.ExtismFunction, functions.len);
const funcPtrs = try allocator.alloc(?*const c.ExtismFunction, functions.len);
defer allocator.free(funcPtrs);
var i: usize = 0;
for (functions) |function| {
for (functions, 0..) |function, i| {
funcPtrs[i] = function.c_func;
i += 1;
}
plugin = c.extism_compiled_plugin_new(data.ptr, @as(u64, data.len), &funcPtrs[0], functions.len, wasi, &errmsg);
} else {
Expand Down
6 changes: 2 additions & 4 deletions src/plugin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ pub fn init(allocator: std.mem.Allocator, data: []const u8, functions: []const F
var plugin: ?*c.ExtismPlugin = null;
var errmsg: [*c]u8 = null;
if (functions.len > 0) {
var funcPtrs = try allocator.alloc(?*c.ExtismFunction, functions.len);
const funcPtrs = try allocator.alloc(?*const c.ExtismFunction, functions.len);
defer allocator.free(funcPtrs);
var i: usize = 0;
for (functions) |function| {
for (functions, 0..) |function, i| {
funcPtrs[i] = function.c_func;
i += 1;
}
plugin = c.extism_plugin_new(data.ptr, @as(u64, data.len), &funcPtrs[0], functions.len, wasi, &errmsg);
} else {
Expand Down
4 changes: 2 additions & 2 deletions test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export fn hello_world(plugin_ptr: ?*sdk.c.ExtismCurrentPlugin, inputs: [*c]const
}

const wasmfile_manifest = manifest.WasmFile{ .path = "wasm/code-functions.wasm" };
const man = .{ .wasm = &[_]manifest.Wasm{.{ .wasm_file = wasmfile_manifest }} };
const man = manifest.Manifest{ .wasm = &[_]manifest.Wasm{.{ .wasm_file = wasmfile_manifest }} };

test "Single threaded tests" {
var wasm_start = try std.time.Timer.start();
Expand Down Expand Up @@ -119,7 +119,7 @@ test "Multi threaded tests" {

test "Plugin Cancellation" {
const loop_manifest = manifest.WasmFile{ .path = "wasm/loop.wasm" };
const loop_man = .{ .wasm = &[_]manifest.Wasm{.{ .wasm_file = loop_manifest }} };
const loop_man = manifest.Manifest{ .wasm = &[_]manifest.Wasm{.{ .wasm_file = loop_manifest }} };
_ = sdk.setLogFile("test.log", .Debug);
var f = Function.init(
"hello_world",
Expand Down
Loading