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

JRuby & M1 Mac: invalid arch name '-arch aarch64' #231

Open
mohamedhafez opened this issue Feb 23, 2022 · 25 comments
Open

JRuby & M1 Mac: invalid arch name '-arch aarch64' #231

mohamedhafez opened this issue Feb 23, 2022 · 25 comments

Comments

@mohamedhafez
Copy link

When I try to gem install sassc under JRuby 9.3.3.0 with my M1 Macbook, I get the following error (even though it works fine under Ruby 3.0.3)

Fetching sassc-2.4.0.gem
Building native extensions. This could take a while...
ERROR:  Error installing sassc:
	ERROR: Failed to build gem native extension.

    current directory: /Users/mohamed/.rvm/gems/jruby-9.3.3.0/gems/sassc-2.4.0/ext
/Users/mohamed/.rvm/rubies/jruby-9.3.3.0/bin/jruby -I /Users/mohamed/.rvm/rubies/jruby-9.3.3.0/lib/ruby/stdlib -r ./siteconf20220222-70925-2bsyqb.rb extconf.rb
creating Makefile

current directory: /Users/mohamed/.rvm/gems/jruby-9.3.3.0/gems/sassc-2.4.0/ext
make DESTDIR\= clean

current directory: /Users/mohamed/.rvm/gems/jruby-9.3.3.0/gems/sassc-2.4.0/ext
make DESTDIR\=
compiling ./libsass/src/ast.cpp
clang: error: invalid arch name '-arch aarch64'
make: *** [ast.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/mohamed/.rvm/gems/jruby-9.3.3.0/gems/sassc-2.4.0 for inspection.
Results logged to /Users/mohamed/.rvm/gems/jruby-9.3.3.0/extensions/universal-java-17/2.6.0/sassc-2.4.0/gem_make.out
@mohamedhafez
Copy link
Author

mohamedhafez commented Feb 25, 2022

@headius perhaps this would be an easy configuration fix for someone on the JRuby team? Or possibly it could be a bug in how JRuby installs C extensions on M1 Macs?

@headius
Copy link

headius commented Feb 25, 2022

Does the sassc gem build on CRuby on M1? This would be in the makefile for libsass so I'm not sure what we can fix on our end...

@headius
Copy link

headius commented Feb 25, 2022

Could be a bug in our mkmf that is providing the wrong flag for arch.

@mohamedhafez
Copy link
Author

mohamedhafez commented Feb 25, 2022

Yup it installs just fine for CRuby 3.0.3.

Taking a look at the Makefile generated by the CRuby installation vs the JRuby installation, there's several differences, but the ARCH_FLAG is -arch aarch64 in JRuby, and -m64 for CRuby...

@mohamedhafez
Copy link
Author

And the only thing different between the Makefile generated by/for JRuby on an Intel Mac is that there the ARCH_FLAG variable is set to x86_64.

@headius
Copy link

headius commented Feb 25, 2022

Show me jruby -v just so I can be sure you are running natively on M1.

ARCH_FLAG seems like the culprit... we will need to figure out where that is being set and make sure it reflects an appropriate build flag on M1.

@mohamedhafez
Copy link
Author

~ $ jruby -v
jruby 9.3.3.0 (2.6.8) 2022-01-19 b26de1f5c5 OpenJDK 64-Bit Server VM 17.0.2+8 on 17.0.2+8 +jit [darwin-aarch64]

@headius
Copy link

headius commented Feb 25, 2022

Hmm oddly enough, JRuby appears to hardcode ARCH_FLAGS to -m64 on a 64-bit platform so need to do more digging to figure out why our flags don't match CRuby.

@headius
Copy link

headius commented Mar 10, 2022

Ok I see now that we override the ARCH_FLAG on Mac to be -arch with either x86_64 or aarch64. I think aarch64 is appropriate for Linux, but MacOS may want it to be arm64.

headius added a commit to headius/jruby that referenced this issue Mar 10, 2022
This should allow sassc and other external libraries to build
using the makefile configuration bits in rbconfig.

See sass/sassc-ruby#231
@headius
Copy link

headius commented Mar 10, 2022

This seems to be a case where MacOS prefers arm64 instead of aarch64 for the OS, so I have pushed jruby/jruby#7132 to fix this in JRuby 9.3.4.0.

This might be relevant on Linux/aarch64 as well but I do not have such a machine to test against right now. I can confirm the fix above does allow sassc to build on JRuby on MacOS/M1.

@headius
Copy link

headius commented Mar 11, 2022

I've merged the fixes into JRuby's 9.3.x branch and they will go out sometime soon in 9.3.4.

@mungler
Copy link

mungler commented Mar 15, 2022

Are there any workarounds for this until 9.3.4.0 comes out? This prevents me from working on my M1 machine.

@mungler
Copy link

mungler commented Mar 15, 2022

I guess I can try the nightly builds

@headius
Copy link

headius commented Mar 16, 2022

The patch mostly changes how we set up some static configuration data. You could make the same changes in some code preamble. I'm not at my desk but I can demonstrate later if you have trouble figuring it out. The values are either writable or we can get around any read-only issues.

@headius
Copy link

headius commented Mar 16, 2022

And by code preamble, I mean making sure to load a file that corrects those bad values before RubyGems runs install scripts. Editing RG source in place is another option.

I'm hoping to set up nightly docker images soon as well.

@mungler
Copy link

mungler commented Mar 16, 2022

Hey, thanks @headius - in fact I grabbed the latest nightly of 9.4.0.0 and stuffed that into my VM as ~/.rubies/jruby-9.3.3.0 - its a hack but it works for me for now, until 9.3.3.0 proper comes along. Thanks!

@mungler
Copy link

mungler commented Mar 16, 2022

Actually, scratch that, its giving me a weird error with our code. I think I probably do need to build a patched 9.3.4.0-pre from source then, or try your preamble idea.

@headius
Copy link

headius commented Mar 16, 2022

The 9.4 builds from master are probably a little premature, since they are currently transitioning to Ruby 3.1 compatibility. A nightly build of 9.3 would be better but may not have run recently due to some unaddressed failures in CI. I'll kick off a snapshot build of 9.3 that you can try out.

@headius
Copy link

headius commented Mar 16, 2022

An updated 9.3.4 build should appear here soon:

https://oss.sonatype.org/content/repositories/snapshots/org/jruby/jruby-dist/9.3.4.0-SNAPSHOT/

@headius
Copy link

headius commented Mar 16, 2022

its giving me a weird error with our code

I would also very much like to know what the error was! We are trying to work towards stabilizing master for our next major release. Open an issue with the error and any information you can provide.

@thesigmoidfunction
Copy link

I and my team is also facing this issue.
The entire team uses M1 MAC; the same architecture and has the system configurations. The entire team could install jruby and sassc without any issues except for me. Please note, they installed jruby-9.3.3.0 way before me whereas I installed jruby-9.3.4.0 first and then installed 9.3.3.0 very recently. Can you help us find and resolve the issue?
Thanks in advance.
PFB the error message while installing (gem)sassc:

/Users/rachitamishra/.rbenv/versions/jruby-9.3.3.0/lib/ruby/gems/shared/gems/sassc-2.1.0/ext
make DESTDIR\=
compiling ./libsass/src/c99func.c
clang: error: invalid arch name '-arch aarch64'
make: *** [c99func.o] Error 1

make failed, exit code 2

@headius
Copy link

headius commented Jul 27, 2022

This really should be fixed in JRuby 9.3.4.0. can you confirm you are getting an error running 9.3.4.0 or higher and not 9.3.3.0?

@thesigmoidfunction
Copy link

Actually, the entire team uses 9.3.3.0 and they face no such issue so, wanted to understand what changed that's causing this error.

@headius
Copy link

headius commented Sep 23, 2022

@thesigmoidfunction If you are still having issues with this, open an issue or discussion on the JRuby project, or join us on the #jruby chat room on Matrix and we'll try to help. I am convinced at this point that we fixed this issue, since we have had users on M1 for several months now.

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

4 participants