Search code examples
rubybundlerfreebsd

FreeBSD Could not find gem in any of the sources


I am trying to bundle on FreeBSD and it cannot find the grpc gem. I installed the grpc 1.30.2 version using a FreeBSD package but it cannot find the system gem.

I'm hoping there is a bundle config setting to find and use the system gem which is already built and intalled.

The error I get is:

An error occurred while installing grpc (1.30.2), and Bundler cannot continue.
Make sure that `gem install grpc -v '1.30.2' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  grpc
* bundle install
Warning: the running version of Bundler (2.0.2) is older than the version that created the lockfile (2.2.11). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
/usr/local/lib/ruby/site_ruby/2.7/rubygems/package.rb:509: warning: Using the last argument as keyword parameters is deprecated
/usr/local/lib/ruby/site_ruby/2.7/rubygems/package.rb:509: warning: Using the last argument as keyword parameters is deprecated
/usr/local/lib/ruby/site_ruby/2.7/rubygems/package.rb:509: warning: Using the last argument as keyword parameters is deprecated
/usr/local/lib/ruby/site_ruby/2.7/rubygems/package.rb:509: warning: Using the last argument as keyword parameters is deprecated
Some gems seem to be missing from your vendor/cache directory.
Could not find grpc-1.30.2 in any of the sources
* Visruleparser
A    extras/visruleparser.pl
Export complete.
* precompile assets
Could not find grpc-1.30.2 in any of the sources
Run `bundle install` to install missing gems.

My Gemfile has these lines

source 'https://rubygems.org'
gem 'grpc', '1.30.2'
gem 'grpc-tools', '1.30.2'

The Gemfile.lock has these

  grpc (= 1.30.2)
  grpc-tools (= 1.30.2)

These FreeBSD packages are installed

>pkg info -x grpc
grpc-1.22.0_4,2
rubygem-grpc-1.30.2
>gem list grpc

*** LOCAL GEMS ***

grpc (1.30.2)

Listing remote gems shows nothing on FreeBSD

>gem list --remote -all gprc 

*** LOCAL GEMS ***

But on macOS I get these (among others)

>gem list --remote --all grpc
grpc (1.37.0 ruby universal-darwin x64-mingw32 x86-linux x86-mingw32 x86_64-linux,
1.36.0 ruby universal-darwin x64-mingw32 x86-linux x86-mingw32 x86_64-linux,
...
1.30.2 ruby universal-darwin x64-mingw32 x86-linux x86-mingw32 x86_64-linux,
...

The gem is installed in the directory /usr/local/lib/ruby/gems/2.7/gems/grpc-1.30.2 with a src subdirectory and a ruby subdirectory below that.

>ls /usr/local/lib/ruby/gems/2.7/gems/grpc-1.30.2/src/ruby
bin ext lib pb  spec

Environment

FreeBSD       11.4
Ruby          2.7.2p137
RubyGems      3.0.8
Bundler       2.1.4

Solution

  • Looks like this may be my fault. The gem packages purposefully remove the cache dir from the gem. This was originally added here:

    https://cgit.freebsd.org/ports/commit/Mk/bsd.ruby.mk?id=8d77480356f58d6d8d1c69884d1ba9cc98ed383a

    and lives on here:

    https://cgit.freebsd.org/ports/tree/Mk/Uses/gem.mk#n111

        ${RM} -r ${STAGEDIR}${PREFIX}/${CACHE_DIR} 2> /dev/null || ${TRUE}
    

    This was added because so many gems include large amounts of stuff that is never used in the cache dir, including complete copies of source, intermediate build output, etc. that shouldn't really be packaged.

    If you're building your own packages you can try the line from gem.mk that removes the cache dir. Otherwise, we may need to revisit this upstream. Regardless, you should probably open a bug upstream at:

    https://bugs.freebsd.org/bugzilla/

    But there are tradeoffs and I'm not sure about the use case of bundling gems installed from system packages. (I haven't been using Ruby as much recently.)