protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
65.56k stars 15.47k forks source link

Ruby gem 3.24.0.rc.1 fails to install for Ruby 2.5 & 2.6 for the 'ruby' platform variant #13307

Closed marcotc closed 1 year ago

marcotc commented 1 year ago

What version of protobuf and what language are you using? Version: v3.24.0-rc1 Language: Ruby

What operating system (Linux, Windows, ...) and version?

Docker x86_64, Debian base image.

What runtime / compiler are you using (e.g., python version or gcc version)

ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux]. Ruby 2.6.

gcc version 8.3.0 (Debian 8.3.0-6).

What did you do? Steps to reproduce the behavior:

  1. docker run --rm -it ruby:2.5 gem install google-protobuf -v 3.24.0.rc.1 --platform ruby
  2. Installation errors out with error: protobuf.h:45:2: error: #error Protobuf requires Ruby >= 2.7

What did you expect to see

Gem should not advertise support for a Ruby version it doesn't support. This is working correctly for all platforms 3.24.0.rc.1 is published for, except the ruby platform, which advertises Ruby >= 2.5. All other platforms advertise Ruby >= 2.7.

For example, for x86_64-linux, the command fails with a clear message: docker run --rm -it ruby:2.5 gem install google-protobuf -v 3.24.0.rc.1 --platform x86_64-linux

Fetching google-protobuf-3.24.0.rc.1-x86_64-linux.gem
ERROR:  Error installing google-protobuf:
    The last version of google-protobuf (= 3.24.0.rc.1) to support your Ruby & RubyGems was 3.24.0.rc.1. Try installing it with `gem install google-protobuf -v 3.24.0.rc.1` and then running the current command again
    google-protobuf requires Ruby version >= 2.7, < 3.3.dev. The current ruby version is 2.5.9.229.

What did you see instead?

Fetching google-protobuf-3.24.0.rc.1.gem
Building native extensions. This could take a while...
ERROR:  Error installing google-protobuf:
    ERROR: Failed to build gem native extension.

    current directory: /usr/local/bundle/gems/google-protobuf-3.24.0.rc.1/ext/google/protobuf_c
/usr/local/bin/ruby -I /usr/local/lib/ruby/site_ruby/2.5.0 -r ./siteconf20230713-1-7dyfs2.rb extconf.rb
creating Makefile

current directory: /usr/local/bundle/gems/google-protobuf-3.24.0.rc.1/ext/google/protobuf_c
make "DESTDIR=" clean

current directory: /usr/local/bundle/gems/google-protobuf-3.24.0.rc.1/ext/google/protobuf_c
make "DESTDIR="
compiling protobuf.c
In file included from protobuf.c:31:
protobuf.h:45:2: error: #error Protobuf requires Ruby >= 2.7
 #error Protobuf requires Ruby >= 2.7
  ^~~~~
cc1: warning: unrecognized command line option ‘-Wno-self-assign’
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
make: *** [Makefile:243: protobuf.o] Error 1

make failed, exit code 2

Gem files will remain installed in /usr/local/bundle/gems/google-protobuf-3.24.0.rc.1 for inspection.
Results logged to /usr/local/bundle/extensions/x86_64-linux/2.5.0/google-protobuf-3.24.0.rc.1/gem_make.out

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment

The issue this causes us is that gem "google-protobuf" is failing in our builds of Ruby 2.5 & 2.6 because bundler thinks 3.24.0.rc.1 is compatible with those versions of Ruby.

haberman commented 1 year ago

Protobuf 3.24.x is dropping support for CRuby <2.7: https://protobuf.dev/news/2023-07-06/#dropping-python-37-support

Unfortunately we were not able to update our gemspec to s.required_ruby_version >= 2.7, because that broke compatibility with JRuby 9.2, which we still support. So currently we still list s.required_ruby_version >= 2.5.

Is there a way we can advertise compatibility with CRuby >= 2.7 and JRuby >= 9.2.0?

marcotc commented 1 year ago

I see that there's a specific platform: java published for this gem.

Would allowing Ruby >= 2.5 only for platform: java work for JRuby 9.2.0?

ivoanjo commented 1 year ago

Hey!

