🍊 Open this project with Gitpod
Ready to use development platform to learn Extism plug-in creation
This project is "Gitpodified" and brings to you all the necessary tools to start quickly with the development of the Extism plug-ins.
Installed components | Version |
---|---|
Extism CLI | 0.3.3 |
Go | 1.21.3 |
TinyGo | 0.30.0 |
Rustc / Cargo | 1.74.1 |
Wasm-pack | 0.12.1 |
Node.js | 20.10.0 |
Extism-js | 1.0.0-rc1 |
🐳 The Docker image https://hub.docker.com/r/k33g/gitpod-extism-playground used by the Gitpod project is built with this Dockerfile:
docker/Dockerfile
mkdir hello
cd hello
go mod init hello
go get github.com/extism/go-sdk
touch main.go
Add this source code to main.go
:
package main
import (
"github.com/extism/go-pdk"
)
//export hello
func hello() {
input := pdk.Input()
message := "🤗 Hello " + string(input)
mem := pdk.AllocateString(message)
pdk.OutputMemory(mem)
}
func main() {}
tinygo build -scheduler=none --no-debug \
-o hello.wasm \
-target wasi main.go
extism call hello.wasm hello --input "Bob Morane" --wasi
# you should get: 🤗 Hello Bob Morane
cargo new --lib hello_demo --name hello
cd hello_demo
cargo add extism-pdk@1.0.0-rc1
Add this section to the Cargo.toml
file:
[lib]
crate_type = ["cdylib"]
Replace the source code of srg/lib.rs
by this content:
use extism_pdk::*;
#[plugin_fn]
pub fn hello(name: String) -> FnResult<String> {
Ok(format!("👋 Hello, {}!", name))
}
cargo clean
cargo build --release --target wasm32-wasi
extism call ./target/wasm32-wasi/release/hello.wasm hello --input "Bob Morane" --wasi
# you should get: 👋 Hello, Bob Morane!
mkdir hello-world
cd hello-world
touch index.js
Add this source code to index.js
:
function helloWorld() {
const name = Host.inputString()
Host.outputString(`👋 Hello world 🌍, ${name} 🤗`)
}
module.exports = {helloWorld}
extism-js index.js -o hello-world.wasm
extism call hello-world.wasm helloWorld --input "Bob Morane" --wasi
# you should get: 👋 Hello world 🌍, Bob Morane 🤗