LoginSignup
7
3

More than 1 year has passed since last update.

【Rails】sasscをインストール出来なかった備忘録

Posted at

環境

・M1
・ruby 2.6.5

エラー内容

アプリの環境構築で、bundle installを実行したい際に、gem sasscががインストール出来ないと出た。

ターミナル.
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/Users/user/workspace/5890_58784_runteq_curriculum_advanced/vendor/bundle/ruby/2.6.0/gems/sassc-2.2.1/ext
/Users/user/.rbenv/versions/2.6.5/bin/ruby -I /Users/user/.rbenv/versions/2.6.5/lib/ruby/2.6.0 -r
./siteconf20220205-67436-1hdyypl.rb extconf.rb
creating Makefile

current directory: /Users/user/workspace/5890_58784_runteq_curriculum_advanced/vendor/bundle/ruby/2.6.0/gems/sassc-2.2.1/ext
make "DESTDIR=" clean

current directory: /Users/user/workspace/5890_58784_runteq_curriculum_advanced/vendor/bundle/ruby/2.6.0/gems/sassc-2.2.1/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

--省略ーー

An error occurred while installing sassc (2.2.1), and Bundler cannot continue.

In Gemfile:
  bootstrap-sass was resolved to 3.4.1, which depends on
    sassc

エラー箇所は下記の場所で、M1macでは非対応らしい。
clang: error: the clang compiler does not support '-march=native'

clang compiler'-march=native'をサポートしていないと出ているので、こいつを無視するように設定したら、インストールがうまく行く。

$ bundle config set --local build.sassc -- --disable-march-tune-native
You are replacing the current local value of build.sassc, which is currently "--use-system-libraries"

bundle config
Bundlerの設定システムと対話を出来るもの。
Bundlerは設定を、下記の優先順位に従って取得する。

1.ローカルのアプリケーション(app/.bundle/config)
2.環境変数
3.ユーザーのホームディレクトリ(~/.bundle/config)

local
--localオプションをつけることで、ホームディレクトリ下ではなくプロジェクト単位の設定ファイルに設定を付与することができる。

--disable-march-tune-native
disable → 無効にする
-march-tune-native'-march=native'のことを指していそう。

余談:bundle configの使い方

現在バンドルされているの全てのBundler設定と、 どこにそれが設定されたのかを示す一覧を出力する。

$ bundle config

Settings are listed in order of priority. The top value will be used.
build.sassc
Set for your local app (xxxxxxx): "--disable-march-tune-native"
Set for the current user (/Users/user/.bundle/config): "--disable-march-tune-native"

path
Set for your local app (xxxxxxx): "vendor/bundle"

sassc
Set for your local app (xxxxxxx): "-v 2.2.1 --use-system-libraries"

全bundleの設定を行う。現在のユーザーとして実行される全てのbundleの設定に対して、値を指定する。設定は、~/.bundle/config内に格納される。

$ bundle config [name] [value]

# 上記と同様の動作
$ bundle config --global [name] [value]

# ローカルで行う場合↓
$ bundle config --local [name] [value]

bundleの設定を削除。

$ bundle config --delete [name]

ビルドオプション

bundlerへフラグを指定することで、特定のGemのインストールを行う度に、そのフラグをgemインストーラーに渡すことが出来る。
一般的なGemであるmysqlの例いうと、 Snow Leopard(Mac OSXの)ユーザーは、mysql_configの実行ファイルが見つけられる場所を、 設定フラグとしてgem installに渡す必要がある。

# mysqlのGemのインストールをする際にフラグを渡す
$ gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

# このコマンド実行以降、渡したフラグに沿ってGemのインストールを実行する
$ bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

参考記事

Build Options
Bundlerでビルドオプションを指定する
bundle configは使えるコマンド

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3