Closed6
Wasmer を使ってみる

まずはこちらを参考に試す。
WebAssemblyをブラウザの外で動かすWasmerを触ってみた
ソースコードはここ。

$ curl https://get.wasmer.io -sSfL | sh

~/.wasmer
にインストールされるみたいなので、PATHを通しておく必要がある。
$ export WASMER_DIR="${HOME}/.wasmer"
$ export PATH="${WASMER_DIR}/bin:${PATH}"

$ wasmer --help
wasmer 1.0.0
Wasmer Engineering Team <engineering@wasmer.io>
WebAssembly standalone runtime.
USAGE:
wasmer <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
SUBCOMMANDS:
cache Wasmer cache
compile Compile a WebAssembly binary
config Get various configuration information needed to compile programs which use Wasmer
create-exe Compile a WebAssembly binary into a native executable
help Prints this message or the help of the given subcommand(s)
inspect Inspect a WebAssembly file
run Run a WebAssembly file. Formats accepted: wasm, wat
self-update Update wasmer to the latest version
validate Validate a WebAssembly binary
wast Run spec testsuite
$ wapm
wapm-cli 0.5.0
USAGE:
wapm <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
SUBCOMMANDS:
add Add packages to the manifest without installing
bin Get the .bin dir path
config Config related subcommands
execute Execute a command, installing it temporarily if necessary
help Prints this message or the help of the given subcommand(s)
init Set up current directory for use with wapm
install Install a package
keys Manage minisign keys for verifying packages
list List the currently installed packages and their commands
login Logins into wapm, saving the token locally for future commands
logout Remove the token for the registry
publish Publish a package
remove Remove packages from the manifest
run Run a command from the package or one of the dependencies
run-background-update-check Run the background updater explicitly
search Search packages
uninstall Uninstall a package
validate Check if a directory or tar.gz is a valid wapm package
whoami Prints the current user (if authed) in the stdout

$ wapm install quickjs
[INFO] Installing _/quickjs@0.0.3
Package installed successfully to wapm_packages!
$ wapm run qjs
QuickJS - Type "\h" for help
qjs > console.log("Hello, Wasmer!")
console.log("Hello, Wasmer!")
Hello, Wasmer!
undefined
qjs >

適当にUUIDv4を生成して表示するだけのソースを作ってやるとできた!
$ rustup target add wasm32-wasi
$ cargo build --release --target wasm32-wasi
$ wasmer run target/wasm32-wasi/release/genuuid.wasm
ebb8900c-efd6-4683-89ce-03cab271e51a
このスクラップは2021/04/02にクローズされました