Skip to content

Ruby 3.1.6 compilation error on MacOS Sonoma 14 related to maybe_unused #304

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

Closed
argent-codes opened this issue Sep 27, 2024 · 2 comments
Closed

Comments

@argent-codes
Copy link

A similar issue was closed earlier in the year, so I apologize if this is considered a duplicate, but I am having the same issues compiling bigdecimal, only on a Ruby version that has not been EOL'd. I see that an openssl-related complication ruby-build issue has touched on similar things, but I am not sure whether / how solutions apply to me.

I am using a MacBook Pro M3, Sonoma Version 14.6.1 (23G93), with Ruby 3.1.6:

gem install bigdecimal -v '1.4.4'
Building native extensions. This could take a while...
ERROR:  Error installing bigdecimal:
	ERROR: Failed to build gem native extension.

    current directory: /Users/ekirilov/.gem/ruby/3.1.6/gems/bigdecimal-1.4.4/ext/bigdecimal
/Users/ekirilov/.rubies/ruby-3.1.6/bin/ruby -I /Users/ekirilov/.rubies/ruby-3.1.6/lib/ruby/3.1.0 extconf.rb
checking RUBY_BIGDECIMAL_VERSION... 1.4.4
checking for labs() in stdlib.h... yes
checking for llabs() in stdlib.h... yes
checking for finite() in math.h... no
checking for isfinite() in math.h... no
checking for struct RRational in ruby.h... no
checking for rb_rational_num() in ruby.h... yes
checking for rb_rational_den() in ruby.h... yes
checking for rb_array_const_ptr() in ruby.h... yes
checking for rb_sym2str() in ruby.h... yes
creating Makefile

current directory: /Users/ekirilov/.gem/ruby/3.1.6/gems/bigdecimal-1.4.4/ext/bigdecimal
make DESTDIR\= sitearchdir\=./.gem.20240927-81327-8kcqw4 sitelibdir\=./.gem.20240927-81327-8kcqw4 clean

current directory: /Users/ekirilov/.gem/ruby/3.1.6/gems/bigdecimal-1.4.4/ext/bigdecimal
make DESTDIR\= sitearchdir\=./.gem.20240927-81327-8kcqw4 sitelibdir\=./.gem.20240927-81327-8kcqw4
compiling bigdecimal.c
bigdecimal.c:220:5: error: 'maybe_unused' attribute cannot be applied to types
  220 |     ENTER(1);
      |     ^
bigdecimal.c:68:33: note: expanded from macro 'ENTER'
   68 | #define ENTER(n) volatile VALUE RB_UNUSED_VAR(vStack[n]);int iStack=0
      |                                 ^
/Users/ekirilov/.rubies/ruby-3.1.6/include/ruby-3.1.0/ruby/backward/2/attributes.h:163:28: note: expanded from macro 'RB_UNUSED_VAR'
  163 | #define RB_UNUSED_VAR(x) x RBIMPL_ATTR_MAYBE_UNUSED()
      |                            ^
/Users/ekirilov/.rubies/ruby-3.1.6/include/ruby-3.1.0/ruby/internal/attr/maybe_unused.h:31:39: note: expanded from macro 'RBIMPL_ATTR_MAYBE_UNUSED'
   31 | # define RBIMPL_ATTR_MAYBE_UNUSED() [[maybe_unused]]
   

I feel like I must be doing something wrong, because I can see that this was patched in 3.1.0, but I don't know what.

@monfresh
Copy link

@argent-codes The reason why you're not able to compile the bigdecimal gem is not because there's something wrong with Ruby 3.1.6, but because you're trying to install a version of the bigdecimal gem that was released over 5 years ago, long before Ruby 3.0 existed, and before Apple Silicon Macs existed.

Ruby 3.1.6 comes with version 3.1.1 of bigdecimal. You can verify this by running gem list after installing a fresh copy of Ruby 3.1.6.

I'm assuming that the reason you're trying to install version 1.4.4 of bigdecimal is because that's the version in your project's Gemfile.lock. If that's the case, I highly recommend running bundle update bigdecimal to update it to a version that is compatible with the arm64 architecture that Apple Silicon Macs use. You might need to update your Gemfile as well, or other gems, if they are not allowing bigdecimal to be updated to the latest version.

In my experience helping thousands of people with Ruby and gem installation issues, the 2 most common sources of errors are using/installing outdated gems and/or outdated Ruby versions, especially on Apple Silicon Macs. Many people don't realize that code that was written for the Intel architecture won't necessarily work on Apple Silicon Macs (unless you use Rosetta). Similarly, people run into all kinds of issues after transferring their dev setup from an Intel Mac to an Apple Silicon Mac.

I hope this helps!

@argent-codes
Copy link
Author

I realize I never came back to this - @monfresh was absolutely correct, and upgrading bigdecimal to a more modern version (a pretty easy process) worked like a charm. I've also been able to resolve other similar issues with other gems by doing the same thing.

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

2 participants