Skip to content

Re-enable npm run test for renamed head-wasip2 package by fixing Bundler standalone compatibility#622

Merged
kateinoigakukun merged 2 commits intoruby:mainfrom
ledsun:try-to-ci-check
Mar 8, 2026
Merged

Re-enable npm run test for renamed head-wasip2 package by fixing Bundler standalone compatibility#622
kateinoigakukun merged 2 commits intoruby:mainfrom
ledsun:try-to-ci-check

Conversation

@ledsun
Copy link
Contributor

@ledsun ledsun commented Jan 7, 2026

2nd Challenge

Summary

This PR keeps npm run test enabled for the head-wasip2 package flow by explicitly loading RubyGems
before Bundler standalone setup when the runtime is still in a partial Gem state.

Root Cause

This was reproduced locally against the failing Ruby revision:

  • 7d4983803887a45c311ab954de4527333b976500

logs: https://github.com/ruby/ruby.wasm/actions/runs/22755141423/job/65997955482#step:16:146

At rubyInit return time in that build, the runtime state was:

  • Gem is defined
  • Gem.ruby_api_version is missing
  • Gem.extension_api_version is missing
  • rubygems.rb is not loaded
  • $LOAD_PATH does not yet include the main stdlib directories needed for RubyGems
  • RbConfig.ruby is still nil

Bundler standalone setup assumes that defined?(Gem) is enough to use RubyGems API helpers. In this runtime state,
that assumption is false, so loading /bundle/bundler/setup.rb fails before tests start.

Fix

Before requiring /bundle/bundler/setup.rb, load RubyGems explicitly when:

  • Gem is already defined, and
  • Gem.ruby_api_version is still missing

This keeps the workaround scoped to the Bundler standalone path used by the component-model package.

Why This Fix

This issue appears to depend on a specific Ruby revision and ruby.wasm startup state, not on Bundler standalone in
Given that:

  • the failure was observed only in a particular runtime state,
  • the local reproduction required that exact revision/runtime combination,
  • and there is not yet a small standalone upstream reproduction for Bundler,

I think, this fix is better.

1st Challenge ## Summary

This PR re-enables npm run test for the renamed head-wasip2 npm package flow by fixing a Bundler standalone compatibility issue in the packaged ruby- head runtime.

Previously, the check step was effectively not running as intended after the rename. Once re-enabled, it failed during VM boot because generated /bundle/ bundler/setup.rb expected RubyGems API-version helpers that may be missing in this runtime combination.

Goal

Ensure the renamed head-wasip2 package pipeline can run npm run test in CI without being skipped, and pass the boot phase reliably.

Root Cause

bundle install --standalone generates bundle/.../bundler/setup.rb that assumes:

  • Gem.ruby_api_version
  • Gem.extension_api_version

are available.

In ruby-head packaging/runtime combinations used by this workflow, either method can be missing, causing NoMethodError before tests execute.

What Changed

1) Patch generated Bundler standalone setup after packaging

In RubyWasm::Packager::Core::DynamicLinking#_build_gem_exts, after standalone bundle generation, we now call:

  • patch_bundler_standalone_setup(local_path)

This injects a compatibility shim into generated bundler/setup.rb that defines missing RubyGems API-version methods only when absent.

2) Preserve Bundler path semantics

Instead of replacing Gem.*_api_version expressions inline, this PR injects method shims so Bundler’s original extension/load-path logic remains intact
(including shared/static behavior).

This avoids regressions like failing to resolve js.so.

3) Update type signatures

Added RBS declaration for the new private helper method.

Another solution

Modifying bundler install --standalone might be smarter.

@ledsun ledsun force-pushed the try-to-ci-check branch from e7cdabe to 5ceab5c Compare March 6, 2026 08:19
@ledsun ledsun changed the title A commit to test whether all CI tests pass Re-enable npm run test for renamed head-wasip2 package by fixing Bundler standalone compatibility Mar 6, 2026
Renames the `FIXME_SKIP_test` script to `test` in `package.json`.
@ledsun ledsun force-pushed the try-to-ci-check branch from e691761 to 3f4d006 Compare March 6, 2026 11:56
@ledsun ledsun marked this pull request as ready for review March 6, 2026 12:25

# 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
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
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.

@ledsun ledsun marked this pull request as draft March 7, 2026 09:26
@ledsun ledsun force-pushed the try-to-ci-check branch from a3ed34a to 4701731 Compare March 7, 2026 09:35
@ledsun ledsun marked this pull request as ready for review March 7, 2026 10:08
Copy link
Member

@kateinoigakukun kateinoigakukun left a comment

Choose a reason for hiding this comment

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

Makes sense to me! Thanks 🙏
As a follow-up, it might be better to fix Bundler's standalone code generator to detect the missing methods more granularly https://github.com/ruby/rubygems/blob/884d80fd158fead18bb4f021796a2af062a45ac9/bundler/lib/bundler/installer/standalone.rb#L76

@kateinoigakukun kateinoigakukun merged commit 71ccf46 into ruby:main Mar 8, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants