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

Generated Makefile for NIFs on Apple M1 processor is incorrect #2655

Closed
NAR opened this issue Nov 29, 2021 · 2 comments
Closed

Generated Makefile for NIFs on Apple M1 processor is incorrect #2655

NAR opened this issue Nov 29, 2021 · 2 comments

Comments

@NAR
Copy link
Contributor

NAR commented Nov 29, 2021

Pre-Check

Environment

Rebar3 report
version 3.17.0+build.5120.ref26d929b0
generated at 2021-11-29T21:05:24+00:00

Current behaviour

I followed the description at http://rebar3.org/docs/tutorials/building_c_cpp/ to create a NIF library. I executed the

rebar3 new lib test_nif
cd test_nif
rebar3 new cmake

commands which generated a c_src/Makefile. This Makefile has an OS X-specific section:

ifeq ($(UNAME_SYS), Darwin)
	CC ?= cc
	CFLAGS ?= -O3 -std=c99 -arch x86_64 -finline-functions -Wall -Wmissing-prototypes
	CXXFLAGS ?= -O3 -arch x86_64 -finline-functions -Wall
	LDFLAGS ?= -arch x86_64 -flat_namespace -undefined suppress

The problem is that the M1 processor in newer Macs is not an x86_64, so the generated shared library can't be loaded by the native Erlang VM. According to the file command the shared library is a Mach-O 64-bit dynamically linked shared library x86_64, but the Erlang VM says:

1> erlang:system_info(system_architecture).
"arm-apple-darwin20.6.0"

Expected behaviour

I expected the generated Makefile to be correct :-) I'm not quite sure what should be the correct solution, my workaround was to remove the -arch x86_64 options (see for example at maxlapshin/fix#14). However, if that option was there for a reason, we might need to branch on machine type too, not only on OS.

@NAR
Copy link
Contributor Author

NAR commented Nov 30, 2021

I created a PR: #2656

@ferd
Copy link
Collaborator

ferd commented Nov 30, 2021

Thanks! Already merged. I don't imagine this option was essential (the architecture isn't specified for other OSes either) and the build worked, so I suppose it to be fine.

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

2 participants