Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions lib/ruby_wasm/packager/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,49 @@ def _build_gem_exts(executor, build, gem_home)
]

executor.system(*args, env: env)
patch_bundler_standalone_setup(local_path)
executor.cp_r(local_path, gem_home)
end

# Bundler standalone setup.rb assumes that once `Gem` is defined,
# Gem.ruby_api_version and Gem.extension_api_version are also available.
# In ruby-head packaging this assumption can fail (Gem exists, but these
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have they removed those APIs but just didn't update standalone mode code to reflect that, right? Ij that case, shouldn't we fix the bundler side instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I'll proceed with the investigation.

# API-version helpers are missing), so we inject a compatibility shim
# before Bundler's load-path setup runs.
def patch_bundler_standalone_setup(local_path)
setup_rb = File.join(local_path, "bundler", "setup.rb")
return unless File.file?(setup_rb)

content = File.read(setup_rb)
marker = "# ruby.wasm compatibility shim for missing Gem API version methods"
return if content.include?(marker)

shim = <<~RUBY
#{marker}
if defined?(Gem)
module Gem
def self.ruby_api_version
RbConfig::CONFIG["ruby_version"]
end unless respond_to?(:ruby_api_version)

def self.extension_api_version
if "no" == RbConfig::CONFIG["ENABLE_SHARED"]
"\#{ruby_api_version}-static"
else
ruby_api_version
end
end unless respond_to?(:extension_api_version)
end
end
RUBY

patched = content.sub(/^require 'rbconfig'\n/, "require 'rbconfig'\n#{shim}\n")
return if patched == content

RubyWasm.logger.info("Patching #{setup_rb} for RubyGems API compatibility")
File.write(setup_rb, patched)
end

def cache_key(digest)
derive_build.cache_key(digest)
end
Expand Down
2 changes: 1 addition & 1 deletion packages/npm-packages/ruby-head-wasm-wasip2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"README.md"
],
"scripts": {
"FIXME_SKIP_test": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasip2 ENABLE_COMPONENT_TESTS=1 npm -C ../ruby-wasm-wasi run test:run",
"test": "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasip2 ENABLE_COMPONENT_TESTS=1 npm -C ../ruby-wasm-wasi run test:run",
"build:deps": "cd ../ruby-wasm-wasi && npm run build",
"build:static:files": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist",
"build:static": "npm run build:static:files",
Expand Down
1 change: 1 addition & 0 deletions sig/ruby_wasm/packager.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class RubyWasm::Packager
def name: () -> string

private def _build_gem_exts: (RubyWasm::BuildExecutor, RubyWasm::Build, string gem_home) -> void
private def patch_bundler_standalone_setup: (string local_path) -> void
private def _link_gem_exts: (RubyWasm::BuildExecutor, RubyWasm::Build, string ruby_root, string gem_home, bytes module_bytes) -> bytes
end

Expand Down
Loading