# Download prebuilt ruby
curl -LO https://github.com/ruby/ruby.wasm/releases/download/2022-08-09-a/ruby-head-wasm32-unknown-wasi-full.tar.gz
tar xfz ruby-head-wasm32-unknown-wasi-full.tar.gz
# Install the same version of native ruby to avoid bundler version mismatch in "BUNDLED WITH" of Gemfile.lock
rbenv install 3.2.0-dev
rbenv local 3.2.0-dev
# Setup Gemfile
bundle init
bundle add syntax_tree
# Install gems in vendor/bundle to mount it on WASI
bundle config set --local path 'vendor/bundle'
bundle install
cat <<EOS > my_app.rb
# 'require "bundler/setup"' is not precisely equivalent to 'bundle exec ...', but enough to load installed gems
require "bundler/setup"
require "syntax_tree"
pp SyntaxTree.parse("1 + 1")
EOS
# Options:
# --mapdir /usr::./head-wasm32-unknown-wasi-full/usr Map ruby directory
# --mapdir /root::./ Map user script directory
# --env BUNDLE_GEMFILE=/root/Gemfile Tell bundler where the Gemfile located because WASI has no PWD concept
wasmtime run \
--mapdir /usr::./head-wasm32-unknown-wasi-full/usr \
--mapdir /root::./ \
--env BUNDLE_GEMFILE=/root/Gemfile \
head-wasm32-unknown-wasi-full/usr/local/bin/ruby -- /root/my_app.rb
Last active
September 11, 2023 21:25
-
-
Save kateinoigakukun/5caf3b83b2732b1653e91b0e75ce3390 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been playing with this trying to get it working. I'll use the dir structure in the repo README, which has src/ instead of root/.
Here's what I run (breaking it into 2 parts - I am not sure how the above could ever work, it needs to be built first, then run, right?)
Running that I get:
Any ideas? Do I need to be using HEAD instead of
ruby-3_2-wasm32-unknown-wasi-full.tar.gz
?