Skip to content

Commit b3a17c5

Browse files
committed
build a smaller wasm file
1 parent f19ddfb commit b3a17c5

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ruby -run -e httpd . -p 8080
3333

3434
## Todo
3535
- [x] explain how to add code outside gems to the image
36-
- [ ] show how to shrink/compress the ruby.wasm file (currently 51MB with debug info, but can be about 10mb or less.)
36+
- [X] ~~show how to shrink/compress the ruby.wasm file (currently 51MB with debug info, but can be about 10mb or less.)~~
3737
- [ ] license + explanation
3838
- [ ] ask upstream if they can make a javascript file that doesnt have the .wasm file path hardcoded.
3939
- [ ] docker file
@@ -54,6 +54,7 @@ ruby -run -e httpd . -p 8080
5454
- [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)
5555
- [RubyでWebAssemblyを試してみよう #ruby #WebAssembly #WASM #WASI - クリエーションライン株式会社](https://www.creationline.com/tech-blog/60328)
5656
- [how_to_use_bundler_and_rubygems_on_wasm.md](https://gist.github.com/kateinoigakukun/5caf3b83b2732b1653e91b0e75ce3390)
57+
- [TODO: Shrinking .wasm Size](https://rustwasm.github.io/docs/book/reference/code-size.html)
5758
- see contributing.md in ruby.wasm repo
5859

5960
## GPT to convert JavaScript to Ruby code:

browser.script.iife.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2100,8 +2100,7 @@ SOFTWARE.
21002100
* an array of strings starting with the Ruby program name.
21012101
*/
21022102
initialize(args = ["ruby.wasm", "-EUTF-8", "-e_=0"]) {
2103-
console.log("tests");
2104-
const c_args = args.map((arg) => arg + "\0");
2103+
const c_args = args.map((arg) => arg + "\0");
21052104
this.guest.rubyInit();
21062105
this.guest.rubySysinit(c_args);
21072106
this.guest.rubyOptions(c_args);

build.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ cd ruby.wasm
44
bundle exec rake compile
55
rake install
66
cd ..
7-
bundle exec rbwasm --log-level debug build --ruby-version 3.3 --target wasm32-unknown-wasi --build-profile full -o ruby-app.wasm
7+
bundle exec rbwasm --log-level debug build --ruby-version 3.3 --target wasm32-unknown-wasi --build-profile full -o ruby-app.wasm
8+
# Remove the debug info
9+
wasm-opt --strip-debug ruby-app.wasm -o ruby-app.wasm
10+
# Optimize for size without hurting speed as much.
11+
wasm-opt ruby-app.wasm -Os -o ruby-app.wasm

ruby-app.wasm

-18.1 MB
Binary file not shown.

0 commit comments

Comments
 (0)