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
Builds incompatible code on MacOS M1 / arm64 architecture #231
Comments
Could you share a sample project that reproduces this? |
https://github.com/tilo/smarter_csv $ file `which ruby `
.rvm/rubies/ruby-3.1.4/bin/ruby: Mach-O 64-bit executable arm64 whereas when the Ruby executable is x86_64 it is not an issue: $ file `which ruby `
.rvm/rubies/ruby-3.0.0/bin/ruby: Mach-O 64-bit executable x86_64 Is there a way to tell the compiler to use This does not seem to work: $ find . -type f -name smarter_csv.bundle -exec rm {} \;
$ export ARCHFLAGS='-arch arm64'
$ rake compile
$ file ./lib/smarter_csv/smarter_csv.bundle
./lib/smarter_csv/smarter_csv.bundle: Mach-O 64-bit bundle x86_64 |
I couldn't reproduce this with Homebrew's Ruby: $ PATH=$(brew --prefix ruby)/bin:$PATH ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
$ PATH=$(brew --prefix ruby)/bin:$PATH ruby -S rake compile
mkdir -p tmp/arm64-darwin22/smarter_csv/3.2.2
cd tmp/arm64-darwin22/smarter_csv/3.2.2
/opt/homebrew/opt/ruby/bin/ruby -I. ../../../../ext/smarter_csv/extconf.rb
creating Makefile
cd -
cd tmp/arm64-darwin22/smarter_csv/3.2.2
/usr/bin/make
compiling ../../../../ext/smarter_csv/smarter_csv.c
../../../../ext/smarter_csv/smarter_csv.c:42:8: warning: variable 'prev_char' set but not used [-Wunused-but-set-variable]
char prev_char = '\0'; // Store the previous character for comparison against an escape character
^
1 warning generated.
linking shared-object smarter_csv/smarter_csv.bundle
ld: warning: -multiply_defined is obsolete
ld: warning: ignoring duplicate libraries: '-lruby.3.2'
cd -
mkdir -p tmp/arm64-darwin22/stage/lib/smarter_csv
/usr/bin/make install sitearchdir=../../../../lib/smarter_csv sitelibdir=../../../../lib/smarter_csv target_prefix=
/usr/bin/install -c -m 0755 smarter_csv.bundle ../../../../lib/smarter_csv
cp tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.bundle tmp/arm64-darwin22/stage/lib/smarter_csv/smarter_csv.bundle
$ file tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.bundle
tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.bundle: Mach-O 64-bit bundle arm64 Could you show full command line outputs like the above on your environment? |
lapcat:smarter_csv tilo$ PATH=$(brew --prefix ruby)/bin:$PATH ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin23]
lapcat:smarter_csv tilo$ PATH=$(brew --prefix ruby)/bin:$PATH ruby -S rake compile
/usr/local/bin/gmake install sitearchdir=../../../../lib/smarter_csv sitelibdir=../../../../lib/smarter_csv target_prefix=
/opt/homebrew/opt/coreutils/bin/ginstall -c -m 0755 smarter_csv.bundle ../../../../lib/smarter_csv
cp tmp/arm64-darwin23/smarter_csv/3.2.2/smarter_csv.bundle tmp/arm64-darwin23/stage/lib/smarter_csv/smarter_csv.bundle
file tmp/arm64-darwin23/stage/lib/smarter_csv/smarter_csv.bundle
tmp/arm64-darwin23/stage/lib/smarter_csv/smarter_csv.bundle: Mach-O 64-bit bundle x86_64 😭
-------
but I'm not using Ruby from homebrew, but RVM:
lapcat:smarter_csv tilo$ which ruby
/Users/tilo/.rvm/rubies/ruby-3.2.2/bin/ruby
lapcat:smarter_csv tilo$ file /Users/tilo/.rvm/rubies/ruby-3.2.2/bin/ruby
/Users/tilo/.rvm/rubies/ruby-3.2.2/bin/ruby: Mach-O 64-bit executable arm64
lapcat:smarter_csv tilo$ ruby -S rake compile
/usr/local/bin/gmake install sitearchdir=../../../../lib/smarter_csv sitelibdir=../../../../lib/smarter_csv target_prefix=
/opt/homebrew/opt/coreutils/bin/ginstall -c -m 0755 smarter_csv.bundle ../../../../lib/smarter_csv
cp tmp/arm64-darwin23/smarter_csv/3.2.2/smarter_csv.bundle tmp/arm64-darwin23/stage/lib/smarter_csv/smarter_csv.bundle
lapcat:smarter_csv tilo$ file tmp/arm64-darwin23/smarter_csv/3.2.2/smarter_csv.bundle
tmp/arm64-darwin23/smarter_csv/3.2.2/smarter_csv.bundle: Mach-O 64-bit bundle x86_64
------
lapcat:smarter_csv tilo$ mkdir -p tmp/arm64-darwin22/smarter_csv/3.2.2
lapcat:smarter_csv tilo$ cd tmp/arm64-darwin22/smarter_csv/3.2.2
lapcat:3.2.2 tilo$ which ruby
/Users/tilo/.rvm/rubies/ruby-3.2.2/bin/ruby
lapcat:3.2.2 tilo$ ruby -I. ../../../../ext/smarter_csv/extconf.rb
creating Makefile
-> this Makefile has `arch = arm64-darwin23` in it
cd -
cd tmp/arm64-darwin22/smarter_csv/3.2.2
lapcat:3.2.2 tilo$ /usr/bin/make
compiling ../../../../ext/smarter_csv/smarter_csv.c
../../../../ext/smarter_csv/smarter_csv.c:42:8: warning: variable 'prev_char' set but not used [-Wunused-but-set-variable]
char prev_char = '\0'; // Store the previous character for comparison against an escape character
^
1 warning generated.
linking shared-object smarter_csv/smarter_csv.bundle
ld: warning: ignoring duplicate libraries: '-lruby.3.2'
$ file smarter_csv.bundle
smarter_csv.bundle: Mach-O 64-bit bundle arm64 🎉
cd -
mkdir -p tmp/arm64-darwin22/stage/lib/smarter_csv
lapcat:smarter_csv tilo$ file tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.o
tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.o: Mach-O 64-bit object arm64
lapcat:smarter_csv tilo$ file tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.bundle
tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.bundle: Mach-O 64-bit bundle arm64
/usr/bin/make install sitearchdir=../../../../lib/smarter_csv sitelibdir=../../../../lib/smarter_csv target_prefix=
/usr/bin/install -c -m 0755 smarter_csv.bundle ../../../../lib/smarter_csv
invalid option -- c
$ /usr/bin/make install sitearchdir=../../../../lib/smarter_csv sitelibdir=../../../../lib/smarter_csv target_prefix=/usr/bin/install -m 0755 smarter_csv.bundle ../../../../lib/smarter_csv
make: *** No rule to make target `install'. Stop.
lapcat:smarter_csv tilo$ cp tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.bundle tmp/arm64-darwin22/stage/lib/smarter_csv/smarter_csv.bundle
lapcat:smarter_csv tilo$ file tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.bundle
tmp/arm64-darwin22/smarter_csv/3.2.2/smarter_csv.bundle: Mach-O 64-bit bundle arm64
$ grep rake-compiler Gemfile.lock
rake-compiler (1.2.5) |
Is this a RVM problem? |
I'm not sure how.. this is what I get from the RVM Ruby: lapcat:smarter_csv tilo$ which ruby
/Users/tilo/.rvm/rubies/ruby-3.2.2/bin/ruby
lapcat:smarter_csv tilo$ file /Users/tilo/.rvm/rubies/ruby-3.2.2/bin/ruby
/Users/tilo/.rvm/rubies/ruby-3.2.2/bin/ruby: Mach-O 64-bit executable arm64
lapcat:smarter_csv tilo$ ruby -S rake compile
/usr/local/bin/gmake install sitearchdir=../../../../lib/smarter_csv sitelibdir=../../../../lib/smarter_csv target_prefix=
/opt/homebrew/opt/coreutils/bin/ginstall -c -m 0755 smarter_csv.bundle ../../../../lib/smarter_csv
cp tmp/arm64-darwin23/smarter_csv/3.2.2/smarter_csv.bundle tmp/arm64-darwin23/stage/lib/smarter_csv/smarter_csv.bundle
lapcat:smarter_csv tilo$ file tmp/arm64-darwin23/smarter_csv/3.2.2/smarter_csv.bundle
tmp/arm64-darwin23/smarter_csv/3.2.2/smarter_csv.bundle: Mach-O 64-bit bundle x86_64 |
Could you run |
same
and after compilation:
😮 but
😮 |
Could you attach |
yes!
|
Could you show |
I was just looking at the same thing
|
|
Hmm... I don't know why... Could you try |
bizarre... what would override the architecture? |
$ cd tmp/arm64-darwin23/smarter_csv/3.2.2
$ /usr/local/bin/gmake clean
$ /usr/local/bin/gmake V=1 |
😮 |
how did it decide that? |
Could you try the following?
|
lapcat:smarter_csv tilo$ echo 'int add(int x, int y) {return x + y;}' > a.c && gcc -I. -I/Users/tilo/.rvm/rubies/ruby-3.2.2/include/ruby-3.2.0/arm64-darwin23 -I/Users/tilo/.rvm/rubies/ruby-3.2.2/include/ruby-3.2.0/ruby/backward -I/Users/tilo/.rvm/rubies/ruby-3.2.2/include/ruby-3.2.0 -I/opt/homebrew/Cellar/openssl@1.1/1.1.1m/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fno-common -O3 -I/opt/homebrew/opt/libyaml/include -I/opt/homebrew/opt/libksba/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/openssl@1.1/include -fdeclspec -O3 -ggdb3 -Wall -Wextra -Wextra-tokens -Wdeprecated-declarations -Wdivision-by-zero -Wdiv-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wundef -fno-common -pipe -o a.o -c a.c && file a.o |
Wow!
|
|
Oh... It's a mystery... |
when building the C-extension, it builds x86_64 code on a arm64 CPU, which results in this error:
Is the CPU type is not correctly detected?
Is there a way to force the rake-compiler to only build code that exactly matches the CPU architecture?
The text was updated successfully, but these errors were encountered: