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

Cannot Build on M3 #92

Open
BeatyThomas opened this issue Mar 12, 2024 · 9 comments
Open

Cannot Build on M3 #92

BeatyThomas opened this issue Mar 12, 2024 · 9 comments

Comments

@BeatyThomas
Copy link

BeatyThomas commented Mar 12, 2024

Ruby Version

ruby 2.7.2p137 (2020-10-01 revision 5445e04352)

Rails Version

5.2

Hardware

M3 (arm64-darwin23)

Posix-spawn Version

0.3.15

Issue

My company recently purchased Apple M3's. We had been using the M1's without an issue. When installing posix-spawn with gem install posix-spawn I get this output:

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

    current directory: /Users/beatythomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/posix-spawn-0.3.15/ext
/Users/beatythomas/.rbenv/versions/2.7.2/bin/ruby -I /Users/beatythomas/.rbenv/versions/2.7.2/lib/ruby/2.7.0 -r ./siteconf20240312-74649-7tb5yl.rb extconf.rb
creating Makefile

current directory: /Users/beatythomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/posix-spawn-0.3.15/ext
make "DESTDIR=" clean

current directory: /Users/beatythomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/posix-spawn-0.3.15/ext
make "DESTDIR="
compiling posix-spawn.c
posix-spawn.c:69:28: warning: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Wcompound-token-split-by-macro]
                        if      (SYM2ID(obj) == rb_intern("in"))   fd = 0;
                                                ^~~~~~~~~~~~~~~

/Users/beatythomas/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/ruby.h:1837:5: note: expanded from macro 'RUBY_CONST_ID_CACHE'
    }
    ^
posix-spawn.c:112:46: note: ')' token is here
        if (TYPE(val) != T_SYMBOL || SYM2ID(val) != rb_intern("close"))
                                                    ^~~~~~~~~~~~~~~~~~
/Users/beatythomas/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/ruby.h:1847:56: note: expanded from macro 'rb_intern'
        __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                                                       ^
posix-spawn.c:226:27: error: incompatible function pointer types passing 'int (VALUE, VALUE, posix_spawn_file_actions_t *)' (aka 'int (unsigned long, unsigned long, void **)') to parameter of type 'int (*)(VALUE, VALUE, VALUE)' (aka 'int (*)(unsigned long, unsigned long, unsigned long)') [-Wincompatible-function-pointer-types]
        rb_hash_foreach(options, posixspawn_file_actions_operations_iter, (VALUE)fops);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/beatythomas/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/intern.h:558:35: note: passing argument to parameter here
void rb_hash_foreach(VALUE, int (*)(VALUE, VALUE, VALUE), VALUE);
                                  ^
posix-spawn.c:246:46: warning: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Wcompound-token-split-by-macro]
        pgroup_val = rb_hash_delete(options, ID2SYM(rb_intern("pgroup")));
                                                    ^~~~~~~~~~~~~~~~~~~
/Users/beatythomas/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/ruby.h:1847:23: note: expanded from macro 'rb_intern'
        __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
      

[ similar warnings not repeated] 


36 warnings and 1 error generated.
make: *** [posix-spawn.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/beatythomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/posix-spawn-0.3.15 for inspection.
Results logged to /Users/beatythomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/extensions/arm64-darwin-23/2.7.0/posix-spawn-0.3.15/gem_make.out

Interestingly though, I can install it without issue using the system ruby:

ruby -v ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]

Any ideas?

@BeatyThomas
Copy link
Author

was able to force it to install with:

gem install posix-spawn -- --with-cflags="-Wno-incompatible-function-pointer-types"

@caseyandgina
Copy link

I don't think this has anything to do with M3 versus M1. It is more likely due to some MacOS update that affects clang?

I've been bashing my head against this problem for many hours, just trying to build the gem on the same computer I had previously built it on. Like you, I found that I could build it with the system-provided Ruby, but no versions that I had installed with rbenv, from 2.7.2 through 3.3.0. The command in your last comment worked for me though!

I have also found 3 other gems that hit this same problem. In some cases, a newer version of those gems did work, so I guess that those gems have done some code change to work around this.

@caseyandgina
Copy link

