Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctype.h missing from puma_http11.c #2304

Closed
mpeltomaa opened this issue Jul 3, 2020 · 22 comments
Closed

ctype.h missing from puma_http11.c #2304

mpeltomaa opened this issue Jul 3, 2020 · 22 comments
Labels

Comments

@mpeltomaa
Copy link

mpeltomaa commented Jul 3, 2020

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

@RyanMorash
Copy link

RyanMorash commented Jul 6, 2020

The following is what I get when trying to install Puma 4.3.5 in Ruby 2.7.1 under rbenv with RubyGems 3.1.2 on MacOS Big Sur 10.16

% sudo gem install puma           
Building native extensions. This could take a while...
ERROR:  Error installing puma:
	ERROR: Failed to build gem native extension.

    current directory: /Users/ryanmorash/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.5/ext/puma_http11
/Users/ryanmorash/.rbenv/versions/2.7.1/bin/ruby -I /Users/ryanmorash/.rbenv/versions/2.7.1/lib/ruby/2.7.0 -r ./siteconf20200705-62350-nsgo9p.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/ryanmorash/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.5/ext/puma_http11
make "DESTDIR=" clean

current directory: /Users/ryanmorash/.rbenv/versions/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

@mpeltomaa
Copy link
Author

mpeltomaa commented Jul 6, 2020

And unused variables, those could be cleaned up as well? I didn't notice use any of mentioned variables above.

@georgeclaghorn
Copy link

georgeclaghorn commented Jul 8, 2020

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  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.

@mpeltomaa
Copy link
Author

mpeltomaa commented Jul 8, 2020

Master seems to be 5.0.0.beta1.

@dentarg
Copy link
Member

dentarg commented Jul 9, 2020

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

The use of isspace is still there in the master branch

while (vlen > 0 && isspace(value[vlen - 1])) vlen--;

Or am I missing something?

@dentarg
Copy link
Member

dentarg commented Jul 9, 2020

Ah, 22b135a added the use of isspace but #include <ctype.h> was added in befe00a which is only in master and v5.0.0.beta1.

@dentarg
Copy link
Member

dentarg commented Jul 9, 2020

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.

@mpeltomaa
Copy link
Author

mpeltomaa commented Jul 9, 2020

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.

@georgeclaghorn
Copy link

georgeclaghorn commented Jul 10, 2020

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.

@georgeclaghorn
Copy link

georgeclaghorn commented Jul 10, 2020

The use of isspace is still there in the master branch

Or am I missing something?

Whoops, yes, I looked in the wrong file. 🤦‍♂️

@mpeltomaa
Copy link
Author

mpeltomaa commented Jul 10, 2020

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.

I think they won't back out on this. I might be quite much wrong here, but this was changed on newer C standards some time ago and gcc for example gave just warning not error on these cases - or do i remember totally wrong?

@frederikspang
Copy link

frederikspang commented Jul 27, 2020

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"

@adampal
Copy link

adampal commented Jul 30, 2020

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.

@tri-dang
Copy link

tri-dang commented Aug 4, 2020

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

@chinomnsoawazie
Copy link

chinomnsoawazie commented Aug 19, 2020

@frederikspang solution just worked for me

@nateberkopec
Copy link
Member

nateberkopec commented Sep 5, 2020

Fixed on master and 4.3.6.

@CR1AT0RS
Copy link

CR1AT0RS commented Sep 27, 2020

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'

tamouse added a commit to GratefulGarmentProject/StockAid that referenced this issue Oct 19, 2020
Addresses: [737](#737)

According to [Issue #2304](puma/puma#2304) at puma/puma, the `ctype.h` header file was no being included.

This has been fixed at version 4.3.6.

**Modifications:**

- change Gemfile to specify at least version 4.3.6 for puma
@yudechen0820
Copy link

yudechen0820 commented Nov 6, 2020

Thank you, @CR1AT0RS! 👍

rsanheim added a commit to simpledotorg/simple-server that referenced this issue Nov 19, 2020
There was a bug on Puma version 4.3.5, causing it to fail when trying to
compile. It was fixed with [#2304].

This commit updates Gemfile.lock and removes the now redundant
explanations on readme.

[#2304]: puma/puma#2304

Co-authored-by: Rob Sanheim <rsanheim@gmail.com>
ericboehs added a commit to department-of-veterans-affairs/vets-api that referenced this issue Dec 1, 2020
There's [a bug in Puma 4.3.5](puma/puma#2304)
which prevents some compilers from building the native extensions
required for Puma.

I was running into this issue on macOS Big Sur. Updating fixed it.
ericboehs added a commit to department-of-veterans-affairs/vets-api that referenced this issue Dec 4, 2020
There's [a bug in Puma 4.3.5](puma/puma#2304)
which prevents some compilers from building the native extensions
required for Puma.

I was running into this issue on macOS Big Sur. Updating fixed it.
caius added a commit to caius/zshrc that referenced this issue Dec 15, 2020
@Shtokhman
Copy link

Shtokhman commented Dec 23, 2020

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"

It worked earlier, but after removing and setting up the project from scratch does not work now
Trying to install puma 2.11.3 on Big Sur 11.1
Any ideas?

@dentarg
Copy link
Member

dentarg commented Dec 23, 2020

@Shtokhman
Copy link

Shtokhman commented Dec 23, 2020

Trying to install puma 2.11.3 on Big Sur 11.1
Not a battle I would fight 😆 (Is using docker an option?)

The most painful is the fact it worked a day ago
Docker as the last option I guess

gabebw added a commit to hotline-webring/hotline-webring that referenced this issue Jan 11, 2021
machupicchubeta added a commit to machupicchubeta/dotfiles that referenced this issue Jan 14, 2021
russell added a commit to zendesk/samson that referenced this issue Jan 25, 2021
Older versions of puma don't work on newer versions of OSX
puma/puma#2304

I had to bump this gem to get `bundle install` to work
russell added a commit to zendesk/samson that referenced this issue Jan 27, 2021
* Update puma

Older versions of puma don't work on newer versions of OSX
puma/puma#2304

I had to bump this gem to get `bundle install` to work

* Update Gemfile

Co-authored-by: Michael Grosser <michael@grosser.it>

Co-authored-by: Michael Grosser <michael@grosser.it>
dunn added a commit to dunn/mastodon-twitter-poster that referenced this issue Mar 26, 2021
@iseth
Copy link

iseth commented Feb 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests