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_snapshot_preview1::fd_write has not been defined #149

Open
rayowang opened this issue Sep 12, 2022 · 4 comments
Open

Comments

@rayowang
Copy link

rayowang commented Sep 12, 2022

I got a strange error when using libwasmtime.dylib on macos:
2022-09-12 23:25:39,764 [ERROR] [wasmtime][instance] Start fail to new wasmtimego instance, err: unknown import: wasi_snapshot_preview1::fd_write has not been defined

@rayowang
Copy link
Author

rayowang commented Sep 12, 2022

The wasm module code:

package main

import (
	"errors"
	"strings"

	"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
	"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
)

func main() {
	proxywasm.SetVMContext(&vmContext{})
}

type vmContext struct {
	// Embed the default VM context here,
	// so that we don't need to reimplement all the methods.
	types.DefaultVMContext
}

// Override types.DefaultVMContext.
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
	return &pluginContext{}
}

type pluginContext struct {
	// Embed the default plugin context here,
	// so that we don't need to reimplement all the methods.
	types.DefaultPluginContext
}

// Override types.DefaultPluginContext.
func (*pluginContext) NewHttpContext(contextID uint32) types.HttpContext {
	return &httpHeaders{contextID: contextID}
}

type httpHeaders struct {
	// Embed the default http context here,
	// so that we don't need to reimplement all the methods.
	types.DefaultHttpContext
	contextID uint32
}

// Override types.DefaultHttpContext.
func (ctx *httpHeaders) OnHttpRequestBody(bodySize int, endOfStream bool) types.Action {
	//1. get request body
	body, err := proxywasm.GetHttpRequestBody(0, bodySize)
	if err != nil {
		proxywasm.LogErrorf("GetHttpRequestBody failed: %v", err)
		return types.ActionPause
	}

	//2. parse request param
	bookName, err := getQueryParam(string(body), "name")
	if err != nil {
		proxywasm.LogErrorf("param not found: %v", err)
		return types.ActionPause
	}

	//3. request function2 through ABI
	inventories, err := proxywasm.InvokeService("id_2", "", bookName)
	if err != nil {
		proxywasm.LogErrorf("invoke service failed: %v", err)
		return types.ActionPause
	}

	//4. return result
	proxywasm.AppendHttpResponseBody([]byte("There are " + inventories + " inventories for " + bookName + "."))
	return types.ActionContinue
}

func getQueryParam(body string, paramName string) (string, error) {
	kvs := strings.Split(body, "&")
	for _, kv := range kvs {
		param := strings.Split(kv, "=")
		if param[0] == paramName {
			return param[1], nil
		}
	}
	return "", errors.New("not found")
}

// Override types.DefaultHttpContext.
func (ctx *httpHeaders) OnHttpStreamDone() {
	proxywasm.LogInfof("%d finished", ctx.contextID)
}

const ID = "id_1"

// DO NOT MODIFY THE FOLLOWING FUNCTIONS!
//export proxy_get_id
func GetID() {
	_ = ID[len(ID)-1]
	proxywasm.SetCallData([]byte(ID))
`

@rayowang rayowang changed the title I got a strange error: unknown import: wasi_snapshot_preview1::fd_write has not been defined I got a strange error when using libwasmtime.dylib on macos: unknown import: wasi_snapshot_preview1::fd_write has not been defined Sep 12, 2022
@rayowang rayowang changed the title I got a strange error when using libwasmtime.dylib on macos: unknown import: wasi_snapshot_preview1::fd_write has not been defined unknown import: wasi_snapshot_preview1::fd_write has not been defined Sep 12, 2022
@alexcrichton
Copy link
Member

Thanks for the report, but this looks like a pretty deep error within the system. Can you explain more why you think the bug is within this module's bindings and not elsewhere?

@rayowang
Copy link
Author

rayowang commented Sep 13, 2022

Thanks for the report, but this looks like a pretty deep error within the system. Can you explain more why you think the bug is within this module's bindings and not elsewhere?

I checked some information, such as this issue #55, is this issue #149 also related to the rust command for compiling dynamic libraries?

@alexcrichton
Copy link
Member

Perhaps? I think that's related to the toolchain rather than this module, then.

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