Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootsnap LoadError for Prism #463

Closed
bparanj opened this issue Jan 11, 2024 · 8 comments · Fixed by #464
Closed

Bootsnap LoadError for Prism #463

bparanj opened this issue Jan 11, 2024 · 8 comments · Fixed by #464

Comments

@bparanj
Copy link

bparanj commented Jan 11, 2024

Steps to reproduce

bug_report.rb:

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "bootsnap"
end

ENV["BOOTSNAP_CACHE_DIR"] = "bootsnap_cache"
require "bootsnap/setup"

require "prism"

Expected behavior

It should load the prism gem that is now part of Ruby 3.3.0 standard library. Any environment other than development results in error.

Actual behavior

RAILS_ENV=test ruby bug.rb
Fetching gem metadata from https://rubygems.org/...
Resolving dependencies...
/home/ubuntu/.rvm/gems/ruby-3.3.0@r71/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require': cannot load such file -- prism/prism (LoadError)
	from /home/ubuntu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/prism.rb:96:in `<main>'
	from /home/ubuntu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
	from /home/ubuntu/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
	from /home/ubuntu/.rvm/gems/ruby-3.3.0@r71/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	from bug.rb:14:in `<main>'

System configuration

Bootsnap version: 1.17.0

Ruby version: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux]

Rails version: Rails 7.1.2

@casperisfine
Copy link
Contributor

Hum, there must be more to it because I can't repro on my machine:

$ ruby /tmp/foo.rb
Fetching gem metadata from https://rubygems.org/...
Resolving dependencies...
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
Prism

@casperisfine
Copy link
Contributor

nevermind, I missed the RAILS_ENV was important, I can now repro.

Thanks, I'll have a look later today or tomorrow.

@casperisfine
Copy link
Contributor

Something is very weird, the prism.so is is loaded as a relative path:

$ DISABLE_BOOTSNAP=true RAILS_ENV=test ruby /tmp/foo.rb  | grep prism
/opt/rubies/3.3.0/lib/ruby/3.3.0/prism/node.rb
/opt/rubies/3.3.0/lib/ruby/3.3.0/prism/node_ext.rb
/opt/rubies/3.3.0/lib/ruby/3.3.0/prism/parse_result.rb
/opt/rubies/3.3.0/lib/ruby/3.3.0/prism/parse_result/comments.rb
/opt/rubies/3.3.0/lib/ruby/3.3.0/prism/visitor.rb
/opt/rubies/3.3.0/lib/ruby/3.3.0/prism/parse_result/newlines.rb
/opt/rubies/3.3.0/lib/ruby/3.3.0/prism/debug.rb
/opt/rubies/3.3.0/lib/ruby/3.3.0/prism/pack.rb
prism/prism.so
/opt/rubies/3.3.0/lib/ruby/3.3.0/prism.rb

prism/prism.so

Also the .so simply isn't in the Ruby installation at all it seems:

$ find  /opt/rubies/3.3.0/lib/ruby/3.3.0/  -name prism.so

I suspect it's loaded with some kind of hack. I'll dig more, but I fear we might need a hack on our side too :/

FYI @kddnewton

@casperisfine
Copy link
Contributor

void
Init_Prism(void)
{
    ruby_init_ext("prism/prism.so", Init_prism);
}
// Private API for statically linked extensions.
// Used with the ext/Setup file, the --with-setup and
// --with-static-linked-ext configuration option, etc.
void
ruby_init_ext(const char *name, void (*init)(void))
{
    st_table *inits_table;
    rb_vm_t *vm = GET_VM();

    if (feature_provided(vm, name, 0))
        return;

    inits_table = vm->static_ext_inits;
    if (!inits_table) {
        inits_table = st_init_strtable();
        vm->static_ext_inits = inits_table;
    }
    st_update(inits_table, (st_data_t)name, register_init_ext, (st_data_t)init);
}

So as I suspected, prism.so doesn't actually exist, Ruby simply pretend it does.

@casperisfine
Copy link
Contributor

1.17.1 is out with the fix. Thanks for the detailed report.

@kddnewton
Copy link

@casperisfine anything you need from me on this? Looks like you solved it.

@casperisfine
Copy link
Contributor

Yeah, I worked around it. This was mostly to let you know.

@kddnewton
Copy link

Sounds good thanks!

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 a pull request may close this issue.

3 participants