Skip to content

Commit 7d12a3e

Browse files
Update README.md
1 parent 515de7b commit 7d12a3e

File tree

1 file changed

+65
-18
lines changed

1 file changed

+65
-18
lines changed

README.md

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,75 @@ It enables running Ruby application on browsers, WASI compatible WebAssembly run
77

88
## npm packages (for JavaScript host environments)
99

10+
See the `README.md` of each package for more detail and its usage.
11+
1012
| Package | Description | npm |
1113
| ------------------------------------------------------------------------------ | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------- |
1214
| [ruby-head-wasm-wasi](./packages/npm-packages/ruby-head-wasm-wasi) | HEAD CRuby built on WASI with JS interop support | [![npm version](https://badge.fury.io/js/ruby-head-wasm-wasi.svg)](https://badge.fury.io/js/ruby-head-wasm-wasi) |
1315
| [ruby-head-wasm-emscripten](./packages/npm-packages/ruby-head-wasm-emscripten) | HEAD CRuby built on Emscripten (not well tested) | [![npm version](https://badge.fury.io/js/ruby-head-wasm-emscripten.svg)](https://badge.fury.io/js/ruby-head-wasm-emscripten) |
1416

17+
## Quick Example: How to package your Ruby application as a WASI application
18+
19+
Dpendencies: [wasi-vfs](https://github.com/kateinoigakukun/wasi-vfs), [wasmtime](https://github.com/bytecodealliance/wasmtime)
20+
21+
```console
22+
# Download a prebuilt Ruby release
23+
$ curl -LO https://github.com/kateinoigakukun/ruby.wasm/releases/download/2022-03-28-a/ruby-head-wasm32-unknown-wasi-full.tar.gz
24+
$ tar xfz ruby-head-wasm32-unknown-wasi-full.tar.gz
25+
26+
# Extract ruby binary not to pack itself
27+
$ mv head-wasm32-unknown-wasi-full/usr/local/bin/ruby ruby.wasm
28+
29+
# Put your app code
30+
$ mkdir src
31+
$ echo "puts 'Hello'" > src/my_app.rb
32+
33+
# Pack the whole directory under /usr and your app dir
34+
$ wasi-vfs pack ruby.wasm --mapdir /src::./src --mapdir /usr::./head-wasm32-unknown-wasi-full/usr -o my-ruby-app.wasm
35+
36+
# Run the packed scripts
37+
$ wasmtime my-ruby-app.wasm -- /src/my_app.rb
38+
Hello
39+
```
40+
1541
## Prebuilt binaries
1642

17-
[The prebuilt binaries are available at here](https://github.com/ruby/ruby.wasm/releases).
43+
This project distributes [prebuilt Ruby binaries in GitHub Releases](https://github.com/ruby/ruby.wasm/releases).
1844
A _build_ is a combination of ruby version, _profile_, and _target_.
1945

20-
The supported _target triples_ in this repository are:
46+
### Supported Target Triples
2147

22-
- `wasm32-unknown-wasi`
23-
- `wasm32-unknown-emscripten`
48+
| Triple | Description |
49+
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
50+
| `wasm32-unknown-wasi` | Targeting WASI-compatible environments (e.g. Node.js, browsers with polyfill, [wasmtime](https://github.com/bytecodealliance/wasmtime), and so on) |
51+
| `wasm32-unknown-emscripten` | Targeting JavaScript environments including Node.js and browsers |
2452

2553
### Profiles
2654

27-
| Profile | Description |
28-
| ---------- | ------------------------------------------------------------------------------------ |
29-
| minimal | No standard extension libraries (like `json`, `yaml`, or `stringio`) |
30-
| full | All standard extension libraries |
31-
| minimal-js | No standard extension libraries, and usable with npm package (only for WASI target) |
32-
| full-js | All standard extension libraries, and usable with npm package (only for WASI target) |
55+
| Profile | Description |
56+
|-----------|-------------------------------------------------------------------------------------------------------------------------------|
57+
| `minimal` | No standard extension libraries (like `json`, `yaml`, or `stringio`) |
58+
| `full` | All standard extension libraries |
59+
| `*-js` | Enabled JS interoperability, only usable with npm package |
60+
| `*-debug` | With DWARF info and [`name` section](https://webassembly.github.io/spec/core/appendix/custom.html#name-section) for debugging |
61+
62+
Note: `*` is a wildcard that represents any other profile name except for itself, applied recursively. For example, `minimal-full-js-debug` is a valid profile.
3363

3464
## Building from source
3565

66+
If you want to build Ruby for WebAssembly from source yourself, follow the below instructions.
67+
68+
(However, in most cases, it's easier to use prebuilt binaries instead of building them yourself)
69+
3670
### Dependencies
3771

38-
- [wit-bindgen](https://github.com/bytecodealliance/wit-bindgen): A language bindings generator for `wit` used in the npm packages.
39-
- [wasi-sdk](https://github.com/WebAssembly/wasi-sdk): For building for WASI target. Set `WASI_SDK_PATH` environment variable to the directory of wasi-sdk.
40-
- [wasi-vfs](https://github.com/kateinoigakukun/wasi-vfs): A virtual filesystem layer for WASI.
41-
- [wasi-preset-args](https://github.com/kateinoigakukun/wasi-preset-args): A tool to preset command-line arguments to a WASI module.
42-
- [Emscripten](https://emscripten.org): For building for Emscripten target
72+
- [wit-bindgen](https://github.com/bytecodealliance/wit-bindgen): A language bindings generator for `wit` used in the npm packages. Install in `PATH`.
73+
- [wasi-sdk](https://github.com/WebAssembly/wasi-sdk): Only for building for WASI target. Set `WASI_SDK_PATH` environment variable to the directory of wasi-sdk.
74+
- [wasi-vfs](https://github.com/kateinoigakukun/wasi-vfs): A virtual filesystem layer for WASI. Install CLI tool in `PATH`. Set `LIB_WASI_VFS_A` environment variable to the path to `libwasi_vfs.a`.
75+
- [wasi-preset-args](https://github.com/kateinoigakukun/wasi-preset-args): A tool to preset command-line arguments to a WASI module. Install in `PATH`.
76+
- [Emscripten](https://emscripten.org): Only for building for Emscripten target. Follow the official instructions to install.
4377

44-
It's recommended to build on a Docker container, which installs all dependencies and provides environment variables:
78+
Note: It's recommended building on a builder Docker container, which installs all dependencies and provides environment variables:
4579

4680
```console
4781
# For building ruby for WASI target
@@ -56,8 +90,21 @@ Then, you can build by `rake` command. See `rake -T` for more information.
5690
# Build only a specific combination of ruby version, profile, and target
5791
# Output is in the `rubies` directory
5892
$ rake build:head-wasm32-unknown-wasi-full-js
59-
# Build npm packages and required ruby
60-
$ rake npm:all
93+
$ tree -L 3 rubies/head-wasm32-unknown-wasi-full-js
94+
rubies/head-wasm32-unknown-wasi-full-js/
95+
├── usr
96+
│   └── local
97+
│   ├── bin
98+
│   ├── include
99+
│   ├── lib
100+
│   └── share
101+
└── var
102+
└── lib
103+
└── gems
104+
105+
# Or build npm package. Output is a tarball of npm package
106+
$ rake npm:ruby-head-wasm-wasi
107+
$ ls packages/npm-packages/ruby-head-wasm-wasi/ruby-head-wasm-wasi-*.tgz
61108
```
62109

63110
## Notable Limitations

0 commit comments

Comments
 (0)