@ledsun blog

無味の味は佳境に入らざればすなわち知れず

ruby.wasmのビルド環境整備

最新のruby.wasmをビルドするために rake npm:ruby-head-wasm-wasi を実行したら次のエラーが出ました。

npx jco transpile --no-wasi-shim --instantiation --valid-lifting-optimization /home/ledsun/ruby.wasm/packages/npm-packages/ruby-head-wasm-wasi/tmp/ruby.component.wasm -o /home/ledsun/ruby.wasm/packages/npm-packages/ruby-head-wasm-wasi/dist/component
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/jco - Not found
npm ERR! 404
npm ERR! 404  'jco@*' is not in this registry.
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in: /home/ledsun/.npm/_logs/2024-04-30T01_24_05_969Z-debug-0.log
rake aborted!

jcoという見慣れない名前があります。 名前からすると Add jco-generated TypeScript interface of the js gem world by kateinoigakukun · Pull Request #432 · ruby/ruby.wasm · GitHub が関係ありそうです。

jcoはgit submoduleで参照しています。 git submodule update --initしてみます。

ledsun@MSI:~/ruby.wasm[1]►git submodule update --init
Submodule 'vendor/jco' (https://github.com/bytecodealliance/jco.git) registered for path 'vendor/jco'
fatal: destination path '/home/ledsun/ruby.wasm/vendor/jco' already exists and is not an empty directory.
fatal: clone of 'https://github.com/bytecodealliance/jco.git' into submodule path '/home/ledsun/ruby.wasm/vendor/jco' failed
Failed to clone 'vendor/jco'. Retry scheduled
fatal: destination path '/home/ledsun/ruby.wasm/vendor/jco' already exists and is not an empty directory.
fatal: clone of 'https://github.com/bytecodealliance/jco.git' into submodule path '/home/ledsun/ruby.wasm/vendor/jco' failed
Failed to clone 'vendor/jco' a second time, aborting

vendor/jco が既にありました。 jcoは以前からあって、参照方法が変わったのかもしれません。 vendor/jco を削除してgit submodule update --initしなおします。

bin/setupしてみます。

error[E0463]: can't find crate for `core`
  |
  = note: the `wasm32-wasi` target may not be installed
  = help: consider downloading the target with `rustup target add wasm32-wasi`

error[E0463]: can't find crate for `compiler_builtins`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `cfg-if` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
Error: command exited with non-zero code `cargo build --workspace --target wasm32-wasi`: 101

rustcでのビルドでエラーが出ました。 エラーメッセージの通り rustup target add wasm32-wasi をしてみます。

ledsun@MSI:~/ruby.wasm[1]►rustup target add wasm32-wasi
info: downloading component 'rust-std' for 'wasm32-wasi'
info: installing component 'rust-std' for 'wasm32-wasi'
 18.6 MiB /  18.6 MiB (100 %)  16.6 MiB/s in  1s ETA:  0s

rustのライブラリーが古かったみたいです。 あとはいつも通り

bin/setup
rake npm:ruby-head-wasm-wasi

でビルドできました。

よく見ると、gitの変更が残っています。

ledsun@MSI:~/ruby.wasm►git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
        modified:   vendor/jco (modified content)

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        packages/npm-packages/ruby-head-wasm-wasi/tmp/

no changes added to commit (use "git add" and/or "git commit -a")

git submoduleの方はわかります。 packages/npm-packages/ruby-head-wasm-wasi/tmp/ は、なんでしょうか? ruby.component.wasmというファイルが一つだけあります。

これは .gitignore に入れても良さそうです。 それともビルド成功時に tmp ディレクトリを消す方が良いのかな? パッと判断がつきません。