Thin and Puma fail with similar issues - ERROR: Failed to build gem native extension on Mac with OpenSSL@1.1

Thin and Puma fail with similar issues - ERROR: Failed to build gem native extension on Mac with OpenSSL@1.1

描述错误 我尝试执行 gem install pumagem install thin 并得到一个错误。

我正在设置一个全新的 Mac:MacOS Catalina 10.15.6 (19G73)

我发现任何 <= 4.2.1 的版本在我的电脑上都可以正常工作 我正在使用 asdf 版本管理器

Puma 错误

我已经尝试了这些命令中的每一个来让它工作

gem install puma

gem install puma -v '4.3.0'  --  --with-ldflags=-L/usr/local/opt/openssl@1.1/lib  --with-cppflags=-I/usr/local/opt/openssl@1.1/include

gem install puma -v '4.3.0'  --  --with-ldflags=-L/usr/local/opt/openssl@1.1/lib  --with-cppflags=-I/usr/local/opt/openssl@1.1/include --with-opt-dir=/usr/local/opt/openssl@1.1
Building native extensions. This could take a while...
ERROR:  Error installing puma:
    ERROR: Failed to build gem native extension.

    current directory: /Users/myname/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.5/ext/puma_http11
/Users/myname/.asdf/installs/ruby/2.7.1/bin/ruby -I /Users/myname/.asdf/installs/ruby/2.7.1/lib/ruby/site_ruby/2.7.0 -r ./siteconf20200806-17963-1cqtelz.rb extconf.rb
checking for BIO_read() in -lcrypto... yes
checking for SSL_CTX_new() in -lssl... yes
checking for openssl/bio.h... yes
checking for DTLS_method() in openssl/ssl.h... yes
checking for TLS_server_method() in openssl/ssl.h... yes
checking for SSL_CTX_set_min_proto_version in openssl/ssl.h... yes
creating Makefile

current directory: /Users/myname/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.5/ext/puma_http11
make "DESTDIR=" clean

current directory: /Users/myname/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.5/ext/puma_http11
make "DESTDIR="
compiling http11_parser.c
ext/puma_http11/http11_parser.c:44:18: warning: unused variable 'puma_parser_en_main' [-Wunused-const-variable]
static const int puma_parser_en_main = 1;
                 ^
1 warning generated.
compiling io_buffer.c
compiling mini_ssl.c
mini_ssl.c:145:7: warning: unused variable 'min' [-Wunused-variable]
  int min, ssl_options;
      ^
mini_ssl.c:299:40: warning: function 'raise_error' could be declared with attribute 'noreturn' [-Wmissing-noreturn]
void raise_error(SSL* ssl, int result) {
                                       ^
2 warnings generated.
compiling puma_http11.c
puma_http11.c:203:22: error: implicitly declaring library function 'isspace' with type 'int (int)' [-Werror,-Wimplicit-function-declaration]
  while (vlen > 0 && isspace(value[vlen - 1])) vlen--;
                     ^
puma_http11.c:203:22: note: include the header <ctype.h> or explicitly provide a declaration for 'isspace'
1 error generated.
make: *** [puma_http11.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/myname/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.5 for inspection.
Results logged to /Users/myname/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-19/2.7.0/puma-4.3.5/gem_make.out

我在这个 thread 上看到您需要 OpenSSL 1.1

OpenSSL@1.1

我重新安装了openssl

brew reinstall openssl@1.1

==> Downloading https://homebrew.bintray.com/bottles/openssl%401.1-1.1.1g.catalina.bottle.tar.gz
Already downloaded: /Users/myname/Library/Caches/Homebrew/downloads/d6b7a6d80c588c89e79f350ce3e05c95d31d804291cc120efcbb6c9478607a41--openssl@1.1-1.1.1g.catalina.bottle.tar.gz
==> Reinstalling openssl@1.1
==> Pouring openssl@1.1-1.1.1g.catalina.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

我在 .zshrc

中使用这些行进行了测试
export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

精简版安装

gem install thin

Building native extensions. This could take a while...
ERROR:  Error installing thin:
    ERROR: Failed to build gem native extension.

    current directory: /Users/myname/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/thin-1.7.2/ext/thin_parser
/Users/myname/.asdf/installs/ruby/2.7.1/bin/ruby -I /Users/myname/.asdf/installs/ruby/2.7.1/lib/ruby/site_ruby/2.7.0 -r ./siteconf20200806-18426-1lt7u04.rb extconf.rb
checking for main() in -lc... yes
creating Makefile

current directory: /Users/myname/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/thin-1.7.2/ext/thin_parser
make "DESTDIR=" clean

current directory: /Users/myname/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/thin-1.7.2/ext/thin_parser
make "DESTDIR="
compiling parser.c
parser.c:31:18: warning: unused variable 'http_parser_en_main' [-Wunused-const-variable]
static const int http_parser_en_main = 1;
                 ^
1 warning generated.
compiling thin.c
thin.c:242:3: error: implicit declaration of function 'thin_http_parser_init' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  thin_http_parser_init(hp);
  ^
thin.c:242:3: note: did you mean 'http_parser_init'?
./parser.h:41:5: note: 'http_parser_init' declared here
int http_parser_init(http_parser *parser);
    ^
thin.c:260:3: error: implicit declaration of function 'thin_http_parser_init' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  thin_http_parser_init(http);
  ^
thin.c:277:3: error: implicit declaration of function 'thin_http_parser_init' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  thin_http_parser_init(http);
  ^
thin.c:294:3: error: implicit declaration of function 'thin_http_parser_finish' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  thin_http_parser_finish(http);
  ^
thin.c:294:3: note: did you mean 'Thin_HttpParser_finish'?
thin.c:290:7: note: 'Thin_HttpParser_finish' declared here
VALUE Thin_HttpParser_finish(VALUE self)
      ^
thin.c:296:10: error: implicit declaration of function 'thin_http_parser_is_finished' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  return thin_http_parser_is_finished(http) ? Qtrue : Qfalse;
         ^
thin.c:334:5: error: implicit declaration of function 'thin_http_parser_execute' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    thin_http_parser_execute(http, dptr, dlen, from);
    ^
thin.c:334:5: note: did you mean 'Thin_HttpParser_execute'?
thin.c:317:7: note: 'Thin_HttpParser_execute' declared here
VALUE Thin_HttpParser_execute(VALUE self, VALUE req_hash, VALUE data, VALUE start)
      ^
thin.c:338:8: error: implicit declaration of function 'thin_http_parser_has_error' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if(thin_http_parser_has_error(http)) {
       ^
thin.c:338:8: note: did you mean 'http_parser_has_error'?
./parser.h:44:5: note: 'http_parser_has_error' declared here
int http_parser_has_error(http_parser *parser);
    ^
thin.c:359:10: error: implicit declaration of function 'thin_http_parser_has_error' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  return thin_http_parser_has_error(http) ? Qtrue : Qfalse;
         ^
thin.c:374:10: error: implicit declaration of function 'thin_http_parser_is_finished' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  return thin_http_parser_is_finished(http) ? Qtrue : Qfalse;
         ^
9 errors generated.
make: *** [thin.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/myname/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/thin-1.7.2 for inspection.
Results logged to /Users/myname/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-19/2.7.0/thin-1.7.2/gem_make.out

Puma 团队向我指出了 temporary solution 用于编译 puma。

gem install puma:4.3.5 -- --with-cflags="-Wno-error=implicit-function-declaration"

我在最新版本中使用了这个变体

gem install puma -- --with-cflags="-Wno-error=implicit-function-declaration"

我也可以使用同样的技术来瘦身,但我没有测试 gem 是否有效。

gem install thin -- --with-cflags="-Wno-error=implicit-function-declaration"
bundle config build.thin --with-cflags="-Wno-error=implicit-function-declaration"

已打开 https://github.com/macournoyer/thin/issues/370 以修复或记录在薄文件中