rules_ruby icon indicating copy to clipboard operation
rules_ruby copied to clipboard

"Can't find ruby interpreter in the PATH"

Open vg250156 opened this issue 4 years ago • 5 comments

Hello, I'm looking for usage information on this project, looking to incorporate it into an existing mono-repo. For our purposes as a primarily golang project, I can't rely on ruby already being pre-installed on our devs' machines, so I'm doing this in a VM that doesn't have ruby installed. A very basic install with the WORKSPACE, BUILD.bazel, a Gemfile and a ruby source file fails to bazel run with /usr/bin/env: ‘ruby’: No such file or directory

It will also output a DEBUG message with DEBUG: /home/vince/.cache/bazel/_bazel_vince/acbc1f1ef0fcc039a89f9e3efce79ee0/external/bazelruby_rules_ruby/ruby/private/toolchains/ruby_runtime.bzl:91:14: Can't find ruby interpreter in the PATH

This is due to the build target boilerplate calling /usr/bin/env ruby in a shebang. I would have assumed that rules_ruby would put the ruby that it has just built into PATH when executing a ruby_binary but this apparently isn't the case. Is there some kind of WORKSPACE invocation I'm missing? How can I get it to use the ruby that it's installing?

vg250156 avatar Sep 27 '21 18:09 vg250156

I have my test project repo here: https://github.com/vg250156/ruby-rules-test/

To reproduce, ensure there is no ruby in PATH, then execute bazel run //:bar

vg250156 avatar Sep 27 '21 18:09 vg250156

I think most people rely on the preinstalled or rbenv-managed ruby.

While our rules do build ruby if none is found, this code path has not been widely used or tested.

In order for #!/usr/bin/env ruby to work the binary folder must simply be in the $PATH

The rules that build ruby interpreter were forked from the Sorbet project. Perhaps you can create an issue there or see how they set this up?

kigster avatar Sep 27 '21 20:09 kigster

I would love to work with you on solving this together. Let me know if you are down.

kigster avatar Nov 08 '21 22:11 kigster

Running into this problem as well! The created ruby_binary is actually not using the pre-built interpreter but my system Ruby (which happens to be a different version breaking everything 😅).

Looking through the code it seems that the right interpreter binary is passed to the ruby_binary wrapper https://github.com/bazelruby/rules_ruby/blob/master/ruby/private/binary.bzl#L68 but the interpreter value is actually not used in the wrapper template itself https://github.com/bazelruby/rules_ruby/blob/master/ruby/private/binary_wrapper.tpl.

Secondly the interpreter executable is not added to the runfiles of the ruby_binary https://github.com/bazelruby/rules_ruby/blob/master/ruby/private/binary.bzl#L75-L78, so even if it would be used within the wrapper Ruby still wouldn't be able to find it.

Not a Bazel expert by far, so my observations could be completely wrong 🙈

mvgijssel avatar Apr 11 '22 21:04 mvgijssel

Looking for additional core maintainers: https://github.com/bazelruby/rules_ruby/discussions/146

kigster avatar May 10 '23 17:05 kigster