mirror of
https://github.com/extism/extism.git
synced 2026-01-08 05:23:55 -05:00
Add `plugin.call_with_host_context` and `current_plugin.host_context` methods, enabling per-call context to be looped from the guest invocation to any host functions it calls. In an HTTP server environment, this enables re-using a plugin across multiple requests while switching out backing connections and user information in host functions. (Imagine a host function, `update_user` -- previously the plugin would have to have been aware of the user to pass to the host function. Now that information is ambient.) This is a backwards-compatible change and requires no changes to existing plugins. Implement by adding a global, mutable externref to the extism kernel. Since most programming languages, including Rust, don't let you define these natively, we accomplish this by using `wasm-merge` to combine the kernel Wasm with Wasm generated by a WAT file containing only the global. (This pattern might be useful for other Wasm constructs we can't use directly from Rust, like `v128` in argument parameters.) Wasmtime requires extern refs to be `Any + Send + Sync + 'static`; we additionally add `Clone`. I haven't tried this with an `Arc` directly, but it should work at least for container structs that hold `Arc`'s themselves.
26 lines
809 B
Bash
Executable File
26 lines
809 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
export CARGO_FLAGS=""
|
|
|
|
while getopts d flag
|
|
do
|
|
case "${flag}" in
|
|
d)
|
|
echo "Disabled bounds-checking";
|
|
export CARGO_FLAGS="--no-default-features";;
|
|
*)
|
|
echo "usage $0 [-d]"
|
|
echo "\t-d: build with bounds checking disabled"
|
|
exit 1
|
|
esac
|
|
done
|
|
|
|
cargo build --package extism-runtime-kernel --bin extism-runtime --release --target wasm32-unknown-unknown $CARGO_FLAGS
|
|
cp target/wasm32-unknown-unknown/release/extism-runtime.wasm .
|
|
|
|
wasm-tools parse extism-context.wat -o extism-context.wasm
|
|
wasm-merge --enable-reference-types ./extism-runtime.wasm runtime extism-context.wasm context -o ../runtime/src/extism-runtime.wasm
|
|
rm extism-context.wasm
|
|
rm extism-runtime.wasm
|
|
wasm-strip ../runtime/src/extism-runtime.wasm
|