diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 41507bf..1f0064e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,10 +1,10 @@ name: Zig CI - + on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: zig: @@ -12,7 +12,7 @@ jobs: 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: @@ -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 diff --git a/.gitignore b/.gitignore index 55cdb70..128dd03 100644 --- a/.gitignore +++ b/.gitignore @@ -9,11 +9,11 @@ # Cheers! # -andrewrk -zig-cache/ +.zig-cache/ zig-out/ /release/ /debug/ /build/ /build-*/ /docgen_tmp/ -*.log \ No newline at end of file +*.log diff --git a/README.md b/README.md index 02f6c58..e755818 100644 --- a/README.md +++ b/README.md @@ -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); @@ -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. diff --git a/build.zig b/build.zig index 6910fda..1be3ea8 100644 --- a/build.zig +++ b/build.zig @@ -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 })); } @@ -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", @@ -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); @@ -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); @@ -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"); } diff --git a/build.zig.zon b/build.zig.zon index 9692213..921329b 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -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 = .{""}, } diff --git a/src/compiled_plugin.zig b/src/compiled_plugin.zig index 6472158..1e2fd1d 100644 --- a/src/compiled_plugin.zig +++ b/src/compiled_plugin.zig @@ -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 { diff --git a/src/plugin.zig b/src/plugin.zig index 52954d1..2f51671 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -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 { diff --git a/test.zig b/test.zig index c95f085..72184d2 100644 --- a/test.zig +++ b/test.zig @@ -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(); @@ -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",