I work with Marco and noticed that since you already have a if RUBY_PLATFORM == "java", you should be able to move the required_ruby_version inside it, e.g. something like:

Gem::Specification.new do |s|
  s.name        = "google-protobuf"
  s.version     = "3.23.0"
  git_tag       = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag
  s.licenses    = ["BSD-3-Clause"]
  s.summary     = "Protocol Buffers"
  s.description = "Protocol Buffers are Google's data interchange format."
  s.homepage    = "https://developers.google.com/protocol-buffers"
  s.authors     = ["Protobuf Authors"]
  s.email       = "protobuf@googlegroups.com"
  s.metadata    = { "source_code_uri" => "https://github.com/protocolbuffers/protobuf/tree/#{git_tag}/ruby" }
  s.require_paths = ["lib"]
  s.files       = Dir.glob('lib/**/*.rb')
  if RUBY_PLATFORM == "java"
    s.platform  = "java"
    s.files     += ["lib/google/protobuf_java.jar"]
    s.required_ruby_version = '>= 2.5'
  else
    s.files     += Dir.glob('ext/**/*')
    s.extensions= ["ext/google/protobuf_c/extconf.rb"]
    s.add_development_dependency "rake-compiler-dock", "= 1.2.1"
    s.required_ruby_version = '>= 2.7'
  end
  s.add_development_dependency "rake-compiler", "~> 1.1.0"
  s.add_development_dependency "test-unit", '~> 3.0', '>= 3.0.9'
end

Code in the gemfile gets evaluated at packaging time, and its output is distributed inside the .gem file.

zhangskz commented 1 year ago

We ended up opting to drop support for JRuby 9.2 and 9.3 in 24.x release, after adding tests for JRuby 9.4 support. This means we can now consistently enforce >=2.7 as our required ruby version, which should resolve this issue.

This will be released in 24.0-rc2 which we are planning to release this week.

This decision was made based on the support window for the corresponding Ruby version per https://cloud.google.com/ruby/getting-started/supported-ruby-versions.

ivoanjo commented 1 year ago

That works great for us as well!

As a follow up, would you mind yanking the 3.24.0.rc.1 version with the incorrect metadata (this one) once rc2 is out?

That would be very very helpful because it would make the legacy Rubies pick up the last supported version (3.24.4), instead of the forever-broken-for-them rc1.

zhangskz commented 1 year ago

We've yanked all 3.24.0.rc.1 artifacts for Ruby, and 3.24.rc.2 has been released with the updated required ruby version number. Please let us know if you still have any trouble, and thanks for catching this in our -RC!

It does seem surprising to us that our -RC version would get picked up automatically given these are release candidates that are expected to be somewhat unstable. How is this being picked up on your side?

ivoanjo commented 1 year ago

We've yanked all 3.24.0.rc.1 artifacts for Ruby, and 3.24.rc.2 has been released with the updated required ruby version number. Please let us know if you still have any trouble, and thanks for catching this in our -RC!

Thanks a lot! :bow:

It does seem surprising to us that our -RC version would get picked up automatically given these are release candidates that are expected to be somewhat unstable. How is this being picked up on your side?

That's a very very good question. My understanding matches yours -- rubygems/bundler should not automatically pick up rc releases unless you ask it to.

And yet, that's what we saw in our CI (and I could reproduce it locally as well): https://app.circleci.com/pipelines/github/DataDog/dd-trace-rb/10871/workflows/90c509f6-a12a-441a-8e1d-ad0b1567efed/jobs/405709 .

Our Ruby 2.6 image used for testing doesn't appear to be particularly fancy (link 1) and the Gemfile excludes a few other versions of google-protobuf (for compatibility with even older Rubies), but nothing seems to jump out at me either (link 2).

zhangskz commented 1 year ago

Closing this issue, since the original ruby required ruby version issue has been addressed.

Nothing jumps out at me in your setup and I believe we are releasing as pre-release correctly -- https://rubygems.org/gems/google-protobuf/versions/3.24.0.rc.2-x64-mingw32 shows gem install google-protobuf -v 3.24.0.rc.2 --pre. Feel free to reopen a new issue if something seems to be misconfigured on our side though.

In any case, it is helpful for us to get feedback like this for our earlier -RCs to address issues like this in subsequent -RCs, so thank you for the report.