ruby_wasm 2.5.0-arm64-darwin → 2.5.1-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +9 -7
  3. data/Gemfile +1 -1
  4. data/README.md +10 -9
  5. data/Rakefile +8 -7
  6. data/docs/cheat_sheet.md +8 -8
  7. data/lib/ruby_wasm/3.1/ruby_wasm.bundle +0 -0
  8. data/lib/ruby_wasm/3.2/ruby_wasm.bundle +0 -0
  9. data/lib/ruby_wasm/{3.0 → 3.3}/ruby_wasm.bundle +0 -0
  10. data/lib/ruby_wasm/build/executor.rb +4 -0
  11. data/lib/ruby_wasm/build/product/crossruby.rb +53 -23
  12. data/lib/ruby_wasm/build/product/libyaml.rb +5 -3
  13. data/lib/ruby_wasm/build/product/openssl.rb +7 -2
  14. data/lib/ruby_wasm/build/product/product.rb +3 -3
  15. data/lib/ruby_wasm/build/product/ruby_source.rb +3 -3
  16. data/lib/ruby_wasm/build/product/wasi_vfs.rb +1 -1
  17. data/lib/ruby_wasm/build/product/zlib.rb +3 -1
  18. data/lib/ruby_wasm/build/target.rb +24 -0
  19. data/lib/ruby_wasm/build/toolchain.rb +1 -1
  20. data/lib/ruby_wasm/build.rb +7 -3
  21. data/lib/ruby_wasm/cli.rb +141 -11
  22. data/lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.command.wasm +0 -0
  23. data/lib/ruby_wasm/packager/component_adapter/wasi_snapshot_preview1.reactor.wasm +0 -0
  24. data/lib/ruby_wasm/packager/component_adapter.rb +14 -0
  25. data/lib/ruby_wasm/packager/core.rb +180 -3
  26. data/lib/ruby_wasm/packager/file_system.rb +5 -3
  27. data/lib/ruby_wasm/packager.rb +18 -81
  28. data/lib/ruby_wasm/rake_task.rb +1 -0
  29. data/lib/ruby_wasm/version.rb +1 -1
  30. data/lib/ruby_wasm.rb +1 -0
  31. data/package-lock.json +410 -133
  32. data/package.json +3 -3
  33. data/rakelib/ci.rake +3 -3
  34. data/rakelib/packaging.rake +26 -12
  35. data/sig/ruby_wasm/build.rbs +36 -27
  36. data/sig/ruby_wasm/cli.rbs +27 -3
  37. data/sig/ruby_wasm/ext.rbs +15 -2
  38. data/sig/ruby_wasm/packager.rbs +37 -6
  39. metadata +9 -9
  40. data/builders/wasm32-unknown-emscripten/Dockerfile +0 -43
  41. data/builders/wasm32-unknown-emscripten/entrypoint.sh +0 -7
  42. data/builders/wasm32-unknown-wasi/Dockerfile +0 -47
  43. data/builders/wasm32-unknown-wasi/entrypoint.sh +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c6e8c3a7519319f289d45b0275ffa0e97b41c12a89c687f2dd82e3321e82943
4
- data.tar.gz: eb71c64ef94a9fea9a45cbb67d85adfee898476bf43da95011e4cde0677dd9ac
3
+ metadata.gz: abea19f7078ec3b3fe28c43a75b79beddf89b4e201a475afea5b35e37f53a083
4
+ data.tar.gz: 2f50628b80582c5b149742141c93852f7277ddefefaba8ced488f55b2cde8ac9
5
5
  SHA512:
6
- metadata.gz: 8af36b52c8b0a0f61baaf5a4c7c29245ff8d742d79258b12f066376e99af52dd4081e99ba1a7489b51dd42af390a37e843ce6d8e06c073e05a5a4ecbea70fd4f
7
- data.tar.gz: '0905bc881c33c0bbe286b78a375d431ee191a2a0a18fe31bac826d1e2a4ad6fec91f9ac27b5ad30e1a063bb4726a5ee6e0c272d4f4868300fc3cd43dfecdc49b'
6
+ metadata.gz: 48136b66102e5f7da55c8683bfab4f8b5937d48f88217c64c5f7e2ae7637ef1b65c7601cd94028e6d79eda6ad5b8e49fe69d395c3dadb9fca492a66e86c732e5
7
+ data.tar.gz: ee71dd976e19ffa18370aaacc4b47fed6557f3a7a797132c41dcef40c079310afdea3c46babbc857b2667422989270f87e5b1eda66da35bc0f57b28bb9f55411
data/CONTRIBUTING.md CHANGED
@@ -21,7 +21,7 @@ $ rake --tasks
21
21
  $ rake build:download_prebuilt
22
22
 
23
23
  # Build Ruby (if you need to build Ruby by yourself)
24
- $ rake build:head-wasm32-unknown-wasi-full
24
+ $ rake build:head-wasm32-unknown-wasip1-full
25
25
 
26
26
  # Build npm package
27
27
  $ rake npm:ruby-head-wasm-wasi
@@ -48,15 +48,15 @@ To select a build profile, see [profiles section in README](https://github.com/r
48
48
 
49
49
  ```console
50
50
  # Build only a specific combination of ruby version, profile, and target
51
- $ rake build:head-wasm32-unknown-wasi-full
51
+ $ rake build:head-wasm32-unknown-wasip1-full
52
52
  # Clean up the build directory
53
- $ rake build:head-wasm32-unknown-wasi-full:clean
53
+ $ rake build:head-wasm32-unknown-wasip1-full:clean
54
54
  # Force to re-execute "make install"
55
- $ rake build:head-wasm32-unknown-wasi-full:remake
55
+ $ rake build:head-wasm32-unknown-wasip1-full:remake
56
56
 
57
57
  # Output is in the `rubies` directory
58
- $ tree -L 3 rubies/head-wasm32-unknown-wasi-full
59
- rubies/head-wasm32-unknown-wasi-full/
58
+ $ tree -L 3 rubies/head-wasm32-unknown-wasip1-full
59
+ rubies/head-wasm32-unknown-wasip1-full/
60
60
  ├── usr
61
61
  │   └── local
62
62
  │   ├── bin
@@ -109,6 +109,8 @@ $ rake 'bump_version[0.6.0]'
109
109
  $ git commit -m"Bump version to 0.6.0"
110
110
  $ git tag 0.6.0
111
111
  $ git push origin 0.6.0
112
+ $ for pkg in pkg/ruby_wasm-*; do gem push $pkg; done
113
+ $ (cd packages/gems/js/ && gem build && gem push js-*.gem)
112
114
  ```
113
115
 
114
116
  ## Release Channels
@@ -122,5 +124,5 @@ $ npm install --save @ruby/wasm-wasi@latest
122
124
  # or if you want the nightly snapshot
123
125
  $ npm install --save @ruby/wasm-wasi@next
124
126
  # or you can specify the exact snapshot version
125
- $ npm install --save @ruby/wasm-wasi@2.5.0-2024-01-28-a
127
+ $ npm install --save @ruby/wasm-wasi@2.5.1-2024-04-21-a
126
128
  ```
data/Gemfile CHANGED
@@ -7,7 +7,7 @@ gemspec
7
7
  group :development do
8
8
  gem "rake"
9
9
  gem "rake-compiler"
10
- gem "rb_sys", "0.9.85"
10
+ gem "rb_sys", "0.9.97"
11
11
  end
12
12
 
13
13
  group :check do
data/README.md CHANGED
@@ -23,7 +23,7 @@ Create and save `index.html` page with the following contents:
23
23
 
24
24
  ```html
25
25
  <html>
26
- <script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.0/dist/browser.script.iife.js"></script>
26
+ <script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/browser.script.iife.js"></script>
27
27
  <script type="text/ruby">
28
28
  require "js"
29
29
 
@@ -35,25 +35,26 @@ Create and save `index.html` page with the following contents:
35
35
 
36
36
  ## Quick Example: How to package your Ruby application as a WASI application
37
37
 
38
- Dependencies: [wasi-vfs](https://github.com/kateinoigakukun/wasi-vfs), [wasmtime](https://github.com/bytecodealliance/wasmtime)
38
+ Dependencies: [wasmtime](https://github.com/bytecodealliance/wasmtime)
39
39
 
40
40
  ```console
41
+ $ gem install ruby_wasm
41
42
  # Download a prebuilt Ruby release
42
- $ curl -LO https://github.com/ruby/ruby.wasm/releases/latest/download/ruby-3.2-wasm32-unknown-wasi-full.tar.gz
43
- $ tar xfz ruby-3.2-wasm32-unknown-wasi-full.tar.gz
43
+ $ curl -LO https://github.com/ruby/ruby.wasm/releases/latest/download/ruby-3.3-wasm32-unknown-wasip1-full.tar.gz
44
+ $ tar xfz ruby-3.3-wasm32-unknown-wasip1-full.tar.gz
44
45
 
45
46
  # Extract ruby binary not to pack itself
46
- $ mv 3.2-wasm32-unknown-wasi-full/usr/local/bin/ruby ruby.wasm
47
+ $ mv ruby-3.3-wasm32-unknown-wasip1-full/usr/local/bin/ruby ruby.wasm
47
48
 
48
49
  # Put your app code
49
50
  $ mkdir src
50
51
  $ echo "puts 'Hello'" > src/my_app.rb
51
52
 
52
53
  # Pack the whole directory under /usr and your app dir
53
- $ wasi-vfs pack ruby.wasm --mapdir /src::./src --mapdir /usr::./3.2-wasm32-unknown-wasi-full/usr -o my-ruby-app.wasm
54
+ $ rbwasm pack ruby.wasm --dir ./src::/src --dir ./ruby-3.3-wasm32-unknown-wasip1-full/usr::/usr -o my-ruby-app.wasm
54
55
 
55
56
  # Run the packed scripts
56
- $ wasmtime my-ruby-app.wasm -- /src/my_app.rb
57
+ $ wasmtime my-ruby-app.wasm /src/my_app.rb
57
58
  Hello
58
59
  ```
59
60
 
@@ -109,8 +110,8 @@ A _build_ is a combination of ruby version, _profile_, and _target_.
109
110
  </thead>
110
111
  <tbody>
111
112
  <tr>
112
- <td><code>wasm32-unknown-wasi</code></td>
113
- <td>Targeting WASI-compatible environments (e.g. Node.js, browsers with polyfill, <a href="https://github.com/bytecodealliance/wasmtime">wasmtime</a>, and so on)</td>
113
+ <td><code>wasm32-unknown-wasip1</code></td>
114
+ <td>Targeting <a href="https://github.com/WebAssembly/WASI/tree/main/legacy/preview1">WASI Preview1</a> compatible environments <br>(e.g. Node.js, browsers with polyfill, <a href="https://github.com/bytecodealliance/wasmtime">wasmtime</a>, and so on)</td>
114
115
  </tr>
115
116
  <tr>
116
117
  <td><code>wasm32-unknown-emscripten</code></td>
data/Rakefile CHANGED
@@ -7,6 +7,7 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), "lib")
7
7
  require "bundler/gem_tasks"
8
8
  require "ruby_wasm/rake_task"
9
9
  require "ruby_wasm/packager"
10
+ require "ruby_wasm/cli"
10
11
 
11
12
  BUILD_SOURCES = %w[3.3 3.2 head]
12
13
  BUILD_PROFILES = %w[full minimal]
@@ -14,7 +15,7 @@ BUILD_PROFILES = %w[full minimal]
14
15
  BUILDS =
15
16
  BUILD_SOURCES
16
17
  .product(BUILD_PROFILES)
17
- .map { |src, profile| [src, "wasm32-unknown-wasi", profile] } +
18
+ .map { |src, profile| [src, "wasm32-unknown-wasip1", profile] } +
18
19
  BUILD_SOURCES.map { |src| [src, "wasm32-unknown-emscripten", "full"] }
19
20
 
20
21
  NPM_PACKAGES = [
@@ -28,26 +29,26 @@ NPM_PACKAGES = [
28
29
  name: "ruby-head-wasm-wasi",
29
30
  ruby_version: "head",
30
31
  gemfile: "packages/npm-packages/ruby-wasm-wasi/Gemfile",
31
- target: "wasm32-unknown-wasi"
32
+ target: "wasm32-unknown-wasip1"
32
33
  },
33
34
  {
34
35
  name: "ruby-3.3-wasm-wasi",
35
36
  ruby_version: "3.3",
36
37
  gemfile: "packages/npm-packages/ruby-wasm-wasi/Gemfile",
37
- target: "wasm32-unknown-wasi"
38
+ target: "wasm32-unknown-wasip1"
38
39
  },
39
40
  {
40
41
  name: "ruby-3.2-wasm-wasi",
41
42
  ruby_version: "3.2",
42
43
  gemfile: "packages/npm-packages/ruby-wasm-wasi/Gemfile",
43
- target: "wasm32-unknown-wasi"
44
+ target: "wasm32-unknown-wasip1"
44
45
  },
45
- { name: "ruby-wasm-wasi", target: "wasm32-unknown-wasi" }
46
+ { name: "ruby-wasm-wasi", target: "wasm32-unknown-wasip1" }
46
47
  ]
47
48
 
48
49
  STANDALONE_PACKAGES = [
49
- { name: "ruby", build: "head-wasm32-unknown-wasi-full" },
50
- { name: "irb", build: "head-wasm32-unknown-wasi-full" }
50
+ { name: "ruby", build: "head-wasm32-unknown-wasip1-full" },
51
+ { name: "irb", build: "head-wasm32-unknown-wasip1-full" }
51
52
  ]
52
53
 
53
54
  LIB_ROOT = File.dirname(__FILE__)
data/docs/cheat_sheet.md CHANGED
@@ -38,7 +38,7 @@ The easiest way to run Ruby on browser is to use `browser.script.iife.js` script
38
38
 
39
39
  ```html
40
40
  <html>
41
- <script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.0/dist/browser.script.iife.js"></script>
41
+ <script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/browser.script.iife.js"></script>
42
42
  <script type="text/ruby">
43
43
  require "js"
44
44
  JS.global[:document].write "Hello, world!"
@@ -51,8 +51,8 @@ If you want to control Ruby VM from JavaScript, you can use `@ruby/wasm-wasi` pa
51
51
  ```html
52
52
  <html>
53
53
  <script type="module">
54
- import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.5.0/dist/browser/+esm";
55
- const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.0/dist/ruby+stdlib.wasm");
54
+ import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.5.1/dist/browser/+esm";
55
+ const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/ruby+stdlib.wasm");
56
56
  const module = await WebAssembly.compileStreaming(response);
57
57
  const { vm } = await DefaultRubyVM(module);
58
58
 
@@ -69,11 +69,11 @@ If you want to control Ruby VM from JavaScript, you can use `@ruby/wasm-wasi` pa
69
69
 
70
70
  ```html
71
71
  <html>
72
- <script src="https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.5.0/dist/browser.umd.js"></script>
72
+ <script src="https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.5.1/dist/browser.umd.js"></script>
73
73
  <script>
74
74
  const main = async () => {
75
75
  const { DefaultRubyVM } = window["ruby-wasm-wasi"];
76
- const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.0/dist/ruby+stdlib.wasm");
76
+ const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/ruby+stdlib.wasm");
77
77
  const module = await WebAssembly.compileStreaming(response);
78
78
  const { vm } = await DefaultRubyVM(module);
79
79
 
@@ -128,7 +128,7 @@ end
128
128
 
129
129
  ```html
130
130
  <html>
131
- <script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.0/dist/browser.script.iife.js"></script>
131
+ <script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/browser.script.iife.js"></script>
132
132
  <script type="text/ruby" data-eval="async">
133
133
  require "js"
134
134
 
@@ -143,8 +143,8 @@ Or using `@ruby/wasm-wasi` package API `RubyVM#evalAsync`:
143
143
  ```html
144
144
  <html>
145
145
  <script type="module">
146
- import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.5.0/dist/browser/+esm";
147
- const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.0/dist/ruby+stdlib.wasm");
146
+ import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.5.1/dist/browser/+esm";
147
+ const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/ruby+stdlib.wasm");
148
148
  const module = await WebAssembly.compileStreaming(response);
149
149
  const { vm } = await DefaultRubyVM(module);
150
150
 
Binary file
Binary file
@@ -128,6 +128,10 @@ module RubyWasm
128
128
  FileUtils.mkdir_p(list)
129
129
  end
130
130
 
131
+ def ln_s(src, dest)
132
+ FileUtils.ln_s(src, dest)
133
+ end
134
+
131
135
  def write(path, data)
132
136
  File.write(path, data)
133
137
  end
@@ -37,7 +37,6 @@ module RubyWasm
37
37
  make_args << "AR=#{@toolchain.ar}"
38
38
  make_args << "RANLIB=#{@toolchain.ranlib}"
39
39
 
40
- make_args << "DESTDIR=#{crossruby.dest_dir}"
41
40
  make_args
42
41
  end
43
42
 
@@ -45,12 +44,15 @@ module RubyWasm
45
44
  objdir = product_build_dir crossruby
46
45
  executor.mkdir_p objdir
47
46
  do_extconf executor, crossruby
47
+
48
+ executor.system "make", "-C", objdir, *make_args(crossruby), "clean"
49
+ build_target = crossruby.target.pic? ? "install-so" : "static"
48
50
  executor.system "make",
49
51
  "-j#{executor.process_count}",
50
52
  "-C",
51
53
  "#{objdir}",
52
54
  *make_args(crossruby),
53
- "static"
55
+ build_target
54
56
  # A ext can provide link args by link.filelist. It contains only built archive file by default.
55
57
  unless File.exist?(linklist(crossruby))
56
58
  executor.write(
@@ -61,9 +63,27 @@ module RubyWasm
61
63
  end
62
64
 
63
65
  def do_extconf(executor, crossruby)
66
+ unless crossruby.target.pic?
67
+ self.do_legacy_extconf(executor, crossruby)
68
+ return
69
+ end
70
+ objdir = product_build_dir crossruby
71
+ source = crossruby.source
72
+ rbconfig_rb = Dir.glob(File.join(crossruby.dest_dir, "usr/local/lib/ruby/*/wasm32-wasi/rbconfig.rb")).first
73
+ raise "rbconfig.rb not found" unless rbconfig_rb
74
+ extconf_args = [
75
+ "-C", objdir,
76
+ "#{@srcdir}/extconf.rb",
77
+ "--target-rbconfig=#{rbconfig_rb}",
78
+ ]
79
+ executor.system Gem.ruby, *extconf_args
80
+ end
81
+
82
+ def do_legacy_extconf(executor, crossruby)
64
83
  objdir = product_build_dir crossruby
65
84
  source = crossruby.source
66
85
  extconf_args = [
86
+ "-C", objdir,
67
87
  "--disable=gems",
68
88
  # HACK: top_srcdir is required to find ruby headers
69
89
  "-e",
@@ -71,9 +91,6 @@ module RubyWasm
71
91
  # HACK: extout is required to find config.h
72
92
  "-e",
73
93
  %Q($extout="#{crossruby.build_dir}/.ext"),
74
- # HACK: skip have_devel check since ruby is not installed yet
75
- "-e",
76
- "$have_devel = true",
77
94
  # HACK: force static ext build by imitating extmk
78
95
  "-e",
79
96
  "$static = true; trace_var(:$static) {|v| $static = true }",
@@ -93,7 +110,6 @@ module RubyWasm
93
110
  # Clear RUBYOPT to avoid loading unrelated bundle setup
94
111
  executor.system crossruby.baseruby_path,
95
112
  *extconf_args,
96
- chdir: objdir,
97
113
  env: {
98
114
  "RUBYOPT" => ""
99
115
  }
@@ -118,7 +134,7 @@ module RubyWasm
118
134
  end
119
135
 
120
136
  class CrossRubyProduct < AutoconfProduct
121
- attr_reader :source, :toolchain
137
+ attr_reader :target, :source, :toolchain
122
138
  attr_accessor :user_exts,
123
139
  :wasmoptflags,
124
140
  :cppflags,
@@ -155,6 +171,14 @@ module RubyWasm
155
171
  executor.system "make", "rbconfig.rb", chdir: build_dir
156
172
  end
157
173
 
174
+ def need_exts_build?
175
+ @user_exts.any?
176
+ end
177
+
178
+ def need_extinit_obj?
179
+ need_exts_build? && !@target.pic?
180
+ end
181
+
158
182
  def build_exts(executor)
159
183
  @user_exts.each do |prod|
160
184
  executor.begin_section prod.class, prod.name, "Building"
@@ -168,6 +192,7 @@ module RubyWasm
168
192
  executor.mkdir_p build_dir
169
193
  @toolchain.install
170
194
  [@source, @baseruby, @libyaml, @zlib, @openssl, @wasi_vfs].each do |prod|
195
+ next unless prod
171
196
  executor.begin_section prod.class, prod.name, "Building"
172
197
  prod.build(executor)
173
198
  executor.end_section prod.class, prod.name
@@ -176,17 +201,20 @@ module RubyWasm
176
201
  configure(executor, reconfigure: reconfigure)
177
202
  executor.end_section self.class, name
178
203
 
179
- build_exts(executor)
204
+ build_exts(executor) if need_exts_build?
180
205
 
181
206
  executor.begin_section self.class, name, "Building"
182
- executor.mkdir_p File.dirname(extinit_obj)
183
- executor.system "ruby",
184
- extinit_c_erb,
185
- *@user_exts.map { |ext| ext.feature_name(self) },
186
- "--cc",
187
- toolchain.cc,
188
- "--output",
189
- extinit_obj
207
+
208
+ if need_extinit_obj?
209
+ executor.mkdir_p File.dirname(extinit_obj)
210
+ executor.system "ruby",
211
+ extinit_c_erb,
212
+ *@user_exts.map { |ext| ext.feature_name(self) },
213
+ "--cc",
214
+ toolchain.cc,
215
+ "--output",
216
+ extinit_obj
217
+ end
190
218
  install_dir = File.join(build_dir, "install")
191
219
  if !File.exist?(install_dir) || remake || reconfigure
192
220
  executor.system "make",
@@ -216,7 +244,7 @@ module RubyWasm
216
244
  end
217
245
 
218
246
  def cache_key(digest)
219
- digest << @params.target
247
+ @params.target.cache_key(digest)
220
248
  digest << @params.default_exts
221
249
  @wasmoptflags.each { |f| digest << f }
222
250
  @cppflags.each { |f| digest << f }
@@ -229,11 +257,11 @@ module RubyWasm
229
257
  end
230
258
 
231
259
  def build_dir
232
- File.join(@build_dir, @params.target, name)
260
+ File.join(@build_dir, @params.target.to_s, name)
233
261
  end
234
262
 
235
263
  def ext_build_dir
236
- File.join(@build_dir, @params.target, name + "-ext")
264
+ File.join(@build_dir, @params.target.to_s, name + "-ext")
237
265
  end
238
266
 
239
267
  def with_libyaml(libyaml)
@@ -274,14 +302,14 @@ module RubyWasm
274
302
  end
275
303
 
276
304
  def configure_args(build_triple, toolchain)
277
- target = @params.target
305
+ target = @params.target.triple
278
306
  default_exts = @params.default_exts
279
307
 
280
308
  ldflags = @ldflags.dup
281
309
  xldflags = @xldflags.dup
282
310
 
283
311
  args = self.system_triplet_args + ["--build", build_triple]
284
- args << "--with-static-linked-ext"
312
+ args << "--with-static-linked-ext" unless @params.target.pic?
285
313
  args << %Q(--with-ext=#{default_exts})
286
314
  args << %Q(--with-libyaml-dir=#{@libyaml.install_root})
287
315
  args << %Q(--with-zlib-dir=#{@zlib.install_root})
@@ -289,7 +317,7 @@ module RubyWasm
289
317
  args << %Q(--with-baseruby=#{baseruby_path})
290
318
 
291
319
  case target
292
- when "wasm32-unknown-wasi"
320
+ when /^wasm32-unknown-wasi/
293
321
  xldflags << @wasi_vfs.lib_wasi_vfs_a if @wasi_vfs
294
322
  # TODO: Find a way to force cast or update API
295
323
  # @type var wasi_sdk_path: untyped
@@ -308,8 +336,9 @@ module RubyWasm
308
336
 
309
337
  args.concat(self.tools_args)
310
338
  (@user_exts || []).each { |lib| xldflags << "@#{lib.linklist(self)}" }
311
- xldflags << extinit_obj
339
+ xldflags << extinit_obj if need_extinit_obj?
312
340
 
341
+ cflags = @cflags.dup
313
342
  xcflags = @xcflags.dup
314
343
  xcflags << "-DWASM_SETJMP_STACK_BUFFER_SIZE=24576"
315
344
  xcflags << "-DWASM_FIBER_STACK_BUFFER_SIZE=24576"
@@ -317,6 +346,7 @@ module RubyWasm
317
346
 
318
347
  args << %Q(LDFLAGS=#{ldflags.join(" ")})
319
348
  args << %Q(XLDFLAGS=#{xldflags.join(" ")})
349
+ args << %Q(CFLAGS=#{cflags.join(" ")})
320
350
  args << %Q(XCFLAGS=#{xcflags.join(" ")})
321
351
  args << %Q(debugflags=#{@debugflags.join(" ")})
322
352
  args << %Q(cppflags=#{@cppflags.join(" ")})
@@ -13,7 +13,7 @@ module RubyWasm
13
13
  end
14
14
 
15
15
  def product_build_dir
16
- File.join(@build_dir, target, "yaml-#{LIBYAML_VERSION}")
16
+ File.join(@build_dir, target.to_s, "yaml-#{LIBYAML_VERSION}")
17
17
  end
18
18
 
19
19
  def destdir
@@ -52,12 +52,14 @@ module RubyWasm
52
52
  executor.system "curl",
53
53
  "-o",
54
54
  "#{product_build_dir}/config/config.guess",
55
- "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD"
55
+ "https://cdn.jsdelivr.net/gh/gcc-mirror/gcc@master/config.guess"
56
56
  executor.system "curl",
57
57
  "-o",
58
58
  "#{product_build_dir}/config/config.sub",
59
- "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD"
59
+ "https://cdn.jsdelivr.net/gh/gcc-mirror/gcc@master/config.sub"
60
60
 
61
+ configure_args = self.configure_args.dup
62
+ configure_args << "CFLAGS=-fPIC" if target.pic?
61
63
  executor.system "./configure", *configure_args, chdir: product_build_dir
62
64
  executor.system "make",
63
65
  "install",
@@ -13,7 +13,7 @@ module RubyWasm
13
13
  end
14
14
 
15
15
  def product_build_dir
16
- File.join(@build_dir, target, "openssl-#{OPENSSL_VERSION}")
16
+ File.join(@build_dir, target.to_s, "openssl-#{OPENSSL_VERSION}")
17
17
  end
18
18
 
19
19
  def destdir
@@ -42,7 +42,7 @@ module RubyWasm
42
42
  --libdir=lib
43
43
  -Wl,--allow-undefined
44
44
  ]
45
- if @target == "wasm32-unknown-wasi"
45
+ if @target.triple.start_with?("wasm32-unknown-wasi")
46
46
  args.concat %w[
47
47
  -D_WASI_EMULATED_SIGNAL
48
48
  -D_WASI_EMULATED_PROCESS_CLOCKS
@@ -52,6 +52,11 @@ module RubyWasm
52
52
  -DHAVE_FORK=0
53
53
  ]
54
54
  end
55
+
56
+ if @target.pic?
57
+ args << "-fPIC"
58
+ end
59
+
55
60
  args + tools_args
56
61
  end
57
62
 
@@ -12,13 +12,13 @@ module RubyWasm
12
12
  end
13
13
  def system_triplet_args
14
14
  args = []
15
- case @target
16
- when "wasm32-unknown-wasi"
15
+ case @target.triple
16
+ when /^wasm32-unknown-wasi/
17
17
  args.concat(%W[--host wasm32-wasi])
18
18
  when "wasm32-unknown-emscripten"
19
19
  args.concat(%W[--host wasm32-emscripten])
20
20
  else
21
- raise "unknown target: #{@target}"
21
+ raise "unknown target: #{@target.triple}"
22
22
  end
23
23
  args
24
24
  end
@@ -19,7 +19,7 @@ module RubyWasm
19
19
  when "tarball"
20
20
  digest << @params[:url]
21
21
  when "local"
22
- digest << File.mtime(@params[:src]).to_i.to_s
22
+ digest << File.mtime(@params[:path]).to_i.to_s
23
23
  else
24
24
  raise "unknown source type: #{@params[:type]}"
25
25
  end
@@ -75,12 +75,12 @@ module RubyWasm
75
75
  )
76
76
  when "local"
77
77
  executor.mkdir_p File.dirname(src_dir)
78
- executor.cp_r @params[:src], src_dir
78
+ executor.ln_s File.expand_path(@params[:path]), src_dir
79
79
  else
80
80
  raise "unknown source type: #{@params[:type]}"
81
81
  end
82
82
  (@params[:patches] || []).each do |patch_path|
83
- executor.system "patch", "-p1", patch_path, chdir: src_dir
83
+ executor.system "patch", "-p1", "-i", patch_path, chdir: src_dir
84
84
  end
85
85
  end
86
86
 
@@ -12,7 +12,7 @@ module RubyWasm
12
12
  def lib_product_build_dir
13
13
  File.join(
14
14
  @build_dir,
15
- "wasm32-unknown-wasi",
15
+ "wasm32-unknown-wasip1",
16
16
  "wasi-vfs-#{WASI_VFS_VERSION}"
17
17
  )
18
18
  end
@@ -13,7 +13,7 @@ module RubyWasm
13
13
  end
14
14
 
15
15
  def product_build_dir
16
- File.join(@build_dir, target, "zlib-#{ZLIB_VERSION}")
16
+ File.join(@build_dir, target.to_s, "zlib-#{ZLIB_VERSION}")
17
17
  end
18
18
 
19
19
  def destdir
@@ -54,6 +54,8 @@ module RubyWasm
54
54
  product_build_dir,
55
55
  "--strip-components=1"
56
56
 
57
+ configure_args = self.configure_args.dup
58
+ configure_args << "CFLAGS=-fPIC" if target.pic?
57
59
  executor.system "env",
58
60
  *configure_args,
59
61
  "./configure",
@@ -0,0 +1,24 @@
1
+ module RubyWasm
2
+ # A build target representation
3
+ class Target
4
+ attr_reader :triple
5
+
6
+ def initialize(triple, pic: false)
7
+ @triple = triple
8
+ @pic = pic
9
+ end
10
+
11
+ def pic?
12
+ @pic
13
+ end
14
+
15
+ def to_s
16
+ "#{@triple}#{@pic ? "-pic" : ""}"
17
+ end
18
+
19
+ def cache_key(digest)
20
+ digest << @triple
21
+ digest << "pic" if @pic
22
+ end
23
+ end
24
+ end
@@ -18,7 +18,7 @@ module RubyWasm
18
18
 
19
19
  def self.get(target, build_dir = nil)
20
20
  case target
21
- when "wasm32-unknown-wasi"
21
+ when /^wasm32-unknown-wasi/
22
22
  return RubyWasm::WASISDK.new(build_dir: build_dir)
23
23
  when "wasm32-unknown-emscripten"
24
24
  return RubyWasm::Emscripten.new
@@ -2,6 +2,7 @@ require_relative "build/build_params"
2
2
  require_relative "build/product"
3
3
  require_relative "build/toolchain"
4
4
  require_relative "build/executor"
5
+ require_relative "build/target"
5
6
 
6
7
  class RubyWasm::Build
7
8
  # Source to build from.
@@ -36,6 +37,7 @@ class RubyWasm::Build
36
37
  toolchain:,
37
38
  build_dir:,
38
39
  rubies_dir:,
40
+ wasi_vfs: :default,
39
41
  **options
40
42
  )
41
43
  @target = target
@@ -45,7 +47,7 @@ class RubyWasm::Build
45
47
 
46
48
  @libyaml = RubyWasm::LibYAMLProduct.new(@build_dir, @target, @toolchain)
47
49
  @zlib = RubyWasm::ZlibProduct.new(@build_dir, @target, @toolchain)
48
- @wasi_vfs = RubyWasm::WasiVfsProduct.new(@build_dir)
50
+ @wasi_vfs = wasi_vfs == :default ? RubyWasm::WasiVfsProduct.new(@build_dir) : wasi_vfs
49
51
  @source = RubyWasm::BuildSource.new(src, @build_dir)
50
52
  @baseruby = RubyWasm::BaseRubyProduct.new(@build_dir, @source)
51
53
  @openssl = RubyWasm::OpenSSLProduct.new(@build_dir, @target, @toolchain)
@@ -78,11 +80,13 @@ class RubyWasm::Build
78
80
  @crossruby.cache_key(digest)
79
81
  digest << @build_dir
80
82
  digest << @rubies_dir
81
- digest << @target
83
+ @target.cache_key(digest)
82
84
  digest << @toolchain.name
83
85
  digest << @libyaml.name
84
86
  digest << @zlib.name
85
87
  digest << @openssl.name
86
- digest << @wasi_vfs.name
88
+ if wasi_vfs = @wasi_vfs
89
+ digest << wasi_vfs.name
90
+ end
87
91
  end
88
92
  end