Skip to content

Commit

Permalink
build a smaller wasm file
Browse files Browse the repository at this point in the history
  • Loading branch information
Largo committed Feb 13, 2024
1 parent f19ddfb commit b3a17c5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ruby -run -e httpd . -p 8080

## Todo
- [x] explain how to add code outside gems to the image
- [ ] show how to shrink/compress the ruby.wasm file (currently 51MB with debug info, but can be about 10mb or less.)
- [X] ~~show how to shrink/compress the ruby.wasm file (currently 51MB with debug info, but can be about 10mb or less.)~~
- [ ] license + explanation
- [ ] ask upstream if they can make a javascript file that doesnt have the .wasm file path hardcoded.
- [ ] docker file
Expand All @@ -54,6 +54,7 @@ ruby -run -e httpd . -p 8080
- [ruby.wasmでrequire_relativeを使えるようにしたい #Ruby - Qiita](https://qiita.com/ledsun/items/3f8ba1ee2699d546c18c#fetch%E3%81%8C%E9%9D%9E%E5%90%8C%E6%9C%9F%E9%96%A2%E6%95%B0)
- [RubyでWebAssemblyを試してみよう #ruby #WebAssembly #WASM #WASI - クリエーションライン株式会社](https://www.creationline.com/tech-blog/60328)
- [how_to_use_bundler_and_rubygems_on_wasm.md](https://gist.github.com/kateinoigakukun/5caf3b83b2732b1653e91b0e75ce3390)
- [TODO: Shrinking .wasm Size](https://rustwasm.github.io/docs/book/reference/code-size.html)
- see contributing.md in ruby.wasm repo

## GPT to convert JavaScript to Ruby code:
Expand Down
3 changes: 1 addition & 2 deletions browser.script.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -2100,8 +2100,7 @@ SOFTWARE.
* an array of strings starting with the Ruby program name.
*/
initialize(args = ["ruby.wasm", "-EUTF-8", "-e_=0"]) {
console.log("tests");
const c_args = args.map((arg) => arg + "\0");
const c_args = args.map((arg) => arg + "\0");
this.guest.rubyInit();
this.guest.rubySysinit(c_args);
this.guest.rubyOptions(c_args);
Expand Down
6 changes: 5 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ cd ruby.wasm
bundle exec rake compile
rake install
cd ..
bundle exec rbwasm --log-level debug build --ruby-version 3.3 --target wasm32-unknown-wasi --build-profile full -o ruby-app.wasm
bundle exec rbwasm --log-level debug build --ruby-version 3.3 --target wasm32-unknown-wasi --build-profile full -o ruby-app.wasm
# Remove the debug info
wasm-opt --strip-debug ruby-app.wasm -o ruby-app.wasm
# Optimize for size without hurting speed as much.
wasm-opt ruby-app.wasm -Os -o ruby-app.wasm
Binary file modified ruby-app.wasm
Binary file not shown.

0 comments on commit b3a17c5

Please sign in to comment.