-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
429 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
zig-out | ||
zig-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const std = @import("std"); | ||
|
||
// if you're not using WASI, change this to .freestanding | ||
const BUILD_TARGET_OS = .wasi; | ||
|
||
pub fn build(b: *std.Build) !void { | ||
const optimize = b.standardOptimizeOption(.{}); | ||
const target = b.standardTargetOptions(.{ | ||
.default_target = .{ .abi = .musl, .os_tag = BUILD_TARGET_OS, .cpu_arch = .wasm32 }, | ||
}); | ||
const pdk_module = b.dependency("extism-pdk", .{ .target = target, .optimize = optimize }).module("extism-pdk"); | ||
|
||
var plugin = b.addExecutable(.{ | ||
.name = "plugin", | ||
.root_source_file = b.path("src/pdk.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
if (BUILD_TARGET_OS == .wasi) { | ||
plugin.wasi_exec_model = .reactor; | ||
} | ||
plugin.rdynamic = true; | ||
plugin.entry = .disabled; // or add an empty `pub fn main() void {}` to your code | ||
plugin.root_module.addImport("extism-pdk", pdk_module); | ||
b.installArtifact(plugin); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
.{ | ||
.name = "ziggity", | ||
// This is a [Semantic Version](https://semver.org/). | ||
// In a future version of Zig it will be used for package deduplication. | ||
.version = "0.0.0", | ||
|
||
// This field is optional. | ||
// This is currently advisory only; Zig does not yet do anything | ||
// with this value. | ||
//.minimum_zig_version = "0.11.0", | ||
|
||
// This field is optional. | ||
// Each dependency must either provide a `url` and `hash`, or a `path`. | ||
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively. | ||
// Once all dependencies are fetched, `zig build` no longer requires | ||
// internet connectivity. | ||
.dependencies = .{ | ||
.@"extism-pdk" = .{ | ||
.url = "https://github.com/extism/zig-pdk/archive/refs/tags/v1.1.0.tar.gz", | ||
.hash = "1220e0aae36b81e1b99f86717dc67101fe0dcdc57c0ac05e1100aefb291f6dc4f7e0", | ||
}, | ||
}, | ||
.paths = .{ | ||
// This makes *all* files, recursively, included in this package. It is generally | ||
// better to explicitly list the files and directories instead, to insure that | ||
// fetching from tarballs, file system paths, and version control all result | ||
// in the same contents hash. | ||
"", | ||
// For example... | ||
//"build.zig", | ||
//"build.zig.zon", | ||
//"src", | ||
//"LICENSE", | ||
//"README.md", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const std = @import("std"); | ||
const schema = @import("schema.zig"); | ||
const Host = schema.Host; | ||
|
||
/// | ||
/// It takes IncomingEvent as input (An incoming event) | ||
pub fn handle(input: schema.IncomingEvent) !void { | ||
if (!std.mem.eql(u8, "content", input.kind)) { | ||
return; | ||
} | ||
|
||
_ = try Host.react(schema.OutgoingReaction{ | ||
.messageId = input.message.id, | ||
.with = "🦎", | ||
}); | ||
|
||
_ = try Host.react(schema.OutgoingReaction{ | ||
.messageId = input.message.id, | ||
.with = "⚡️", | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// THIS FILE WAS GENERATED BY `xtp-zig-bindgen`. DO NOT EDIT. | ||
const std = @import("std"); | ||
const extism = @import("extism-pdk"); | ||
|
||
const user = @import("main.zig"); | ||
const schema = @import("schema.zig"); | ||
|
||
const _plugin = extism.Plugin.init(std.heap.wasm_allocator); | ||
|
||
const ERR_PRINTING_MSG: []const u8 = "std.fmt.allocPrint failed when formatting plugin error"; | ||
|
||
export fn handle() i32 { | ||
// Get the input data | ||
// in JSON | ||
const json_input = _plugin.getJsonOpt(schema.IncomingEvent, .{}) catch |err| { | ||
const msg = std.fmt.allocPrint(_plugin.allocator, "{}", .{err}) catch ERR_PRINTING_MSG; | ||
_plugin.setError(msg); | ||
return -1; | ||
}; | ||
defer json_input.deinit(); | ||
|
||
var input = json_input.value(); | ||
// decode all the inner buffer fields from base64 (may be no-op) | ||
input = (input.XXX__decodeBase64Fields() catch |err| { | ||
const msg = std.fmt.allocPrint(_plugin.allocator, "{}", .{err}) catch ERR_PRINTING_MSG; | ||
_plugin.setError(msg); | ||
return -1; | ||
}).*; | ||
|
||
// Call the implementation function | ||
user.handle(input) catch |err| { | ||
const msg = std.fmt.allocPrint(_plugin.allocator, "{}", .{err}) catch ERR_PRINTING_MSG; | ||
_plugin.setError(msg); | ||
return -1; | ||
}; | ||
|
||
return 0; | ||
} |
Oops, something went wrong.