bundle init bundle add ruby_wasm
エラーが出ました。
thread 'main' panicked at /home/ledsun/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rb-sys-0.9.97/build/main.rs:64:59: called `Result::unwrap()` on an `Err` value: "Stable API is needed but could not find a candidate. Try enabling the `stable-api-compiled-fallback` feature in rb-sys." note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace warning: build failed, waiting for other jobs to finish... cargo failed, exit code 101 Gem files will remain installed in /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/gems/3.4.0+0/gems/ruby_wasm-2.6.1 for inspection. Results logged to /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/gems/3.4.0+0/extensions/x86_64-linux/3.4.0+0-static/ruby_wasm-2.6.1/gem_make.out /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/rubygems/ext/builder.rb:125:in 'Gem::Ext::Builder.run' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/rubygems/ext/cargo_builder.rb:34:in 'Method#call' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/rubygems/ext/cargo_builder.rb:34:in 'Gem::Ext::CargoBuilder#build' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/rubygems/ext/builder.rb:193:in 'Gem::Ext::Builder#build_extension' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/rubygems/ext/builder.rb:227:in 'block in Gem::Ext::Builder#build_extensions' <internal:array>:54:in 'Array#each' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/rubygems/ext/builder.rb:224:in 'Gem::Ext::Builder#build_extensions' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/rubygems/installer.rb:852:in 'Gem::Installer#build_extensions' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/bundler/rubygems_gem_installer.rb:76:in 'Bundler::RubyGemsGemInstaller#build_extensions' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/bundler/rubygems_gem_installer.rb:28:in 'Bundler::RubyGemsGemInstaller#install' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/bundler/source/rubygems.rb:205:in 'Bundler::Source::Rubygems#install' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/bundler/installer/gem_installer.rb:54:in 'Bundler::GemInstaller#install' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/bundler/installer/gem_installer.rb:16:in 'Bundler::GemInstaller#install_from_spec' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/bundler/installer/parallel_installer.rb:132:in 'Bundler::ParallelInstaller#do_install' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/bundler/installer/parallel_installer.rb:123:in 'block in Bundler::ParallelInstaller#worker_pool' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/bundler/worker.rb:62:in 'Bundler::Worker#apply_func' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/bundler/worker.rb:57:in 'block in Bundler::Worker#process_queue' <internal:kernel>:191:in 'Kernel#loop' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/bundler/worker.rb:54:in 'Bundler::Worker#process_queue' /home/ledsun/.rbenv/versions/3.4-dev/lib/ruby/3.4.0+0/bundler/worker.rb:90:in 'block (2 levels) in Bundler::Worker#create_threads' An error occurred while installing ruby_wasm (2.6.1), and Bundler cannot continue. In Gemfile: ruby_wasm
念のためrustup update
しました。
変わりませんでした。
Rubyのバージョンの問題かもしれません。
rbenv local 3.4.0-preview1 gem install ruby_wasm
cargo failed, exit code 101 Gem files will remain installed in /home/ledsun/.rbenv/versions/3.4.0-preview1/lib/ruby/gems/3.4.0+0/gems/ruby_wasm-2.6.1 for inspection. Results logged to /home/ledsun/.rbenv/versions/3.4.0-preview1/lib/ruby/gems/3.4.0+0/extensions/x86_64-linux/3.4.0+0/ruby_wasm-2.6.1/gem_make.out
変わっていなさそうです。 Ruby 3.3.1だと?
ledsun@MSI:~/ruby.wasm-test[1]►rbenv local 3.3.1 ledsun@MSI:~/ruby.wasm-test►gem install ruby_wasm Fetching ruby_wasm-2.6.1-x86_64-linux.gem Successfully installed ruby_wasm-2.6.1-x86_64-linux Parsing documentation for ruby_wasm-2.6.1-x86_64-linux Installing ri documentation for ruby_wasm-2.6.1-x86_64-linux Done installing documentation for ruby_wasm after 0 seconds 1 gem installed A new release of RubyGems is available: 3.5.9 → 3.5.10! Run `gem update --system 3.5.10` to update your installation.
しゅっと行きました。
ruby.wasm開発用にビルドしていたgemが使えたみたいです。
せっかくなのでrbwasm
コマンドをつかってみましょう。
ledsun@MSI:~/ruby.wasm-test[1]►rbwasm build -o ruby.wasm % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 75.8M 100 75.8M 0 0 20.2M 0 0:00:03 0:00:03 --:--:-- 30.3M % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 40.4M 100 40.4M 0 0 18.4M 0 0:00:02 0:00:02 --:--:-- 28.8M ==> RubyWasm::BuildSource(3.3) -- Building ==> curl -L -o /home/ledsun/ruby.wasm-test/build/checkouts/3.3.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.1.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 21.0M 100 21.0M 0 0 19.0M 0 0:00:01 0:00:01 --:--:-- 19.0M ==> tar xf /home/ledsun/ruby.wasm-test/build/checkouts/3.3.tar.gz -C /home/ledsun/ruby.wasm-test/build/checkouts/3.3 --strip-components\=1 ==> RubyWasm::BuildSource(3.3) -- done in 1.78s ==> RubyWasm::BaseRubyProduct(baseruby-3.3) -- Building ==> /home/ledsun/ruby.wasm-test/build/checkouts/3.3/configure --prefix\=/home/ledsun/ruby.wasm-test/build/x86_64-pc-linux/baseruby-3.3/opt --disable-install-doc ==> make -j8 install
おお、これはruby.wasm自体をビルドするときによく見る奴です。 RubyのVMをコンパイルしています。 考えてみれば当たり前ですが、ruby.wasmをビルドするときと同じ手順を踏むんですね。
せっかくなのでruby.wasmファイルにgemを書き込んでみます。 とりあえず slim をインストールします。 C拡張を使っていなければ何でも良いです。
ledsun@MSI:~/ruby.wasm-test►bundle add slim Fetching gem metadata from https://rubygems.org/.. Resolving dependencies... Fetching gem metadata from https://rubygems.org/.. Resolving dependencies... Fetching temple 0.10.3 Installing temple 0.10.3 Fetching slim 5.2.1 Installing slim 5.2.1
bundle exec rbwasm build -o ruby.wasm
してみます。
ledsun@MSI:~/ruby.wasm-test►bundle exec rbwasm build -o ruby.wasm INFO: Using Gemfile: [#<Pathname:/home/ledsun/ruby.wasm-test/Gemfile>] ==> tar -C /tmp/d20240528-55886-raholf/usr -xzf /home/ledsun/ruby.wasm-test/rubies/ruby-3.3-wasm32-unknown-wasip1-full.tar.gz --strip-components\=2 INFO: Packaging gem: temple-0.10.3 INFO: Packaging gem: tilt-2.3.0 INFO: Packaging gem: slim-5.2.1 INFO: Packaging setup.rb: bundle/setup.rb INFO: Size: 51.83 MB
おお、すごい。 ruby.wasmファイルにgemが書き込まれています! はー、つまりGemfile.lockをみて必要なgemを探してきて書き込んでいるのでしょうか?
ついでにC拡張を使ったgemも試してみましょう。
bundle add rexml bundle exec rbwasm build -o ruby.wasm
こちらは失敗します。
bundler: failed to load command: rbwasm (/home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/bin/rbwasm) /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/build/executor.rb:77:in `system': Command failed with status (1): '/home/ledsun/ruby.wasm-test/build/x86_64-pc-linux/baseruby-3.3/opt/bin/ruby' '-C' '/home/ledsun/ruby.wasm-test/build/wasm32-unknown-wasip1/ruby-3.3-wasm32-unknown-wasip1-full-f7ec96ef2eaad9f30ae602f0a709d006-ext/strscan-3.1.0/ext/strscan' '--disable=gems' '-e' '$top_srcdir="/home/ledsun/ruby.wasm-test/build/checkouts/3.3"' '-e' '$extout="/home/ledsun/ruby.wasm-test/build/wasm32-unknown-wasip1/ruby-3.3-wasm32-unknown-wasip1-full-f7ec96ef2eaad9f30ae602f0a709d006/.ext"' '-e' '$static = true; trace_var(:$static) {|v| $static = true }' '-e' '$0="/home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/strscan-3.1.0/ext/strscan/extconf.rb"' '-e' 'require_relative "/home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/strscan-3.1.0/ext/strscan/extconf.rb"' '-e' 'require "json"; File.write("/home/ledsun/ruby.wasm-test/build/wasm32-unknown-wasip1/ruby-3.3-wasm32-unknown-wasip1-full-f7ec96ef2eaad9f30ae602f0a709d006-ext/strscan-3.1.0/ext/strscan/rbwasm.metadata.json", JSON.dump({target: $target}))' '-I/home/ledsun/ruby.wasm-test/build/wasm32-unknown-wasip1/ruby-3.3-wasm32-unknown-wasip1-full-f7ec96ef2eaad9f30ae602f0a709d006' '--' (RuntimeError) from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/build/product/crossruby.rb:117:in `do_legacy_extconf' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/build/product/crossruby.rb:70:in `do_extconf' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/build/product/crossruby.rb:48:in `build' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/build/product/crossruby.rb:191:in `block in build_exts' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/build/product/crossruby.rb:189:in `each' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/build/product/crossruby.rb:189:in `build_exts' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/build/product/crossruby.rb:210:in `build' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/packager/core.rb:274:in `block in build' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler.rb:404:in `block in with_unbundled_env' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler.rb:659:in `with_env' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler.rb:404:in `with_unbundled_env' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/packager/core.rb:283:in `build' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/packager/core.rb:10:in `build' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/packager.rb:28:in `package' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/cli.rb:344:in `do_build' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/cli.rb:171:in `block in do_build_with_force_ruby_platform' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/tmpdir.rb:99:in `mktmpdir' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/cli.rb:170:in `do_build_with_force_ruby_platform' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/cli.rb:137:in `block in build' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler/settings.rb:158:in `temporary' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/cli.rb:136:in `build' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/lib/ruby_wasm/cli.rb:34:in `run' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ruby_wasm-2.6.1-x86_64-linux/exe/rbwasm:7:in `<top (required)>' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/bin/rbwasm:25:in `load' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/bin/rbwasm:25:in `<top (required)>' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler/cli/exec.rb:58:in `load' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler/cli/exec.rb:58:in `kernel_load' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler/cli/exec.rb:23:in `run' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler/cli.rb:451:in `exec' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor/command.rb:28:in `run' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor.rb:527:in `dispatch' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler/cli.rb:34:in `dispatch' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor/base.rb:584:in `start' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler/cli.rb:28:in `start' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/bundler-2.5.9/exe/bundle:28:in `block in <top (required)>' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundler/friendly_errors.rb:117:in `with_friendly_errors' from /home/ledsun/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/bundler-2.5.9/exe/bundle:20:in `<top (required)>' from /home/ledsun/.rbenv/versions/3.3.1/bin/bundle:25:in `load' from /home/ledsun/.rbenv/versions/3.3.1/bin/bundle:25:in `<main>'
なるほど興味深いです。