elixir-explorer / adbc

Apache Arrow ADBC bindings for Elixir
https://arrow.apache.org/adbc/
Apache License 2.0
50 stars 16 forks source link

Compiling for MacOS arm64 targets #6

Closed Qqwy closed 1 year ago

Qqwy commented 1 year ago

Until now, the project did not compile on my MacOS M1 laptop. It worked perfectly fine on my old x86-64 Linux laptop, but I wanted to try to make it compile properly on my current laptop as well.

After some trial and error, I've figured out that the proper way to do this, seems to be to pass the option CMAKE_OSX_ARCHITECTURES=arm64 to cmake.

What I don't know, however, is what the best way to set this setting properly on the actual device the Makefile ends up executing on.

Any ideas?

cocoa-xu commented 1 year ago

Hi @Qqwy, it works fine on my M2 MBP. I wonder if you have any error logs for that?

Qqwy commented 1 year ago
This is the log when running `mix clean && mix compile` on a037709fc969e99b52399ed0e61468ac8955792b. ``` ➜ mix clean && mix compile ==> elixir_make Compiling 6 files (.ex) Generated elixir_make app ==> cc_precompiler Compiling 3 files (.ex) Generated cc_precompiler app ==> adbc Downloading precompiled NIF to /Users/qqwy/Library/Caches/adbc-nif-2.16-aarch64-apple-darwin-0.1.0.tar.gz Error happened while installing adbc from precompiled binary: "precompiled \"adbc-nif-2.16-aarch64-apple-darwin-0.1.0.tar.gz\" does not exist or cannot download: :enoent". Attempting to compile adbc from source... CMake Warning: Ignoring empty string ("") provided on the command line. Not searching for unused variables given on the command line. -- The C compiler identification is AppleClang 14.0.3.14030022 -- The CXX compiler identification is AppleClang 14.0.3.14030022 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Performing Test CXX_LINKER_SUPPORTS_VERSION_SCRIPT -- Performing Test CXX_LINKER_SUPPORTS_VERSION_SCRIPT - Failed -- Found SQLite3: /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include (found version "3.39.5") -- --------------------------------------------------------------------- -- Arrow version: 0.4.0 -- -- Build configuration summary: -- Generator: Unix Makefiles -- Build type: Release -- Source directory: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/3rd_party/apache-arrow-adbc/c -- Install prefix: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv -- -- Compile and link options: -- -- ADBC_CXXFLAGS="" [default=""] -- Compiler flags to append when compiling ADBC C++ libraries -- ADBC_GO_BUILD_TAGS="" [default=""] -- Build tags to append when compiling ADBC Go libraries -- ADBC_BUILD_STATIC=OFF [default=ON] -- Build static libraries -- ADBC_BUILD_SHARED=ON [default=ON] -- Build shared libraries -- ADBC_PACKAGE_KIND="" [default=""] -- Arbitrary string that identifies the kind of package -- (for informational purposes) -- ADBC_GIT_ID=a037709fc969e99b52399ed0e61468ac8955792b [default=""] -- The Arrow git commit id (if any) -- ADBC_GIT_DESCRIPTION="" [default=""] -- The Arrow git commit description (if any) -- ADBC_NO_DEPRECATED_API=OFF [default=OFF] -- Exclude deprecated APIs from build -- ADBC_USE_CCACHE=ON [default=ON] -- Use ccache when compiling (if available) -- ADBC_USE_PRECOMPILED_HEADERS=OFF [default=OFF] -- Use precompiled headers when compiling -- ADBC_ARMV8_ARCH=armv8-a [default=armv8-a|armv8-a+crc+crypto] -- Arm64 arch and extensions -- ADBC_ALTIVEC=ON [default=ON] -- Build with Altivec if compiler has support -- ADBC_RPATH_ORIGIN=OFF [default=OFF] -- Build Arrow libraries with RATH set to $ORIGIN -- ADBC_INSTALL_NAME_RPATH=ON [default=ON] -- Build Arrow libraries with install_name set to @rpath -- ADBC_GGDB_DEBUG=ON [default=ON] -- Pass -ggdb flag to debug builds -- -- Test and benchmark options: -- -- ADBC_BUILD_EXAMPLES=OFF [default=OFF] -- Build the Arrow examples -- ADBC_BUILD_TESTS=OFF [default=OFF] -- Build the Arrow googletest unit tests -- ADBC_BUILD_INTEGRATION=OFF [default=OFF] -- Build the Arrow integration test executables -- ADBC_BUILD_BENCHMARKS=OFF [default=OFF] -- Build the Arrow micro benchmarks -- ADBC_TEST_LINKAGE=shared [default=shared|static] -- Linkage of Arrow libraries with unit tests executables. -- -- Lint options: -- -- ADBC_GENERATE_COVERAGE=OFF [default=OFF] -- Build with C++ code coverage enabled -- -- Checks options: -- -- ADBC_TEST_MEMCHECK=OFF [default=OFF] -- Run the test suite using valgrind --tool=memcheck -- ADBC_USE_ASAN=OFF [default=OFF] -- Enable Address Sanitizer checks -- ADBC_USE_TSAN=OFF [default=OFF] -- Enable Thread Sanitizer checks -- ADBC_USE_UBSAN=OFF [default=OFF] -- Enable Undefined Behavior sanitizer checks -- -- Thirdparty toolchain options: -- -- ADBC_DEPENDENCY_SOURCE=BUNDLED [default=AUTO|BUNDLED|SYSTEM|CONDA|VCPKG|BREW] -- Method to use for acquiring arrow's build dependencies -- -- Advanced developer options: -- -- -- Project components options: -- -- ADBC_DRIVER_FLIGHTSQL=OFF [default=OFF] -- Build the Flight SQL driver -- ADBC_DRIVER_MANAGER=ON [default=OFF] -- Build the driver manager -- ADBC_DRIVER_POSTGRESQL=OFF [default=OFF] -- Build the PostgreSQL driver -- ADBC_DRIVER_SQLITE=ON [default=OFF] -- Build the SQLite driver -- ADBC_DRIVER_SNOWFLAKE=OFF [default=OFF] -- Build the Snowflake driver -- Configuring done -- Generating done -- Build files have been written to: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/cmake_adbc gmake[1]: Entering directory '/Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/cmake_adbc' [ 33%] Building CXX object driver_manager/CMakeFiles/adbc_driver_manager_objlib.dir/adbc_driver_manager.cc.o [ 33%] Building C object vendor/nanoarrow/CMakeFiles/nanoarrow.dir/nanoarrow.c.o [ 33%] Building C object driver/common/CMakeFiles/adbc_driver_common.dir/utils.c.o [ 44%] Linking C static library libadbc_driver_common.a [ 44%] Built target adbc_driver_common [ 55%] Linking C static library libnanoarrow.a [ 55%] Built target nanoarrow [ 77%] Building C object driver/sqlite/CMakeFiles/adbc_driver_sqlite_objlib.dir/statement_reader.c.o [ 77%] Building C object driver/sqlite/CMakeFiles/adbc_driver_sqlite_objlib.dir/sqlite.c.o [ 77%] Built target adbc_driver_manager_objlib [ 88%] Linking CXX shared library libadbc_driver_manager.dylib [ 88%] Built target adbc_driver_manager_shared [ 88%] Built target adbc_driver_sqlite_objlib [100%] Linking C shared library libadbc_driver_sqlite.dylib [100%] Built target adbc_driver_sqlite_shared Install the project... -- Install configuration: "Release" -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/libadbc_driver_manager.4.0.0.dylib -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/libadbc_driver_manager.4.dylib -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/libadbc_driver_manager.dylib -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/cmake/AdbcDriverManager/AdbcDriverManagerConfig.cmake -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/cmake/AdbcDriverManager/AdbcDriverManagerConfigVersion.cmake -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/cmake/AdbcDriverManager/AdbcDriverManagerTargets.cmake -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/cmake/AdbcDriverManager/AdbcDriverManagerTargets-release.cmake -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/pkgconfig/adbc-driver-manager.pc -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/include/adbc.h -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/include/adbc_driver_manager.h -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/libadbc_driver_sqlite.4.0.0.dylib -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/libadbc_driver_sqlite.4.dylib -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/libadbc_driver_sqlite.dylib -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/cmake/AdbcDriverSQLite/AdbcDriverSQLiteConfig.cmake -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/cmake/AdbcDriverSQLite/AdbcDriverSQLiteConfigVersion.cmake -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/cmake/AdbcDriverSQLite/AdbcDriverSQLiteTargets.cmake -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/cmake/AdbcDriverSQLite/AdbcDriverSQLiteTargets-release.cmake -- Installing: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/lib/pkgconfig/adbc-driver-sqlite.pc gmake[1]: Leaving directory '/Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/cmake_adbc' CMake Warning: Ignoring empty string ("") provided on the command line. Not searching for unused variables given on the command line. -- The C compiler identification is AppleClang 14.0.3.14030022 -- The CXX compiler identification is AppleClang 14.0.3.14030022 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Using PRIV_DIR: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv -- Using ERTS_INCLUDE_DIR: /Users/qqwy/.asdf/installs/erlang/25.0/erts-13.0/include -- CMAKE_TOOLCHAIN_FILE: -- Configuring done -- Generating done -- Build files have been written to: /Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/cmake_adbc_nif [ 33%] Building CXX object CMakeFiles/adbc_nif.dir/c_src/nif_utils.cpp.o [ 66%] Building CXX object CMakeFiles/adbc_nif.dir/c_src/adbc_nif.cpp.o [100%] Linking CXX shared library adbc_nif.so [100%] Built target adbc_nif Compiling 10 files (.ex) 12:30:13.271 [error] Process #PID<0.336.0> raised an exception ** (Protocol.UndefinedError) protocol String.Chars not implemented for {:load_failed, 'Failed to load NIF library: \'dlopen(/Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/adbc_nif.so, 0x0002): tried: \'/Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/adbc_nif.so\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64\')), \'/System/Volumes/Preboot/Cryptexes/OS/Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/adbc_nif.so\' (no such file), \'/Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/adbc_nif.so\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64\'))\''} of type Tuple (elixir 1.14.1) lib/string/chars.ex:3: String.Chars.impl_for!/1 (elixir 1.14.1) lib/string/chars.ex:22: String.Chars.to_string/1 lib/adbc_nif.ex:11: Adbc.Nif.load_nif/0 (kernel 8.4) code_server.erl:1317: anonymous fn/1 in :code_server.handle_on_load/5 12:30:13.272 [warning] The on_load function for module Elixir.Adbc.Nif returned: {%Protocol.UndefinedError{ protocol: String.Chars, value: {:load_failed, 'Failed to load NIF library: \'dlopen(/Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/adbc_nif.so, 0x0002): tried: \'/Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/adbc_nif.so\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64\')), \'/System/Volumes/Preboot/Cryptexes/OS/Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/adbc_nif.so\' (no such file), \'/Users/qqwy/Programming/Personal/elixir/rust_c/adbc/_build/dev/lib/adbc/priv/adbc_nif.so\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64\'))\''}, description: "" }, [ {String.Chars, :impl_for!, 1, [file: 'lib/string/chars.ex', line: 3]}, {String.Chars, :to_string, 1, [file: 'lib/string/chars.ex', line: 22]}, {Adbc.Nif, :load_nif, 0, [file: 'lib/adbc_nif.ex', ...]}, {:code_server, :"-handle_on_load/5-fun-0-", 1, [...]} ]} Generated adbc app ```

