rules_ruby icon indicating copy to clipboard operation
rules_ruby copied to clipboard

`ruby_library` not using specified SDK version

Open jgao54 opened this issue 2 years ago • 2 comments

We are testing out the flow where the desired version of ruby is not installed on the host.

I expect for rules_ruby to be able to install and use v2.7.6. (Note this first requires bumping the ruby-build version, which I created a PR here).

With the version specified in WORKSPACE:

load("@bazelruby_rules_ruby//ruby:deps.bzl", "rules_ruby_select_sdk")
rules_ruby_select_sdk(version = "2.7.6")

I can confirm that ruby interpreter that's installed to the @org_ruby_lang_ruby_toolchain external repository is the right version:

➜  org_ruby_lang_ruby_toolchain build/bin/ruby -v
ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [arm64-darwin21]

However, running any ruby_library target i get this error on my macos:

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in 'require': incompatible library version...

I think this requires updating the way the binary wrapper is implemented, which defaults to the first ruby found in PATH today rather than the version that's specified in the SDK:

#!/usr/bin/env ruby

...

def find_ruby_binary
  File.join(
    RbConfig::CONFIG['bindir'],
    RbConfig::CONFIG['ruby_install_name'],
  )
end

In fact, it looks like there was an intention to substitute {interpreter} here but the wrapper script template itself does not have a {interpreter} placeholder anywhere, which looks like a bug.

jgao54 avatar Jun 27 '23 01:06 jgao54

I missed this issue, which points to the same bug.

jgao54 avatar Jun 27 '23 02:06 jgao54

That's not the issue afaik.

Thank you for including your error:

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in 'require': incompatible library version...

What this error tells you is that the Ruby being used here is the system Ruby that comes with Os-X. It's a Ruby 2.6, and it's installed into a read only file system. So naturally you can't install any gems there.

The rules expect your ruby to be installed by rbenv.

In order for rbenv to work, you must add the following to your shell initialization file:

eval "$(rbenv init -)"

Once you do and restart your terminal session, run the command which ruby, and if it worked you should see something like

  • /Users/<username>/.rbenv/shims/ruby

That's how you know it's working.

kigster avatar Nov 09 '23 17:11 kigster