Skip to content

WASM returns blank values using Go 1.26 built-in "new" function #5414

@mrcook

Description

@mrcook

Hi, I'm wanting to use the Go 1.26 built-in new function in WASM plugins (via Extism), but when compiling with TinyGo all the values are blank.

Here's an example plugin showing the behaviour:

type Person struct {
	Name *string
	Age  *int
}

func main() {}

//go:wasmexport person
func person() int32 {
	name := "Dickens"
	age := 31

	charles := Person{
		Name: new(name),
		Age:  new(age),
	}
	// Host application receives:
	// TinyGo: {"Name":"","Age":0}
	// Go:     {"Name":"Dickens","Age":31}

	// charles := Person{
	// 	Name: &name,
	// 	Age:  &age,
	// }
	// Host application receives:
	// TinyGo: {"Name":"Dickens","Age":31}
	// Go:     {"Name":"Dickens","Age":31}

	if err := pdk.OutputJSON(charles); err != nil {
		return 1
	}
	return 0
}

I'm using macos 15.7.5:

$ tinygo version
=> tinygo version 0.41.1 darwin/arm64 (using go version go1.26.3 and LLVM version 20.1.1)
$ go version
=> go version go1.26.3 darwin/arm64

$ tinygo build -target wasi -buildmode=c-shared -o plugin-tiny.wasm .
$ GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o plugin-go.wasm .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions