sass / sassc-ruby

Use libsass with Ruby!
MIT License
363 stars 157 forks source link

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

Open mohamedhafez opened 2 years ago

mohamedhafez commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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

mohamedhafez commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago
~ $ 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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Relevant code is here:

https://github.com/jruby/jruby/blob/68764c6fee4811dfbd7996504da9400cab61d61d/core/src/main/java/org/jruby/ext/rbconfig/RbConfigLibrary.java#L440-L446

headius commented 2 years ago

This seems to be a case where MacOS prefers arm64 instead of aarch64 for the OS, so I have pushed https://github.com/jruby/jruby/pull/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 commented 2 years ago

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

mungler commented 2 years ago

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

mungler commented 2 years ago

I guess I can try the nightly builds

headius commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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.