8

Using Apple Silicon M1 machine. Attempting to install ruby gem gem install sassc -v '2.1.0'.

The problem is that clang compiler does not have flag 'native' for Apple M1 yet. Related

Error given: (note I replaced my name with 'yournamehere')

Fetching sassc 2.1.0
Installing sassc 2.1.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/yournamehere/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/sassc-2.1.0/ext
/Users/yournamehere/.asdf/installs/ruby/2.7.2/bin/ruby -I /Users/yournamehere/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0 -r ./siteconf20210303-14183-1uwhwj4.rb extconf.rb
creating Makefile

current directory: /Users/yournamehere/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/sassc-2.1.0/ext
make "DESTDIR=" clean

current directory: /Users/yournamehere/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/sassc-2.1.0/ext
make "DESTDIR="
compiling ./libsass/src/units.cpp
clang: error: the clang compiler does not support '-march=native'
make: *** [units.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/yournamehere/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/sassc-2.1.0 for inspection.
Results logged to /Users/yournamehere/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/extensions/arm64-darwin-20/2.7.0/sassc-2.1.0/gem_make.out

An error occurred while installing sassc (2.1.0), and Bundler cannot continue.
Make sure that `gem install sassc -v '2.1.0' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  sassc-rails was resolved to 2.1.2, which depends on
    sassc
xxjjnn
  • 14,591
  • 19
  • 61
  • 94

3 Answers3

31

According to this answer on sassc-ruby, this flag worked for me as a current workaround:

gem install sassc -- --disable-march-tune-native
João Paulo Motta
  • 3,765
  • 1
  • 19
  • 18
3

We can manually install the gem without that flag. First find where the gem is lurking, looking at the full error this is the line we want:

Gem files will remain installed in /Users/yournamehere/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/sassc-2.1.0 for inspection.

So lets navigate there in terminal. We will be running future commands from this folder until we cd out of there.

cd /Users/yournamehere/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/sassc-2.1.0

Search the directory for march=native using ripgrep or something. Just as the full error message says, it is in ext/Makefile. In this particular Makefile, there are two places where there is a line with march=native.

87 CFLAGS   = $(CCDLFLAGS) $(cflags)  -fno-common -pipe -march=native -mtune=native -flto -DLIBSASS_VERSION='"3.6.1"' $(ARCH_FLAG)
...
91 CXXFLAGS = $(CCDLFLAGS) -g -O2 -std=c++11 -march=native -mtune=native -flto -DLIBSASS_VERSION='"3.6.1"' $(ARCH_FLAG)

Trim away the march=native from all lines. Save and close the file. Now we want to build the gem.

gem build sassc.gemspec

This will create sassc-2.1.0.gem. Do NOT try to install it from here, this directory gets overwritten. Lets copy it to Downloads folder (or somewhere).

mkdir ~/Downloads/sassc
cp -r . ~/Downloads/sassc

Now navigate back to your starting folder where you were having trouble installing sassc.

cd ~/work/projecty_mc_project_face

Now install it from your locally built, march=native free gem

gem install --local ~/Downloads/sassc/sassc-2.1.0.gem

And it should work

> gem install --local ~/Downloads/sassc/sassc-2.1.0.gem
Building native extensions. This could take a while...
Successfully installed sassc-2.1.0
Parsing documentation for sassc-2.1.0
Installing ri documentation for sassc-2.1.0
Done installing documentation for sassc after 0 seconds
1 gem installed

UPDATE: Although the above approach allows you to bundle install, any code which actually uses sassc raises an error:

LoadError:
  cannot load such file -- sassc
xxjjnn
  • 14,591
  • 19
  • 61
  • 94
1

This solved it for me:

bundle update sassc
eikes
  • 4,811
  • 2
  • 31
  • 31