wasmify-rails 0.2.3 → 0.3.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +15 -0
- data/lib/generators/wasmify/install/install_generator.rb +1 -1
- data/lib/generators/wasmify/install/templates/config/wasmify.yml +6 -0
- data/lib/wasmify/rails/builder.rb +27 -3
- data/lib/wasmify/rails/configuration.rb +20 -12
- data/lib/wasmify/rails/packer.rb +24 -5
- data/lib/wasmify/rails/railtie.rb +12 -0
- data/lib/wasmify/rails/shims/rails-html-sanitizer.rb +3 -0
- data/lib/wasmify/rails/version.rb +1 -1
- data/lib/wasmify-rails.rb +1 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ba6a11376e388d3ded351a2c72bfed1bab2063c2b4eb98d8c63f1a5d50214e4
|
4
|
+
data.tar.gz: 8444b60b24fbfac498cf489c09ad0d4787552cee1e921cb3c9f5dece19643666
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 653e2e65cbeb368db2da8b6c357e25d6b017750d906b08a2e60bd71e24c9b5f6410970223a5c13cb806a99b495eb3256b3e1c5964181f0ad0e51a0d85e2190d3
|
7
|
+
data.tar.gz: 105c28242943f9055901e116fb4bac929028b225751d49f5745a3304683a8fb8cb7f8a917119aa63fa0bab1d127b7d96bd1ac2ff12dff3b31e053507549f7d28
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.3.1
|
6
|
+
|
7
|
+
- Use latest patch versions for Ruby 3.3 and 3.4.
|
8
|
+
|
9
|
+
## 0.3.0
|
10
|
+
|
11
|
+
- Add `ignore_gem_extensions` configuration option.
|
12
|
+
|
13
|
+
- Make it possible to use builder and packer without Rails.
|
14
|
+
|
5
15
|
## 0.2.3
|
6
16
|
|
7
17
|
- Add `skipInitialize` option to `initVM`.
|
data/README.md
CHANGED
@@ -188,6 +188,21 @@ This gem provides a variety of _adapters_ and plugins to make your Rails applica
|
|
188
188
|
|
189
189
|
- `Rack::DataUriUploads` middleware to transparently transform Data URI uploads into files.
|
190
190
|
|
191
|
+
## Known Issues
|
192
|
+
|
193
|
+
### `can't load bigdecimal.so`
|
194
|
+
|
195
|
+
Compiling `bigdecimal` as a gem (not a part of the Ruby distribution, i.e., when using recent Ruby versions) doesn't work; at the same time, modern Rails versions have `require 'bigdecimal` call on boot. Currently, we propose the following workaround:
|
196
|
+
|
197
|
+
- Add `bigdecimal` to the `ignore_gem_extensions` list in the `wasmify.yml` file.
|
198
|
+
- Add the following line to your `config/application.rb` file (before loading Wasm shims):
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
$LOADED_FEATURES << $LOAD_PATH.resolve_feature_path("bigdecimal")[1]
|
202
|
+
```
|
203
|
+
|
204
|
+
We do not include this patch by default hoping that we can have a proper fix in the future.
|
205
|
+
|
191
206
|
## Roadmap
|
192
207
|
|
193
208
|
- PGLite support (see [this example](https://github.com/kateinoigakukun/mastodon/blob/fff2e4a626a20a616c546ddf4f91766abaf1133a/pwa/dist/pglite.rb#L1))
|
@@ -133,7 +133,7 @@ class Wasmify::InstallGenerator < Rails::Generators::Base
|
|
133
133
|
def finish
|
134
134
|
run "bundle install"
|
135
135
|
|
136
|
-
say_status :info, "✅ The application is prepared for Wasm-
|
136
|
+
say_status :info, "✅ The application is prepared for Wasm-ification!\n\n" \
|
137
137
|
"Next steps are:\n" \
|
138
138
|
" - Check your Gemfile: add `group: [:default, :wasm]` to the dependencies required in Wasm runtime" \
|
139
139
|
" - Run `bin/rails wasmify:build:core:verify` to see if the bundle compiles"
|
@@ -5,10 +5,22 @@ require "wasmify-rails"
|
|
5
5
|
require "ruby_wasm"
|
6
6
|
require "ruby_wasm/cli"
|
7
7
|
|
8
|
+
# Patch ruby.wasm CLI to use the latest patch versions of Ruby
|
9
|
+
RubyWasm::CLI.singleton_class.prepend(Module.new do
|
10
|
+
def build_source_aliases(root)
|
11
|
+
super.tap do |sources|
|
12
|
+
sources["3.3"][:url] = "https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.8.tar.gz"
|
13
|
+
sources["3.4"][:url] = "https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.3.tar.gz"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end)
|
17
|
+
|
8
18
|
module Wasmify
|
9
19
|
module Rails
|
10
20
|
# A wrapper for rbwasm build command
|
11
21
|
class Builder
|
22
|
+
ORIGINAL_EXCLUDED_GEMS = RubyWasm::Packager::EXCLUDED_GEMS.dup.freeze
|
23
|
+
|
12
24
|
attr_reader :output_dir, :target
|
13
25
|
|
14
26
|
def initialize(output_dir: Wasmify::Rails.config.tmp_dir, target: Wasmify::Rails.config.wasm_target)
|
@@ -16,16 +28,28 @@ module Wasmify
|
|
16
28
|
@target = target
|
17
29
|
end
|
18
30
|
|
19
|
-
def run(name:, exclude_gems: [], opts: "")
|
31
|
+
def run(name:, exclude_gems: [], ignore_extensions: [], opts: "")
|
32
|
+
# Reset excluded gems
|
33
|
+
RubyWasm::Packager::EXCLUDED_GEMS.replace(ORIGINAL_EXCLUDED_GEMS)
|
34
|
+
$exclude_gems = []
|
20
35
|
$exclude_exts = []
|
21
36
|
|
22
37
|
# Add configured excluded gems
|
23
38
|
Wasmify::Rails.config.exclude_gems.each do |gem_name|
|
24
|
-
|
39
|
+
RubyWasm::Packager::EXCLUDED_GEMS << gem_name
|
40
|
+
end
|
41
|
+
|
42
|
+
# Add configured excluded extensions
|
43
|
+
Wasmify::Rails.config.ignore_gem_extensions.each do |ext_name|
|
44
|
+
$exclude_exts << ext_name
|
25
45
|
end
|
26
46
|
|
27
47
|
# Add additional excluded gems
|
28
48
|
exclude_gems.each do |gem_name|
|
49
|
+
RubyWasm::Packager::EXCLUDED_GEMS << gem_name
|
50
|
+
end
|
51
|
+
|
52
|
+
ignore_extensions.each do |gem_name|
|
29
53
|
$exclude_exts << gem_name
|
30
54
|
end
|
31
55
|
|
@@ -46,7 +70,7 @@ module Wasmify
|
|
46
70
|
-o #{File.join(output_dir, name)}
|
47
71
|
) + opts
|
48
72
|
|
49
|
-
patches_dir = ::Rails.
|
73
|
+
patches_dir = Wasmify::Rails.config.root_dir.join("ruby_wasm_patches").to_s
|
50
74
|
|
51
75
|
if File.directory?(patches_dir)
|
52
76
|
Dir.children(patches_dir).each do |patch|
|
@@ -1,28 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "yaml"
|
4
|
+
|
3
5
|
module Wasmify
|
4
6
|
module Rails
|
5
|
-
RUBY_VERSION_TO_WASM_RUBY_VERSION = {
|
6
|
-
"3.3" => "3.3.3",
|
7
|
-
"3.2" => "3.2.4"
|
8
|
-
}
|
9
|
-
|
10
7
|
class Configuration
|
11
|
-
attr_reader :pack_directories, :
|
8
|
+
attr_reader :pack_directories, :pack_root, :additional_root_files,
|
9
|
+
:exclude_gems, :ignore_gem_extensions,
|
10
|
+
:ruby_version,
|
12
11
|
:tmp_dir, :output_dir, :wasm_target,
|
13
12
|
:skip_assets_precompile
|
14
13
|
|
15
14
|
def initialize
|
16
|
-
config_path =
|
15
|
+
config_path = ENV.fetch("WASMIFY_CONFIG_PATH") { root_dir.join("config", "wasmify.yml") }
|
17
16
|
raise "config/wasmify.yml not found" unless File.exist?(config_path)
|
18
17
|
|
19
18
|
config = YAML.load_file(config_path)
|
20
19
|
|
21
20
|
@pack_directories = config["pack_directories"]
|
22
|
-
@
|
21
|
+
@additional_root_files = config["additional_root_files"]
|
22
|
+
@exclude_gems = config["exclude_gems"] || []
|
23
|
+
@ignore_gem_extensions = config["ignore_gem_extensions"] || []
|
24
|
+
@pack_root = config["pack_root"] || "/rails"
|
23
25
|
@ruby_version = config["ruby_version"] || ruby_version_from_file || "3.3"
|
24
|
-
@tmp_dir = config["tmp_dir"] ||
|
25
|
-
@output_dir = config["output_dir"] ||
|
26
|
+
@tmp_dir = config["tmp_dir"] || root_dir.join("tmp", "wasmify")
|
27
|
+
@output_dir = config["output_dir"] || root_dir.join("dist")
|
26
28
|
@skip_assets_precompile = config["skip_assets_precompile"] || false
|
27
29
|
@wasm_target = config["wasm_target"] || "wasm32-unknown-wasip1"
|
28
30
|
end
|
@@ -37,12 +39,18 @@ module Wasmify
|
|
37
39
|
|
38
40
|
def ruby_version = @ruby_version ||= ruby_version_from_file || "3.3"
|
39
41
|
|
42
|
+
def root_dir
|
43
|
+
return ::Rails.root if defined?(::Rails) && ::Rails.respond_to?(:root)
|
44
|
+
|
45
|
+
Pathname.new(Dir.pwd)
|
46
|
+
end
|
47
|
+
|
40
48
|
private
|
41
49
|
|
42
50
|
def ruby_version_from_file
|
43
|
-
return unless File.file?(
|
51
|
+
return unless File.file?(root_dir.join(".ruby-version"))
|
44
52
|
|
45
|
-
File.read(
|
53
|
+
File.read(root_dir.join(".ruby-version")).strip.match(/(\d+\.\d+(?:\.d+)?)/).then do |matches|
|
46
54
|
matches[1] if matches
|
47
55
|
end
|
48
56
|
end
|
data/lib/wasmify/rails/packer.rb
CHANGED
@@ -12,7 +12,24 @@ module Wasmify
|
|
12
12
|
|
13
13
|
attr_reader :output_dir
|
14
14
|
|
15
|
-
|
15
|
+
if defined?(ActionView::Helpers::NumberHelper)
|
16
|
+
include ActionView::Helpers::NumberHelper
|
17
|
+
else
|
18
|
+
include(Module.new do
|
19
|
+
def number_to_human_size(num)
|
20
|
+
num = num.to_i
|
21
|
+
human_size = case
|
22
|
+
when num < 1024
|
23
|
+
"#{num} bytes"
|
24
|
+
when num < 1024*1024
|
25
|
+
"#{(num.to_f/1024).round(1)} KB"
|
26
|
+
else
|
27
|
+
"#{(num.to_f/1024/1024).round(1)} MB"
|
28
|
+
end
|
29
|
+
human_size
|
30
|
+
end
|
31
|
+
end)
|
32
|
+
end
|
16
33
|
|
17
34
|
def initialize(output_dir: Wasmify::Rails.config.output_dir)
|
18
35
|
@output_dir = output_dir
|
@@ -24,12 +41,14 @@ module Wasmify
|
|
24
41
|
"Please see installations instructions at: https://github.com/kateinoigakukun/wasi-vfs"
|
25
42
|
end
|
26
43
|
|
44
|
+
pack_root = Wasmify::Rails.config.pack_root
|
45
|
+
|
27
46
|
args = %W[
|
28
47
|
pack #{ruby_wasm_path}
|
29
48
|
]
|
30
49
|
|
31
50
|
directories.each do |dir|
|
32
|
-
args << "--dir #{::Rails.
|
51
|
+
args << "--dir #{Wasmify::Rails.config.root_dir.join(dir)}::#{pack_root}/#{dir}"
|
33
52
|
end
|
34
53
|
|
35
54
|
output_path = File.join(output_dir, name)
|
@@ -38,14 +57,14 @@ module Wasmify
|
|
38
57
|
|
39
58
|
# Generate a temporary directory with the require root files
|
40
59
|
Dir.mktmpdir do |tdir|
|
41
|
-
ROOT_FILES.each do |file|
|
42
|
-
FileUtils.cp(::Rails.
|
60
|
+
(ROOT_FILES + (Wasmify::Rails.config.additional_root_files || [])).each do |file|
|
61
|
+
FileUtils.cp(Wasmify::Rails.config.root_dir.join(file), tdir) if File.exist?(Wasmify::Rails.config.root_dir.join(file))
|
43
62
|
end
|
44
63
|
|
45
64
|
# Create a storage/ directory for Active Storage attachments
|
46
65
|
FileUtils.mkdir_p(File.join(tdir, storage_dir)) if storage_dir
|
47
66
|
|
48
|
-
args << "--dir #{tdir}
|
67
|
+
args << "--dir #{tdir}::#{pack_root}"
|
49
68
|
|
50
69
|
args << "-o #{output_path}"
|
51
70
|
|
@@ -15,3 +15,15 @@ module Wasmify
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
|
20
|
+
require "action_mailer/null_delivery"
|
21
|
+
|
22
|
+
# NullDB for Active Record
|
23
|
+
ActiveRecord::ConnectionAdapters.register("nulldb", "ActiveRecord::ConnectionAdapters::NullDBAdapter", "active_record/connection_adapters/nulldb_adapter")
|
24
|
+
|
25
|
+
# SQLite3 Wasm adapter
|
26
|
+
ActiveRecord::ConnectionAdapters.register("sqlite3_wasm", "ActiveRecord::ConnectionAdapters::SQLite3WasmAdapter", "active_record/connection_adapters/sqlite3_wasm_adapter")
|
27
|
+
|
28
|
+
# PGlite adapter
|
29
|
+
ActiveRecord::ConnectionAdapters.register("pglite", "ActiveRecord::ConnectionAdapters::PGliteAdapter", "active_record/connection_adapters/pglite_adapter")
|
data/lib/wasmify-rails.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require "wasmify/rails/version"
|
4
4
|
require "wasmify/rails/configuration"
|
5
5
|
require "wasmify/rails/shim"
|
6
|
-
require "wasmify/rails/railtie"
|
6
|
+
require "wasmify/rails/railtie" if defined?(::Rails::Railtie)
|
7
7
|
|
8
8
|
module Wasmify
|
9
9
|
module Rails
|
@@ -17,14 +17,3 @@ end
|
|
17
17
|
module ImageProcessing
|
18
18
|
autoload :Null, "image_processing/null"
|
19
19
|
end
|
20
|
-
|
21
|
-
require "action_mailer/null_delivery"
|
22
|
-
|
23
|
-
# NullDB for Active Record
|
24
|
-
ActiveRecord::ConnectionAdapters.register("nulldb", "ActiveRecord::ConnectionAdapters::NullDBAdapter", "active_record/connection_adapters/nulldb_adapter")
|
25
|
-
|
26
|
-
# SQLite3 Wasm adapter
|
27
|
-
ActiveRecord::ConnectionAdapters.register("sqlite3_wasm", "ActiveRecord::ConnectionAdapters::SQLite3WasmAdapter", "active_record/connection_adapters/sqlite3_wasm_adapter")
|
28
|
-
|
29
|
-
# PGlite adapter
|
30
|
-
ActiveRecord::ConnectionAdapters.register("pglite", "ActiveRecord::ConnectionAdapters::PGliteAdapter", "active_record/connection_adapters/pglite_adapter")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wasmify-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|