Skip to content

Make the gem CLI work under RUBY_BOX=1 - #9810

Merged
hsbt merged 3 commits into
masterfrom
ruby-box-gem-cli
Aug 26, 2026
Merged

Make the gem CLI work under RUBY_BOX=1#9810
hsbt merged 3 commits into
masterfrom
ruby-box-gem-cli

Conversation

@hsbt

@hsbt hsbt commented Aug 25, 2026

Copy link
Copy Markdown
Member

Under Ruby::Box (RUBY_BOX=1, experimental in Ruby 4.0), every gem command fails to start with ArgumentError: undefined class/module Gem:: because the builtin Marshal runs in the root box and cannot resolve Gem:: constants defined in the main box (https://bugs.ruby-lang.org/issues/22090). This replaces the Marshal.load Marshal.dump deep copies of option defaults with a hand-written Gem::Util.deep_dup.

Native extension builds still fail after that because the extconf.rb subprocess inherits RUBY_BOX=1 and hits infinite recursion in RbConfig.expand (SystemStackError, a known ruby-core issue). Build tools are not a target of box isolation, so Gem::Ext::Builder.run now unsets RUBY_BOX in the subprocess environment.

With both fixes, RUBY_BOX=1 gem install succeeds including native builds. An integration canary runs gem list --local under RUBY_BOX=1 when Ruby::Box is available.

hsbt and others added 3 commits August 26, 2026 13:42
Under Ruby::Box (RUBY_BOX=1) the builtin Marshal runs in the root box and
cannot resolve Gem:: constants defined in the main box, so every gem
command failed to start while deep-copying its option defaults.

https://bugs.ruby-lang.org/issues/22090

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Under Ruby::Box mkmf makes RbConfig.expand recurse until SystemStackError,
so building a native extension failed even once the CLI itself started.
Build tools are not a target of box isolation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The unit tests cover each fix on its own, but nothing checks that a boxed
gem command actually gets as far as listing gems.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@hsbt
hsbt force-pushed the ruby-box-gem-cli branch from 59572d1 to e6ee031 Compare August 26, 2026 04:44
@hsbt
hsbt merged commit bf7937d into master Aug 26, 2026
107 checks passed
@hsbt
hsbt deleted the ruby-box-gem-cli branch August 26, 2026 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant