Skip to content

Commit 3f4d006

Browse files
committed
Activates standard 'test' script
Renames the `FIXME_SKIP_test` script to `test` in `package.json`.
1 parent 24fbf24 commit 3f4d006

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

lib/ruby_wasm/packager/core.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,49 @@ def _build_gem_exts(executor, build, gem_home)
221221
]
222222

223223
executor.system(*args, env: env)
224+
patch_bundler_standalone_setup(local_path)
224225
executor.cp_r(local_path, gem_home)
225226
end
226227

228+
# Bundler standalone setup.rb assumes that once `Gem` is defined,
229+
# Gem.ruby_api_version and Gem.extension_api_version are also available.
230+
# In ruby-head packaging this assumption can fail (Gem exists, but these
231+
# API-version helpers are missing), so we inject a compatibility shim
232+
# before Bundler's load-path setup runs.
233+
def patch_bundler_standalone_setup(local_path)
234+
setup_rb = File.join(local_path, "bundler", "setup.rb")
235+
return unless File.file?(setup_rb)
236+
237+
content = File.read(setup_rb)
238+
marker = "# ruby.wasm compatibility shim for missing Gem API version methods"
239+
return if content.include?(marker)
240+
241+
shim = <<~RUBY
242+
#{marker}
243+
if defined?(Gem)
244+
module Gem
245+
def self.ruby_api_version
246+
RbConfig::CONFIG["ruby_version"]
247+
end unless respond_to?(:ruby_api_version)
248+
249+
def self.extension_api_version
250+
if "no" == RbConfig::CONFIG["ENABLE_SHARED"]
251+
"\#{ruby_api_version}-static"
252+
else
253+
ruby_api_version
254+
end
255+
end unless respond_to?(:extension_api_version)
256+
end
257+
end
258+
RUBY
259+
260+
patched = content.sub(/^require 'rbconfig'\n/, "require 'rbconfig'\n#{shim}\n")
261+
return if patched == content
262+
263+
RubyWasm.logger.info("Patching #{setup_rb} for RubyGems API compatibility")
264+
File.write(setup_rb, patched)
265+
end
266+
227267
def cache_key(digest)
228268
derive_build.cache_key(digest)
229269
end

packages/npm-packages/ruby-head-wasm-wasip2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"README.md"
3131
],
3232
"scripts": {
33-
"FIXME_SKIP_test": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasip2 ENABLE_COMPONENT_TESTS=1 npm -C ../ruby-wasm-wasi run test:run",
33+
"test": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasip2 ENABLE_COMPONENT_TESTS=1 npm -C ../ruby-wasm-wasi run test:run",
3434
"build:deps": "cd ../ruby-wasm-wasi && npm run build",
3535
"build:static:files": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist",
3636
"build:static": "npm run build:static:files",

sig/ruby_wasm/packager.rbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class RubyWasm::Packager
8181
def name: () -> string
8282

8383
private def _build_gem_exts: (RubyWasm::BuildExecutor, RubyWasm::Build, string gem_home) -> void
84+
private def patch_bundler_standalone_setup: (string local_path) -> void
8485
private def _link_gem_exts: (RubyWasm::BuildExecutor, RubyWasm::Build, string ruby_root, string gem_home, bytes module_bytes) -> bytes
8586
end
8687

0 commit comments

Comments
 (0)