Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set default host function namespace to extism:host/user #37

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ kvStore := make(map[string][]byte)

kvRead := extism.NewHostFunctionWithStack(
"kv_read",
"env",
func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {
key, err := p.ReadString(stack[0])
if err != nil {
Expand All @@ -173,7 +172,6 @@ kvRead := extism.NewHostFunctionWithStack(

kvWrite := extism.NewHostFunctionWithStack(
"kv_write",
"env",
func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {
key, err := p.ReadString(stack[0])
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions extism_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ func TestHost_simple(t *testing.T) {

mult := NewHostFunctionWithStack(
"mult",
"env",
func(ctx context.Context, plugin *CurrentPlugin, stack []uint64) {
a := api.DecodeI32(stack[0])
b := api.DecodeI32(stack[1])
Expand Down Expand Up @@ -256,7 +255,6 @@ func TestHost_memory(t *testing.T) {

mult := NewHostFunctionWithStack(
"to_upper",
"host",
func(ctx context.Context, plugin *CurrentPlugin, stack []uint64) {
offset := stack[0]
buffer, err := plugin.ReadBytes(offset)
Expand All @@ -280,6 +278,8 @@ func TestHost_memory(t *testing.T) {
[]api.ValueType{PTR},
)

mult.SetNamespace("host")

if plugin, ok := plugin(t, manifest, mult); ok {
defer plugin.Close()

Expand All @@ -304,7 +304,6 @@ func TestHost_multiple(t *testing.T) {

green_message := NewHostFunctionWithStack(
"hostGreenMessage",
"env",
func(ctx context.Context, plugin *CurrentPlugin, stack []uint64) {
offset := stack[0]
input, err := plugin.ReadString(offset)
Expand All @@ -330,7 +329,6 @@ func TestHost_multiple(t *testing.T) {

purple_message := NewHostFunctionWithStack(
"hostPurpleMessage",
"env",
func(ctx context.Context, plugin *CurrentPlugin, stack []uint64) {
offset := stack[0]
input, err := plugin.ReadString(offset)
Expand Down
8 changes: 5 additions & 3 deletions host.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ type HostFunction struct {
Returns []api.ValueType
}

func (f *HostFunction) SetNamespace(namespace string) {
f.Namespace = namespace
}

// NewHostFunctionWithStack creates a new instance of a HostFunction, which is designed
// to provide custom functionality in a given host environment.
// Here's an example multiplication function that loads operands from memory:
//
// mult := NewHostFunctionWithStack(
// "mult",
// "env",
// func(ctx context.Context, plugin *CurrentPlugin, stack []uint64) {
// a := api.DecodeI32(stack[0])
// b := api.DecodeI32(stack[1])
Expand All @@ -75,15 +78,14 @@ type HostFunction struct {
// )
func NewHostFunctionWithStack(
name string,
namespace string,
callback HostFunctionStackCallback,
params []api.ValueType,
returnTypes []api.ValueType) HostFunction {

return HostFunction{
stackCallback: callback,
Name: name,
Namespace: namespace,
Namespace: "extism:host/user",
Params: params,
Returns: returnTypes,
}
Expand Down
9 changes: 4 additions & 5 deletions plugins/host/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module github.com/extism/extism-sdk-plugins-host

go 1.20
go 1.21.0

require (
github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263 // indirect
github.com/valyala/fastjson v1.6.3 // indirect
)
toolchain go1.21.1

require github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263
4 changes: 0 additions & 4 deletions plugins/host/go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
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/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
2 changes: 1 addition & 1 deletion plugins/host/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/extism/go-pdk"
)

//go:wasm-module env
//go:wasm-module extism:host/user
//export mult
func mult(x, y uint64) uint64

Expand Down
9 changes: 4 additions & 5 deletions plugins/host_memory/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module github.com/extism/extism-sdk-plugins-host-memory

go 1.20
go 1.21.0

require (
github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263 // indirect
github.com/valyala/fastjson v1.6.3 // indirect
)
toolchain go1.21.1

require github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263
4 changes: 0 additions & 4 deletions plugins/host_memory/go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
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/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
9 changes: 4 additions & 5 deletions plugins/host_multiple/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module github.com/extism/extism-sdk-plugins-host-multiple

go 1.20
go 1.21.0

require (
github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263 // indirect
github.com/valyala/fastjson v1.6.3 // indirect
)
toolchain go1.21.1

require github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263
4 changes: 0 additions & 4 deletions plugins/host_multiple/go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
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/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
4 changes: 4 additions & 0 deletions plugins/host_multiple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/extism/go-pdk"
)

//go:wasm-module extism:host/user
//export hostPurpleMessage
func hostPurpleMessage(offset uint64) uint64

Expand All @@ -13,6 +14,7 @@ func purpleMessage(message string) pdk.Memory {
return pdk.FindMemory(off)
}

//go:wasm-module extism:host/user
//export hostGreenMessage
func hostGreenMessage(offset uint64) uint64

Expand All @@ -22,6 +24,7 @@ func greenMessage(message string) pdk.Memory {
return pdk.FindMemory(off)
}

//go:wasm-module extism:host/user
//export say_purple
func say_purple() int32 {
input := pdk.InputString()
Expand All @@ -34,6 +37,7 @@ func say_purple() int32 {

}

//go:wasm-module extism:host/user
//export say_green
func say_green() int32 {
input := pdk.Input()
Expand Down
2 changes: 1 addition & 1 deletion plugins/log/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func run_test() int32 {
pdk.Log(pdk.LogDebug, "this is a debug log")
pdk.Log(pdk.LogInfo, "this is an info log")
pdk.Log(pdk.LogWarn, "this is a warning log")
pdk.Log(pdk.LogError, "this is an erorr log")
pdk.Log(pdk.LogError, "this is an error log")

return 0
}
Expand Down
9 changes: 4 additions & 5 deletions plugins/noop/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module github.com/extism/extism-sdk-plugins-noop

go 1.20
go 1.21.0

require (
github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263 // indirect
github.com/valyala/fastjson v1.6.3 // indirect
)
toolchain go1.21.1

require github.com/extism/go-pdk v1.0.0-rc1.0.20231019212020-62d54a6e0263
4 changes: 0 additions & 4 deletions plugins/noop/go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
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/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
5 changes: 4 additions & 1 deletion plugins/noop/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package main

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

//export run_test
func run_test() int32 {
return 0
pdk.SetErrorString("my custom error")
return 1
}

func main() {}
Binary file added plugins/noop/throw.wasm
Binary file not shown.
Binary file modified wasm/host.wasm
Binary file not shown.
Binary file modified wasm/host_memory.wasm
Binary file not shown.
Binary file modified wasm/host_multiple.wasm
Binary file not shown.