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

Gem install fails for Ruby 3.2 in MacOS 12.6 #120

Closed
emceeaich opened this issue Jan 6, 2023 · 4 comments
Closed

Gem install fails for Ruby 3.2 in MacOS 12.6 #120

emceeaich opened this issue Jan 6, 2023 · 4 comments

Comments

@emceeaich
Copy link

Summary

Gem install fails with include file not found

Steps to reproduce

git clone [email protected]:zk-ruby/zookeeper.git
cd zookeeper
cat .ruby-version
3.2.0
^d
gem make zookeeper.gemspec
gem install zookeeper-1.5.4
irb 
>> require('zookeeper')

What happened

irb
irb(main):001:0> RUBY_VERSION
=> "3.2.0"
irb(main):002:0> require 'zookeeper'
<internal:/Users/emmah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- /Users/emmah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/zookeeper-1.5.4/ext/zookeeper_c (LoadError)
	from <internal:/Users/emmah/.rbenv/versions/3.2.0/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /Users/emmah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/zookeeper-1.5.4/lib/zookeeper.rb:26:in `block in require_root'
	from /Users/emmah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/zookeeper-1.5.4/lib/zookeeper.rb:25:in `each'
	from /Users/emmah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/zookeeper-1.5.4/lib/zookeeper.rb:25:in `require_root'
	from /Users/emmah/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/zookeeper-1.5.4/ext/c_zookeeper.rb:8:in `<top (required)>'

Expected

Gem installs without error

@emceeaich
Copy link
Author

Another member of the team observed this when reproducing the error:

also here’s some output from when i installed it locally in 3.2:

linking shared-object zookeeper_c.bundle
current directory: /Users/daniel/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/zookeeper-1.5.4/ext
["make", "DESTDIR=", "sitearchdir=./.gem.20230105-56605-j5n3n4", "sitelibdir=./.gem.20230105-56605-j5n3n4", "install"]
/usr/bin/install -c -m 0755 zookeeper_c.bundle ./.gem.20230105-56605-j5n3n4

and the same bits for 3.1:

linking shared-object zookeeper_c.bundle
current directory: /Users/daniel/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/zookeeper-1.5.4/ext
["make", "DESTDIR=", "install"]
/usr/bin/install -c -m 0755 zookeeper_c.bundle ./.gem.20230105-66585-rsvonm

@tsroten
Copy link

tsroten commented Jan 6, 2023

It looks like the issue stems from the upgrade to Rubygems 3.4 as part of the Ruby 3.2.0 release. Specifically, build artifacts in the ext/ directory are cleaned up during gem installation.

Here is a possible fix:

diff --git a/ext/c_zookeeper.rb b/ext/c_zookeeper.rb
index 1c6f091..54f7d3f 100644
--- a/ext/c_zookeeper.rb
+++ b/ext/c_zookeeper.rb
@@ -5,7 +5,11 @@ Zookeeper.require_lib(
   'zookeeper/exceptions' # zookeeper_c depends on exceptions defined in here
 )

-Zookeeper.require_root 'ext/zookeeper_c'
+begin
+    Zookeeper.require_root 'ext/zookeeper_c'
+rescue LoadError # Rubygems 3.4+ cleans up build artifacts in the ext/ directory.
+    Zookeeper.require_lib 'zookeeper_c'
+end

 # require File.expand_path('../zookeeper_c', __FILE__)

malmckay added a commit that referenced this issue Jan 6, 2023
Adds a test to catch issues like #120
@malmckay
Copy link
Member

malmckay commented Jan 6, 2023

@emceeaich & @tsroten Thanks for the report, and the suggested fix. I've release 1.5.5 that loads correctly on Ruby 3.2

@malmckay malmckay closed this as completed Jan 6, 2023
@emceeaich
Copy link
Author

Confirming this is working in my env. Thank you all!

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

No branches or pull requests

3 participants