@ledsun blog

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

ruby.wasmがビルドできない

ruby.wasmのビルドが通らなくなったので、環境を最新にします。

cd vendor/jco/
git reset --hard
cd ../..
git submodule update

します。 この手順が要るかはよくわかっていません。 雰囲気でやっています。

bin/setup に成功するまで

bin/setupを実行すると次のエラーが出ます。

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

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

次のコマンドを実行します。

rustup update
rustup target add wasm32-wasip1`

bin/setupが成功するようになります。

rake npm:ruby-head-wasm-wasi には成功しない

rake npm:ruby-head-wasm-wasiを実行すると失敗します。

Rubyのビルド済み環境にリセットします。 rake build:download_prebuiltを実行します。

rake npm:ruby-head-wasm-wasiを実行すると失敗します。 次のようなエラーが出ます。

  ==> make -j8 install DESTDIR\=/home/ledsun/ruby.wasm/build/wasm32-unknown-wasip1-pic/ruby-head-wasm32-unknown-wasip1-pic-full/install
clang-16clang-16clang-16: : : warning: warning: warning: argument unused during compilation: '-shared' [-Wunused-command-line-argument]
argument unused during compilation: '-shared' [-Wunused-command-line-argument]argument unused during compilation: '-shared' [-Wunused-command-line-argument]

clang-16: warning: argument unused during compilation: '-shared' [-Wunused-command-line-argument]
wasm-ld: error: enc/cp949.o: undefined symbol: rb_enc_register
...
rake aborted!
Command failed with status (1): [RUBY_WASM_ROOT=/home/ledsun/ruby.wasm RUBY_WASM_EXPERIMENTAL_DYNAMIC_LINKING=1 bundle exec /home/ledsun/ruby.wasm/exe/rbwasm build --ruby-version head --target wasm32-unknown-wasip1 --build-profile full -o /home/ledsun/ruby.wasm/packages/npm-packages/ruby-head-wasm-wasi/tmp/ruby.component.wasm]
/home/ledsun/ruby.wasm/rakelib/packaging.rake:83:in 'block (5 levels) in <top (required)>'
/home/ledsun/ruby.wasm/rakelib/packaging.rake:69:in 'Dir.chdir'
/home/ledsun/ruby.wasm/rakelib/packaging.rake:69:in 'block (4 levels) in <top (required)>'
/home/ledsun/ruby.wasm/rakelib/packaging.rake:123:in 'block (3 levels) in <top (required)>'
Tasks: TOP => npm:ruby-head-wasm-wasi:build => npm:ruby-head-wasm-wasi:ruby
(See full trace by running task with --trace)

どうも RUBY_WASM_ROOT=/home/ledsun/ruby.wasm RUBY_WASM_EXPERIMENTAL_DYNAMIC_LINKING=1 bundle exec /home/ledsun/ruby.wasm/exe/rbwasm build --ruby-version head --target wasm32-unknown-wasip1 --build-profile full -o /home/ledsun/ruby.wasm/packages/npm-packages/ruby-head-wasm-wasi/tmp/ruby.component.wasm を実行した時にエラーが起きているようです。

ruby.component.wasmを作ろうとしてリンクに失敗しているように思います。

vender/jcoをリセット

jcoのupdateが良くないのかもしれません。 念のため初期状態に戻します。

rm -rf venber/jco
git submodule update --init

bin/setupを実行します。

`RUBY_WASM_ROOT=/home/ledsun/ruby.wasm RUBY_WASM_EXPERIMENTAL_DYNAMIC_LINKING=1 bundle exec /home/ledsun/ruby.wasm/exe/rbwasm build --ruby-version head --target wasm32-unknown-wasip1 --build-profile full -o /home/ledsun/ruby.wasm/packages/npm-packages/ruby-head-wasm-wasi/tmp/ruby.component.wasm に成功しない

RUBY_WASM_ROOT=/home/ledsun/ruby.wasm RUBY_WASM_EXPERIMENTAL_DYNAMIC_LINKING=1 bundle exec /home/ledsun/ruby.wasm/exe/rbwasm build --ruby-version head --target wasm32-unknown-wasip1 --build-profile full -o /home/ledsun/ruby.wasm/packages/npm-packages/ruby-head-wasm-wasi/tmp/ruby.component.wasm を実行します。 エラーが起きます。

