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

require "strscan.so" uses the strscan gem and does not work #2420

Closed
eregon opened this issue Aug 4, 2021 · 4 comments · Fixed by ruby/strscan#35
Closed

require "strscan.so" uses the strscan gem and does not work #2420

eregon opened this issue Aug 4, 2021 · 4 comments · Fixed by ruby/strscan#35
Assignees

Comments

@eregon
Copy link
Member

eregon commented Aug 4, 2021

$ gem i strscan
Fetching strscan-3.0.0.gem
Building native extensions. This could take a while...
Successfully installed strscan-3.0.0
1 gem installed

$ ruby -e 'require "strscan.so"; puts $".grep(/strscan/); p StringScanner.new("")'
/home/eregon/.rubies/truffleruby-dev/lib/gems/gems/strscan-3.0.0/lib/strscan.so
/home/eregon/.rubies/truffleruby-dev/lib/gems/gems/strscan-3.0.0/ext/strscan/strscan.c:214:in `strscan_s_allocate': External LLVMFunction onig_region_init cannot be found. (com.oracle.truffle.llvm.runtime.except.LLVMLinkerException) (RuntimeError)
Translated to internal error
	from /home/eregon/.rubies/truffleruby-dev/lib/truffle/truffle/cext.rb:1240:in `__allocate__'
	from -e:1:in `<main>'

However require "strscan" picks the stdlib and works fine:

$ ruby -e 'require "strscan"; puts $".grep(/strscan/); p StringScanner.new("")'
/home/eregon/.rubies/truffleruby-dev/lib/truffle/strscan.rb
#<StringScanner fin>

Even bundle exec picks the stdlib:

$ cat Gemfile
gem "strscan"
$ bundle exec ruby -e 'require "strscan"; puts $".grep(/strscan/); p StringScanner.new("")' 
/home/eregon/.rubies/truffleruby-dev/lib/truffle/strscan.rb
#<StringScanner fin>

Found by @noahgibbs in Shopify/yjit-bench#32 (comment)

strscan gem

@eregon eregon changed the title Using the strscan gem does not work require "strscan.so" uses the strscan gem and does not work Aug 4, 2021
@eregon
Copy link
Member Author

eregon commented Aug 4, 2021

It's surprising that the strscan.so is even used in that case, maybe it was a bug of 21.1.0.
I don't see any require "strscan.so" from a quick look.

Anyway we should probably make a PR to the strscan gem so it just does nothing on TruffleRuby since the strscan stdlib is a lot faster (no need to move every String to native or emulate the Onigmo C API) and with much less indirections.

@noahgibbs
Copy link

Makes sense. It's a dependency of one of the (removed in 3.1) net-* gems, so you're likely to see this more frequently going forward. When 3.1 is released properly, there's going to be a lot more code that just installs those gems unconditionally, as our yjit-bench version of Railsbench had been doing.

There are definitely a lot of weird issues with having duplicates of the default CRuby built-in gems that then depend on other external-but-duplicate-a-builtin gems. Bundler's not dealing well with them either.

@eregon
Copy link
Member Author

eregon commented Apr 22, 2022

ruby/strscan#35 will fix this.

@eregon eregon self-assigned this Apr 22, 2022
kou added a commit to ruby/strscan that referenced this issue May 1, 2022
* This is necessary since lib/strscan.rb was added (#25), as the
  TruffleRuby stdlib strscan.rb is no longer found first by `require "strscan"`.
* Write conditions in a way that any other Ruby implementation would
  simply use its stdlib until it is added explicit support in this gem.

Fixes oracle/truffleruby#2420

Co-authored-by: Sutou Kouhei <[email protected]>
@eregon
Copy link
Member Author

eregon commented May 17, 2022

Fixed by ruby/strscan#35

@eregon eregon closed this as completed May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants