Skip to content

Commit 5ceab5c

Browse files
committed
Add patching for Bundler standalone setup.rb for RubyGems API compatibility
1 parent 4a23f34 commit 5ceab5c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

lib/ruby_wasm/packager/core.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,27 @@ 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 may generate setup.rb that unconditionally calls
229+
# Gem.ruby_api_version. Ruby head can temporarily miss this API while still
230+
# exposing Gem.extension_api_version, so we rewrite the generated setup file
231+
# to use a fallback expression and keep packaged runtimes loadable.
232+
def patch_bundler_standalone_setup(local_path)
233+
setup_rb = File.join(local_path, "bundler", "setup.rb")
234+
return unless File.file?(setup_rb)
235+
236+
content = File.read(setup_rb)
237+
fallback = "Gem.respond_to?(:ruby_api_version) ? Gem.ruby_api_version : Gem.extension_api_version"
238+
patched = content.gsub("Gem.ruby_api_version", fallback)
239+
return if patched == content
240+
241+
RubyWasm.logger.info("Patching #{setup_rb} for RubyGems API compatibility")
242+
File.write(setup_rb, patched)
243+
end
244+
227245
def cache_key(digest)
228246
derive_build.cache_key(digest)
229247
end

0 commit comments

Comments
 (0)