puma: ctype.h missing from puma_http11.c

Describe the bug

#include <ctype.h> needs to be added to ext/puma_http11/puma_http11.c. Without this include compilation of Puma will fail due to error:

include the header <ctype.h> or explicitly provide a declaration for 'isspace' 
1 error generated.

This seems to be fixed on 5.0.0.beta1 although it won’t help since beta doesn’t behave nicely and cannot be used in production.

To Reproduce Just try to compile puma.

Expected behavior Succesfully compiled Puma would be expected behaviour 😃

Desktop (please complete the following information): MacOS 15.5.5 and MacOS Big Sur Puma version 4.3.5

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 23
  • Comments: 25 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Until fixed by ctype and/or Apple default parameters, it’s workaround by setting the -Wno-error flag for gcc in puma’s bundler config.

$ bundle config build.puma --with-cflags="-Wno-error=implicit-function-declaration"

Or just install 4.3.5 with the flags:

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

I’m also seeing the same issue in macOS 10.15.6 in a new rails app when trying to install puma 4.3.5 I can install puma v 4.2 without any issues but I had to use @frederikspang’s suggestion above (gem install puma:4.3.5 -- --with-cflags="-Wno-error=implicit-function-declaration") to install v 4.3.5 successfully.

Fixed on master and 4.3.6.

For latest version of OSX:

gem install puma -v '4.3.5' -- --with-opt-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include

Or just upgrade gem to

gem 'puma', '~> 5.0'

Would it be bad to include ctype.h anyway? And also important to note: I can reproduce this with MacOS 15.5.5 which is Catalina, not Big Sur.

For puma 6, this helped:

export PUMA_DISABLE_SSL=1

Seeing this is reported for the new macOS version, Big Sur, it is probably related to something that changed in macOS.

I found a few similar issues when I started searching:

The paragraph that these issues all quote…

New in macOS Big Sur 11 beta, the system ships with a built-in dynamic linker cache of all system-provided libraries. As part of this change, copies of dynamic libraries are no longer present on the filesystem. Code that attempts to check for dynamic library presence by looking for a file at a path or enumerating a directory will fail. Instead, check for library presence by attempting to dlopen() the path, which will correctly check for the library in the cache. (62986286)

…is listed under a headline “Known Issues” at https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes, so it might even get fixed, making it work to compile Puma 4.3.5 in Big Sur.

I think this issue can be closed without action. If it persist when Big Sur is out of beta, maybe we can reconsider.

I don’t think it’s the linker cache. Clang now enables -Werror=implicit-function-declaration by default:

Clang now reports an error when you use a function without an explicit declaration when building C or Objective-C code for macOS (-Werror=implicit-function-declaration flag is on). This additional error detection unifies Clang’s behavior for iOS/tvOS and macOS 64-bit targets for this diagnostic. (49917738)

Apple could back out of this particular change, but even if they do, it’s probably a good idea not to rely on the implicit function declaration anyway.

Went to open a PR and realized this is already fixed in master because isspace is no longer used.

v4.3.4
puma_http11 ((v4.3.4)) $ ruby 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
puma_http11 ((v4.3.4)) $ make
compiling http11_parser.c
compiling io_buffer.c
compiling mini_ssl.c
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
master
puma_http11 (master) $ ruby 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
puma_http11 (master) $ make
compiling http11_parser.c
compiling mini_ssl.c
compiling puma_http11.c
linking shared-object puma/puma_http11.bundle
puma_http11 (master) $ 

There doesn’t seem to be a stable branch for the 4.3.x line so I’m not sure if master is targeting 4.x or 5.0.

Now the implicit-function-declaration is breaking things, when you install puma with the correct gem install puma -- --with-cppflags=-I/usr/local/opt/openssl/include and then try to install it with bundle install it will fail because you might have added the implicit-function-declaration to bundle which would have added it here: ~/.bundle/config if you remove the following line and re run bundle install puma will compile correctly

BUNDLE_BUILD__PUMA: "--with-cflags=-Wno-error=implicit-function-declaration"

If you have openssl 3 installed with brew just install puma with the path like this:

replace the version that bundle install was trying to install

gem install puma:5.6.2 -- --with-cppflags=-I/usr/local/opt/openssl/include

@frederikspang’s solution is working well with my issue, thank you so much.