As an example, nio4r 2.5.7 fails to build with the same error. Your workaround works for this specific version, but is not required for the current version (2.7.0).

@caseyandgina
Copy link

caseyandgina commented Mar 13, 2024

Ohhh, one other note - the output in your paste is one of the 36 warnings, not the 1 error. Those are suppressed in a later Ruby 2.7 version than 2.7.2. This is a relevant link about that: https://bugs.ruby-lang.org/issues/17865. I'm not sure which, but I ran into the same thing with 2.7.2 and switched to 2.7.8 to simplify the output. Here's that error:

$ gem install posix-spawn
Fetching posix-spawn-0.3.15.gem
Building native extensions. This could take a while...
ERROR:  Error installing posix-spawn:
	ERROR: Failed to build gem native extension.

    current directory: /Users/casey/.rbenv/versions/2.7.8/lib/ruby/gems/2.7.0/gems/posix-spawn-0.3.15/ext
/Users/casey/.rbenv/versions/2.7.8/bin/ruby -I /Users/casey/.rbenv/versions/2.7.8/lib/ruby/2.7.0 -r ./siteconf20240312-77190-b1ef1v.rb extconf.rb
creating Makefile

current directory: /Users/casey/.rbenv/versions/2.7.8/lib/ruby/gems/2.7.0/gems/posix-spawn-0.3.15/ext
make "DESTDIR=" clean

current directory: /Users/casey/.rbenv/versions/2.7.8/lib/ruby/gems/2.7.0/gems/posix-spawn-0.3.15/ext
make "DESTDIR="
compiling posix-spawn.c
posix-spawn.c:226:27: error: incompatible function pointer types passing 'int (VALUE, VALUE, posix_spawn_file_actions_t *)' (aka 'int (unsigned long, unsigned long, void **)') to parameter of type 'int (*)(VALUE, VALUE, VALUE)' (aka 'int (*)(unsigned long, unsigned long, unsigned long)') [-Wincompatible-function-pointer-types]
        rb_hash_foreach(options, posixspawn_file_actions_operations_iter, (VALUE)fops);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/casey/.rbenv/versions/2.7.8/include/ruby-2.7.0/ruby/intern.h:558:35: note: passing argument to parameter here
void rb_hash_foreach(VALUE, int (*)(VALUE, VALUE, VALUE), VALUE);
                                  ^
1 error generated.
make: *** [posix-spawn.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/casey/.rbenv/versions/2.7.8/lib/ruby/gems/2.7.0/gems/posix-spawn-0.3.15 for inspection.
Results logged to /Users/casey/.rbenv/versions/2.7.8/lib/ruby/gems/2.7.0/extensions/arm64-darwin-23/2.7.0/posix-spawn-0.3.15/gem_make.out

@caseyandgina
Copy link

This also appears to work if you're using Bundler to install the gem:
bundle config build.posix-spawn --with-cflags="-Wno-incompatible-function-pointer-types"

@anonoz
Copy link

anonoz commented Mar 14, 2024

was able to force it to install with:

gem install posix-spawn -- --with-cflags="-Wno-incompatible-function-pointer-types"

A bunch of gems are failing on M2 too, this flag is usable for similar errors. Thanks a bunch!

@dmitrypol
Copy link

I have the same problem on:

2.6 GHz 6-Core Intel Core i7
Mac OS Sonoma 14.3.1 (23D60)

THANK YOU for the fix.

@LorenzoBettini
Copy link

was able to force it to install with:

gem install posix-spawn -- --with-cflags="-Wno-incompatible-function-pointer-types"

In my case, it still gives compilation error and then it says:

At top level:
cc1: note: unrecognized command-line option ‘-Wno-incompatible-function-pointer-types’ may have been intended to silence earlier diagnostics

@jvdmr
Copy link

jvdmr commented May 29, 2024

Having this same issue on an M1 Macbook Pro running Sonoma 14.5, using rbenv with both 2.7.x and 3.3.x, so I agree it's probably related to a macOS software update and not hardware related.

Workaround with the -Wno-incompatible-function-pointer-typesflag works for me too, thanks for that tip!

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

No branches or pull requests

6 participants