Skip to content

Commit

Permalink
feat: support EXTISM_ENABLE_WASI_OUTPUT (#51)
Browse files Browse the repository at this point in the history
for any program that embeds the Go SDK, 

```sh
EXTISM_ENABLE_WASI_OUTPUT=1 extism call code.wasm foo --wasi 
will print things from e.g. fmt.Println (to stdout or stderr as needed)
```

brings the SDK into parity with the Rust runtime which has the same
behavior.

---------

Co-authored-by: zach <zach@dylibso.com>
  • Loading branch information
nilslice and zshipko authored Jan 2, 2024
1 parent 073f096 commit 43f5bda
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions extism.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ func NewPlugin(
// See: https://github.com/extism/go-sdk/pull/1#issuecomment-1650527495
moduleConfig = moduleConfig.WithStartFunctions().WithFSConfig(fs)

_, wasiOutput := os.LookupEnv("EXTISM_ENABLE_WASI_OUTPUT")
if c.hasWasi && wasiOutput {
moduleConfig = moduleConfig.WithStderr(os.Stderr).WithStdout(os.Stdout)
}

// Try to find the main module:
// - There is always one main module
// - If a Wasm value has the Name field set to "main" then use that module
Expand Down
10 changes: 10 additions & 0 deletions plugins/println/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/extism/extism-sdk-plugins-println

go 1.21.0

toolchain go1.21.1

require (
github.com/extism/go-pdk v1.0.0-rc2 // indirect
github.com/valyala/fastjson v1.6.3 // indirect
)
8 changes: 8 additions & 0 deletions plugins/println/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/extism/go-pdk v0.0.0-20230119214914-65bffbeb3e64 h1:IfR1k741q+yQLvv5sLShCkvt3FgKU4wQVJfp7hhb/iY=
github.com/extism/go-pdk v0.0.0-20230119214914-65bffbeb3e64/go.mod h1:1wdiAoG8306g4WK+6laBrS+75089/0V4XRVTllt8b5U=
github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263 h1:uSo+K1JhsMlamDmaxyAGj0dGExZHLsL+Edyug0dC+uk=
github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263/go.mod h1:Gz+LIU/YCKnKXhgge8yo5Yu1F/lbv7KtKFkiCSzW/P4=
github.com/extism/go-pdk v1.0.0-rc2 h1:EZuo8idErnV8KB8TTSTiO2T1lkX047OQ7K8STjn2WBs=
github.com/extism/go-pdk v1.0.0-rc2/go.mod h1:Gz+LIU/YCKnKXhgge8yo5Yu1F/lbv7KtKFkiCSzW/P4=
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
16 changes: 16 additions & 0 deletions plugins/println/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"fmt"

pdk "github.com/extism/go-pdk"
)

//export run_test
func run_test() int32 {
input := pdk.InputString()
fmt.Println("this was printed from the plugin", input)
return 0
}

func main() {}
Binary file added wasm/println.wasm
Binary file not shown.

0 comments on commit 43f5bda

Please sign in to comment.