Maybe there is some weird configuration setting missing on my machine that makes Make/CMake think it should compile for x86 instead?

josevalim commented 1 year ago

@Qqwy I think it is something related to Rosetta? Either make or something else is compiling the wrong version. What happens if you set CMAKE_OSX_ARCHITECTURES=arm64 as an env var in your shell?

Qqwy commented 1 year ago

What happens if you set CMAKE_OSX_ARCHITECTURES=arm64 as an env var in your shell?

It does not change the output; it seems cmake does not read those -D settings (looking into its docs, they seem to be called 'cache entries') from the environment variables.

Running the arch or uname -m shell commands on this M1 laptop shows arm64 as expected. 🤔

Qqwy commented 1 year ago

At the very least it's good to know that it works on your computers, because then it is more likely that it is a problem with my laptop rather than something that needs to be improved in the library 😅

cocoa-xu commented 1 year ago

Emmm, that seems to be weird. Could you please add one line in the CMakeLists.txt, below line 14?

message(STATUS "CMAKE_HOST_SYSTEM_PROCESSOR: ${CMAKE_HOST_SYSTEM_PROCESSOR}")

It should look like this

... skipped
-- Using PRIV_DIR: /Users/cocoa/Workspace/Git/adbc/_build/test/lib/adbc/priv
-- CMAKE_HOST_SYSTEM_PROCESSOR: arm64
...
Qqwy commented 1 year ago

Yes, that prints -- CMAKE_HOST_SYSTEM_PROCESSOR: x86_64 🤔 . I'm currently running cmake version 3.25.1.

Ah! Updating cmake resolved the issue. Either the other version was (too) old, or it was installed (only) as part of some kind of rosetta-app installation (which is weird, how did it end up in the non-Rosetta path? 🤐 ). Installing the up-to-date version 3.26.4 through the arm64 version of homebrew fixed the issue.

Thank you both for your help! 🙇

cocoa-xu commented 1 year ago

which is weird, how did it end up in the non-Rosetta path?

Maybe the path to the Rosetta bin presents before the non-Rosetta one in $PATH? 🤔

Or it might be linked with --force option when installed by the x86_64 homebrew?