安装sassc时出错,clang编译器不支持'-march=native',M1

时间:2021-03-03 12:00:43

标签: ruby clang apple-m1

使用 Apple Silicon M1 机器。正在尝试安装 ruby​​ gem gem install sassc -v '2.1.0'

问题是clang编译器还没有Apple M1的'native'标志。 Related

给出错误:(注意我用'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

3 个答案:

答案 0 :(得分:2)

我们可以在没有该标志的情况下手动安装 gem。首先找到 gem 潜伏的地方,查看完整的错误这是我们想要的行:

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.

所以让我们在终端中导航到那里。我们将从此文件夹运行未来的命令,直到我们cd离开那里。

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

使用 ripgrep 或其他方法在目录中搜索 march=native。正如完整的错误消息所说,它在 ext/Makefile 中。在这个特定的 Makefile 中,有两个地方有一行 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)

修剪掉所有行中的 march=native。保存并关闭文件。现在我们要构建 gem。

gem build sassc.gemspec

这将创建 sassc-2.1.0.gem。不要尝试从这里安装它,这个目录会被覆盖。让我们将其复制到下载文件夹(或其他地方)。

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

现在导航回您在安装 sassc 时遇到问题的起始文件夹。

cd ~/work/projecty_mc_project_face

现在从您本地构建的 march=native 免费 gem 安装它

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

它应该可以工作

> 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

更新:虽然上述方法允许您捆绑安装,但任何实际使用 sassc 的代码都会引发错误:

LoadError:
  cannot load such file -- sassc

答案 1 :(得分:2)

根据 sassc-ruby 上的 this answer,这个标志对我来说是一种当前的解决方法:

gem install sassc -- --disable-march-tune-native

答案 2 :(得分:1)

这为我解决了:

bundle update sassc