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

unknown import: wasi::thread-spawn has not been defined #218

Open
owenthereal opened this issue May 9, 2024 · 1 comment
Open

unknown import: wasi::thread-spawn has not been defined #218

owenthereal opened this issue May 9, 2024 · 1 comment

Comments

@owenthereal
Copy link

I'm trying to run a wasi program with threads enabled, but I'm getting the following when running it with wasmtime-go:

package main

import (
	"fmt"
	"log"
	"os"
	"path/filepath"

	"github.com/bytecodealliance/wasmtime-go"
)

func main() {
	dir, err := os.MkdirTemp("", "out")
	if err != nil {
		log.Fatal(err)
	}
	defer os.RemoveAll(dir)
	stdoutPath := filepath.Join(dir, "stdout")

	f, err := os.ReadFile(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}

	cfg := wasmtime.NewConfig()
	cfg.SetWasmThreads(true)

	engine := wasmtime.NewEngineWithConfig(cfg)

	module, err := wasmtime.NewModule(engine, f)
	if err != nil {
		log.Fatal(err)
	}

	linker := wasmtime.NewLinker(engine)
	err = linker.DefineWasi()
	if err != nil {
		log.Fatal(err)
	}

	wasiConfig := wasmtime.NewWasiConfig()
	wasiConfig.SetStdoutFile(stdoutPath)

	store := wasmtime.NewStore(engine)
	store.SetWasi(wasiConfig)
	instance, err := linker.Instantiate(store, module)
	if err != nil {
		log.Fatal(err)
	}

	nom := instance.GetFunc(store, "_start")
	_, err = nom.Call(store)
	if err != nil {
		log.Fatal(err)
	}

	// Print WASM stdout
	out, err := os.ReadFile(stdoutPath)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Print(string(out))
}

I was able to run it with wasmtime though: wasmtime --wasm threads --wasi threads program.wasm

@alexcrichton
Copy link
Member

Thanks for the report! This is expected though in that this import is part of the wasi-threads proposal which has not been implemented in the C API (nor standardized to a large degree)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants