LoginSignup
4
2

More than 1 year has passed since last update.

Ruby3.1.0のbundle installでpuma5.5.2がダウンロードできなかった時

Posted at

環境

  • macOS 12.1 (Monteray)
  • ruby 3.1.0p0 (2021-12-25 revision fb4df44d16)[arm64-darwin21]
  • Rails 7.0.1
  • Apple clang version 13.0.0 (clang-1300.0.29.30)

要約

bundle config build.puma CC="clang -fdeclspec"

でbundle installの実行時にオプションを渡して

bundle install

を実行。

出ていたエラーメッセージなど

Rails7.0.1でrails newした後Gemを入れようとしてbundle installを実行するとこんな感じのエラーが発生しました。(一部省略)

current directory:
/rails/rails7-try/vendor/bundle/ruby/3.1.0/gems/puma-5.5.2/ext/puma_http11
/.anyenv/envs/rbenv/versions/3.1.0/bin/ruby -I
/.anyenv/envs/rbenv/versions/3.1.0/lib/ruby/3.1.0
-r ./siteconf20220111-40100-3sw1db.rb extconf.rb
--with-cflags\=-Wno-error\=implicit-function-declaration
checking for BIO_read() in -lcrypto... *** extconf.rb failed
***
Could not create Makefile due to some reason, probably lack of
necessary
libraries and/or headers.  Check the mkmf.log file for more
details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
/.anyenv/envs/rbenv/versions/3.1.0/bin/$(RUBY_BASE_NAME)
    --with-puma_http11-dir
    --without-puma_http11-dir
    --with-puma_http11-include
    --without-puma_http11-include=${puma_http11-dir}/include
    --with-puma_http11-lib
    --without-puma_http11-lib=${puma_http11-dir}/lib
    --with-openssl-dir
    --with-openssl-include
    --without-openssl-include=${openssl-dir}/include
    --with-openssl-lib
    --without-openssl-lib=${openssl-dir}/lib
    --with-openssl-config
    --without-openssl-config
    --with-pkg-config
    --without-pkg-config
    --with-crypto-dir
    --without-crypto-dir
    --with-crypto-include
    --without-crypto-include=${crypto-dir}/include
    --with-crypto-lib
    --without-crypto-lib=${crypto-dir}/lib
    --with-cryptolib
    --without-cryptolib
/.anyenv/envs/rbenv/versions/3.1.0/lib/ruby/3.1.0/mkmf.rb:498:in
`try_do': The compiler failed to generate an executable file.
(RuntimeError)
You have to install development tools first.

To see why this extension failed to compile, please check the
mkmf.log which can be found here:

/rails/rails7-try/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-21/3.1.0/puma-5.5.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/rails/rails7-try/vendor/bundle/ruby/3.1.0/gems/puma-5.5.2
for inspection.
Results logged to
/rails/rails7-try/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-21/3.1.0/puma-5.5.2/gem_make.out

An error occurred while installing puma (5.5.2), and
Bundler cannot continue.

In Gemfile:
  puma

ログを見ろと言っているのでログを見ているとこんな感じ(一部省略)になっており、どうやらパラメータを渡せとのこと。

/.anyenv/envs/rbenv/versions/3.1.0/include/ruby-3.1.0/ruby/assert.h:132:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
^
/.anyenv/envs/rbenv/versions/3.1.0/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

どういうふうに渡せば良いのかわからないので調べていると下記の記事を発見したので参考にさせて頂きました。

ただbundle install時に渡したかったので

bundle config build.puma CC="clang -fdeclspec"

を実行してホームディレクトリ配下の.bundle/configに値をセット。

ファイルを見ると

BUNDLE_BUILD__PUMA: "CC=clang -fdeclspec"

と追加されているのがわかります。

この状態で

bundle install

を実行すると問題なくインストールできました。

意外とハマったので共有します。

4
2
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
4
2