make[1]: Leaving directory '/home/ledsun/ruby.wasm/build/wasm32-unknown-wasip1-pic/ruby-head-wasm32-unknown-wasip1-pic-full'
transdb.h unchanged
clang-16clang-16clang-16: : : warning: warning: warning: argument unused during compilation: '-shared' [-Wunused-command-line-argument]
argument unused during compilation: '-shared' [-Wunused-command-line-argument]
argument unused during compilation: '-shared' [-Wunused-command-line-argument]
clang-16: warning: argument unused during compilation: '-shared' [-Wunused-command-line-argument]
wasm-ld: error: enc/cesu_8.o: undefined symbol: rb_enc_register
wasm-ld: error: enc/cesu_8.o: undefined symbol: OnigEncAsciiToLowerCaseTable
...
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [enc.mk:407: .ext/wasm32-wasi/enc/emacs_mule.so] Error 1
make: *** [uncommon.mk:1041: enc] Error 2
make: *** Waiting for unfinished jobs....
Try running with `rake --verbose` for more complete output.
bundler: failed to load command: /home/ledsun/ruby.wasm/exe/rbwasm (/home/ledsun/ruby.wasm/exe/rbwasm)
/home/ledsun/ruby.wasm/lib/ruby_wasm/build/executor.rb:77:in 'RubyWasm::BuildExecutor#system': Command failed with status (2): 'make' '-j8' 'install' 'DESTDIR=/home/ledsun/ruby.wasm/build/wasm32-unknown-wasip1-pic/ruby-head-wasm32-unknown-wasip1-pic-full/install' (RuntimeError)
        from /home/ledsun/ruby.wasm/lib/ruby_wasm/build/product/crossruby.rb:225:in 'RubyWasm::CrossRubyProduct#build'

エラーは大きくは変わっていません。

makeで失敗している

次のコマンドでエラーが再現できるようです。

cd build/wasm32-unknown-wasip1-pic/ruby-head-wasm32-unknown-wasip1-pic-full
make install

もう少し絞れそうです。

cd /home/ledsun/ruby.wasm/build/wasm32-unknown-wasip1-pic/ruby-head-wasm32-unknown-wasip1-pic-full/ext/cgi/escape
make
linking shared-object cgi/escape.so
clang-16: warning: argument unused during compilation: '-shared' [-Wunused-command-line-argument]
wasm-ld: error: escape.o: undefined symbol: rb_ext_ractor_safe
wasm-ld: error: escape.o: undefined symbol: rb_intern2
wasm-ld: error: escape.o: undefined symbol: rb_cObject
wasm-ld: error: escape.o: undefined symbol: rb_define_class
wasm-ld: error: escape.o: undefined symbol: rb_define_module_under
wasm-ld: error: escape.o: undefined symbol: rb_define_module_under
wasm-ld: error: escape.o: undefined symbol: rb_define_alias
wasm-ld: error: escape.o: undefined symbol: rb_define_alias
wasm-ld: error: escape.o: undefined symbol: rb_prepend_module
wasm-ld: error: escape.o: undefined symbol: rb_extend_object
wasm-ld: error: escape.o: undefined symbol: rb_string_value
wasm-ld: error: escape.o: undefined symbol: rb_enc_get
wasm-ld: error: escape.o: undefined symbol: rb_enc_dummy_p
wasm-ld: error: escape.o: undefined symbol: rb_call_super
wasm-ld: error: escape.o: undefined symbol: rb_string_value
wasm-ld: error: escape.o: undefined symbol: rb_enc_get
wasm-ld: error: escape.o: undefined symbol: rb_enc_dummy_p
wasm-ld: error: escape.o: undefined symbol: rb_enc_get
wasm-ld: error: escape.o: undefined symbol: ruby_scan_digits
wasm-ld: error: escape.o: undefined symbol: ruby_scan_digits
wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:274: ../../../.ext/wasm32-wasi/cgi/escape.so] Error 1

soファイルをwasm上でダイナミックリンクするための変換処理が上手く行ってなさそうです。 しかし、どうすれば解消できるのかはわかりません。