Skip to content

Commit

Permalink
* upgrade wasmify-rails + readme
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Oct 17, 2024
1 parent 2123973 commit 66809df
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 26 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
PATH
remote: ../../anycable/anycable-rails
specs:
anycable-rails (1.5.3)
anycable-rails (1.5.4)
anycable (~> 1.5.0)
anycable-rails-core (= 1.5.3)
anycable-rails-core (1.5.3)
anycable-rails-core (= 1.5.4)
anycable-rails-core (1.5.4)
actioncable (>= 7.0, < 9.0)
anycable-core (~> 1.5.0)
globalid

PATH
remote: ../../writebook/gems/wasmify-rails
specs:
wasmify-rails (0.1.4)
wasmify-rails (0.1.5)
js (>= 2.6, < 3.0)
railties (>= 7.0, < 9.0)
ruby_wasm (>= 2.6, < 3.0)
Expand Down
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
# README
# Rails on Wasm playground application

This README would normally document whatever steps are necessary to get the
application up and running.
This is a sample application to showcase different Rails on Wasm techniques.

Things you may want to cover:
## Install & Run

* Ruby version
You need to make a few steps to run this application in your browser:

* System dependencies
1. Install Ruby deps:

* Configuration
```bash
bundle install
```

* Database creation
1+. Feel free to run the app locally (as a regular Rails app):

* Database initialization
```bash
bin/dev
```

* How to run the test suite
2. Compile the app into a Wasm module:

* Services (job queues, cache servers, search engines, etc.)
```bash
bin/rails wasmify:pack
```

* Deployment instructions
3. Install PWA app dependencies:

* ...
```bash
cd pwa/ && yarn install
```

4. Run the PWA app to see the Rails app running in your browser:

```bash
cd pwa/ && yarn dev
```

Go to [http://localhost:5173/boot.html](http://localhost:5173/boot.html).
4 changes: 4 additions & 0 deletions app/controllers/todos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class TodosController < ApplicationController
# GET /todos or /todos.json
def index
@todos = Todo.all
respond_to do |format|
format.html
format.json { render json: @todos }
end
end

# GET /todos/1 or /todos/1.json
Expand Down
2 changes: 1 addition & 1 deletion pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"vite-plugin-pwa": "^0.20.5"
},
"dependencies": {
"wasmify-rails": "^0.1.4",
"wasmify-rails": "^0.1.5",
"@sqlite.org/sqlite-wasm": "3.46.1-build3"
}
}
7 changes: 6 additions & 1 deletion pwa/rails.sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ const initVM = async (progress, opts = {}) => {

let redirectConsole = true;

const env = [];

// env.push(`RUBY_FIBER_MACHINE_STACK_SIZE=${String(1024 * 1024 * 20)}`)

vm = await initRailsVM("/app.wasm", {
database: { adapter: "sqlite3_wasm" },
env,
progressCallback: (step) => {
progress?.updateStep(step);
},
Expand Down Expand Up @@ -87,7 +92,7 @@ self.addEventListener("install", (event) => {
event.waitUntil(installApp().then(() => self.skipWaiting()));
});

const rackHandler = new RackHandler(initVM, { assumeSSL: true });
const rackHandler = new RackHandler(initVM, { assumeSSL: true, async: false });

self.addEventListener("fetch", (event) => {
const bootResources = ["/boot", "/boot.js", "/boot.html", "/rails.sw.js"];
Expand Down
14 changes: 7 additions & 7 deletions pwa/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2489,9 +2489,9 @@ tr46@^1.0.1:
punycode "^2.1.0"

tslib@^2.6.3:
version "2.7.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.7.0.tgz#d9b40c5c40ab59e8738f297df3087bf1a2690c01"
integrity sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==
version "2.8.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.0.tgz#d124c86c3c05a40a91e6fdea4021bd31d377971b"
integrity sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==

type-fest@^0.16.0:
version "0.16.0"
Expand Down Expand Up @@ -2622,10 +2622,10 @@ vite@^4.4.5:
optionalDependencies:
fsevents "~2.3.2"

wasmify-rails@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/wasmify-rails/-/wasmify-rails-0.1.4.tgz#e80f3b3c8f1275f7ea33f1e86b85c6d24c76a992"
integrity sha512-YO9W5qJrfPWR1mUXQvFb+ceLVHymrlkLJQioSGCCeUY++JtxE4XLiNvyCyZswH8RfdDOoYhvGZ4XacxRZeI7pg==
wasmify-rails@^0.1.5:
version "0.1.5"
resolved "https://registry.yarnpkg.com/wasmify-rails/-/wasmify-rails-0.1.5.tgz#867909ec6d20df372784e2e06ada59ff172c8851"
integrity sha512-CgbdcUvYV56w1851HlkL0hrnxkWHhXp7/jjQ2Jr9Q4OOZRz76LtbPj11TN58xLGMHISnvSnUfQWoIRLBcVm33A==
dependencies:
"@bjorn3/browser_wasi_shim" "^0.3.0"
"@ruby/wasm-wasi" "^2.6.2"
Expand Down

0 comments on commit 66809df

Please sign in to comment.