1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

TinyGo でビルドした WASM コンテナを実行すると When linking module: "env" , function name: "runtime.ticks" エラー

Last updated at Posted at 2023-04-06

概要

以下のように TinyGo を使って WASM コンテナを作成したが、実行時にエラーが発生してしまった。

# WASM のコンパイル
docker run --rm -v ${PWD}:/home/tinygo \
	  tinygo/tinygo:0.27.0 \
	  tinygo build -target=wasm -o /home/tinygo/main.wasm

# WASM コンテナ作成
docker buildx build --platform wasi/wasm -t wasm-container .

# 実行
docker run --rm \
	  --runtime=io.containerd.wasmedge.v1 \
	  --platform=wasi/wasm \
	  wasm-container:latest
[2023-04-06 02:32:42.529] [error] instantiation failed: unknown import, Code: 0x62
[2023-04-06 02:32:42.529] [error]     When linking module: "env" , function name: "runtime.ticks"
[2023-04-06 02:32:42.529] [error]     At AST node: import description
[2023-04-06 02:32:42.529] [error]     This may be the import of host environment like JavaScript or Golang. Please check that you've registered the necessary host modules from the host programming language.
[2023-04-06 02:32:42.529] [error]     At AST node: import section
[2023-04-06 02:32:42.529] [error]     At AST node: module
docker: Error response from daemon: Others("unknown import"): unknown.

環境

  • TinyGo 0.27.0
  • Docker Desktop 4.17.1

原因

tinygo build 時の target を wasm にする。

        docker run --rm -v ${PWD}:/home/tinygo \
          tinygo/tinygo:0.27.0 \
-         tinygo build -target=wasi -o /home/tinygo/main.wasm
+         tinygo build -target=wasm -o /home/tinygo/main.wasm

また、docker build 時と docker run 時の platform を合わせないと、当然ながら docker run 時に Unable to find image エラーが発生するため注意。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?