Skip to content

Ready to use development platform to learn Extism plug-in creation

License

Notifications You must be signed in to change notification settings

bots-garden/extism-playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Extism playground

🍊 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

Create a TinyGo plug-in

Generate the project

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() {}

Build the wasm plug-in

tinygo build -scheduler=none --no-debug \
-o hello.wasm \
-target wasi main.go

Call the function with the Extism CLI

extism call hello.wasm hello --input "Bob Morane" --wasi
# you should get: 🤗 Hello Bob Morane

Create a Rust plug-in

Generate the project

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))
}

Build the wasm plug-in

cargo clean
cargo build --release --target wasm32-wasi

Call the function with the Extism CLI

extism call ./target/wasm32-wasi/release/hello.wasm hello --input "Bob Morane" --wasi
# you should get: 👋 Hello, Bob Morane!

Create a JavaScript plug-in

Generate the project

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}

Build the wasm plug-in

extism-js index.js -o hello-world.wasm

Call the function with the Extism CLI

extism call hello-world.wasm helloWorld --input "Bob Morane" --wasi
# you should get: 👋 Hello world 🌍, Bob Morane 🤗

About

Ready to use development platform to learn Extism plug-in creation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published