【问题标题】:Error installing sassc, clang compiler does not support '-march=native', M1安装 sassc 时出错,clang 编译器不支持 '-march=native',M1
【发布时间】:2021-03-03 12:00:43
【问题描述】:

使用 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

【问题讨论】:

    标签: ruby clang apple-m1


    【解决方案1】:

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

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

    【讨论】:

    • 这对我来说适用于 sassc 版本 2.2.1。默认情况下,在 arm64 上执行此操作的 PR 是 open here
    • 也为我工作。我认为这应该被标记为正确答案。
    • 也为我工作。 M1 Pro 14,蒙特雷,2022 年 2 月
    【解决方案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
    

    【讨论】:

      【解决方案3】:

      这为我解决了:

      bundle update sassc
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-12
        • 2021-08-16
        • 2018-11-26
        • 1970-01-01
        • 1970-01-01
        • 2012-10-06
        • 2015-09-26
        • 1970-01-01
        相关资源
        最近更新 更多