@ruby/head-wasm-emscripten 2.3.0-2023-11-29-b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # @ruby/head-wasm-emscripten
2
+
3
+ WebAssembly port of CRuby by Emscripten with a thin JavaScript wrapper.
4
+
5
+ This package distributes the latest `master` branch of CRuby.
6
+
7
+ ## Installation
8
+
9
+ For installing `@ruby/head-wasm-emscripten`, just run this command in your shell:
10
+
11
+ ```console
12
+ $ npm install --save @ruby/head-wasm-emscripten@latest
13
+ # or if you want the nightly snapshot
14
+ $ npm install --save @ruby/head-wasm-emscripten@next
15
+ # or you can specify the exact snapshot version
16
+ $ npm install --save @ruby/head-wasm-emscripten@2.3.0-2023-11-26-a
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ This quick start is for browsers and Node.js environments. See [the example project](https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-wasm-emscripten/example) for more details.
22
+
23
+ ```javascript
24
+ import { loadRuby } from "@ruby/head-wasm-emscripten";
25
+
26
+ const main = async () => {
27
+ const args = ["--disable-gems", "-e", "puts 'Hello :)'"];
28
+ console.log(`$ ruby.wasm ${args.join(" ")}`);
29
+
30
+ const defaultModule = {
31
+ locateFile: (path) => "./node_modules/@ruby/head-wasm-emscripten/dist/" + path,
32
+ setStatus: (msg) => console.log(msg),
33
+ print: (line) => console.log(line),
34
+ arguments: args,
35
+ };
36
+
37
+ await loadRuby(defaultModule);
38
+ };
39
+
40
+ main();
41
+
42
+ ```
43
+
44
+ ## APIs
45
+
46
+ `loadRuby(defaultModule): Promise<Module>`
47
+
48
+ This package provides only `loadRuby` function, which loads the Ruby interpreter and stdlib asynchronously.
49
+
50
+ This takes a `defaultModule` object as an argument, which is used as a base for the Emscripten's Module object.
51
+
52
+ ### Module object
53
+
54
+ > Module is a global JavaScript object with attributes that Emscripten-generated code calls at various points in its execution.
55
+
56
+ https://emscripten.org/docs/api_reference/module.html
57
+
58
+ This package is a thin wrapper of Emscripten module, so you can control the behavior of the interpreter by modifying the Emscripten's Module object.
59
+
60
+
61
+ ## Building the package from source
62
+
63
+ For building the package from source, you need to prepare a Ruby build produced by Emscripten, and you need Emscripten SDK in your PATH.
64
+
65
+ The instructions for building a Ruby targeting WebAssembly are available [here](https://github.com/ruby/ruby.wasm#building-from-source).
66
+
67
+ Then, you can run the following command in your shell:
68
+
69
+ ```console
70
+ # Check the directory structure of your Ruby build
71
+ $ tree -L 3 path/to/wasm32-unknown-emscripten-full/
72
+ path/to/wasm32-unknown-emscripten-full/
73
+ ├── usr
74
+ │ └── local
75
+ │ ├── bin
76
+ │ ├── include
77
+ │ ├── lib
78
+ │ └── share
79
+ └── var
80
+ └── lib
81
+ └── gems
82
+ $ ./build-package.sh path/to/wasm32-unknown-emscripten-full/
83
+ Remember to build the main file with -s FORCE_FILESYSTEM=1 so that it includes support for loading this file package
84
+
85
+ index.js → dist...
86
+ created dist in 3.5s
87
+ ```
88
+
89
+ It's recommended to build on a Docker container with the following command:
90
+
91
+ ```console
92
+ $ docker run -it --rm \
93
+ -v $(pwd):/src \
94
+ -v path/to/wasm32-unknown-emscripten-full:/install \
95
+ emscripten/emsdk /bin/bash
96
+ ```