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

list_cpu_feature doesn't build on Apple M1 #210

Open
jwatte opened this issue Dec 22, 2021 · 2 comments
Open

list_cpu_feature doesn't build on Apple M1 #210

jwatte opened this issue Dec 22, 2021 · 2 comments
Labels
Apple M1 Apple M1 related issues

Comments

@jwatte
Copy link

jwatte commented Dec 22, 2021

Note that Apple no longer sells new x64 MacBooks. It's literally impossible to get a new x64 MacBook for an engineer joining a team.

Using CMake 3.22

When doing a git clone [email protected]:google/cpu_features && cd cpu_features && mkdir build && cd build && cmake ../ && make I get the following build errors:

Cloning into 'cpu_features'...
remote: Enumerating objects: 1476, done.
remote: Counting objects: 100% (473/473), done.
remote: Compressing objects: 100% (258/258), done.
remote: Total 1476 (delta 261), reused 349 (delta 197), pack-reused 1003
Receiving objects: 100% (1476/1476), 522.02 KiB | 1.81 MiB/s, done.
Resolving deltas: 100% (922/922), done.
jwatte@Jons-MBP ~ % cd cpu_features 
jwatte@Jons-MBP cpu_features % ls
CMakeLists.txt	LICENSE		ci		include		scripts		test
CONTRIBUTING.md	README.md	cmake		ndk_compat	src
jwatte@Jons-MBP cpu_features % mkdir build
jwatte@Jons-MBP cpu_features % cd build 
jwatte@Jons-MBP build % cmake ..
-- The C compiler identification is AppleClang 13.0.0.13000029
-- 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
-- Looking for dlfcn.h
-- Looking for dlfcn.h - found
-- Looking for getauxval
-- Looking for getauxval - not found
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- 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
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jwatte/cpu_features/build/googletest-download
[ 11%] Creating directories for 'googletest'
[ 22%] Performing download step (git clone) for 'googletest'
Cloning into 'googletest-src'...
Already on 'main'
Your branch is up to date with 'origin/main'.
[ 33%] Performing update step for 'googletest'
HEAD is now at 71d4e2f7 Makes TestForDeathTest.CRTDebugDeath only run when _DEBUG is defined
[ 44%] No patch step for 'googletest'
[ 55%] No configure step for 'googletest'
[ 66%] No build step for 'googletest'
[ 77%] No install step for 'googletest'
[ 88%] No test step for 'googletest'
[100%] Completed 'googletest'
[100%] Built target googletest
-- Found Python: /opt/homebrew/Frameworks/Python.framework/Versions/3.9/bin/python3.9 (found version "3.9.9") found components: Interpreter 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jwatte/cpu_features/build
jwatte@Jons-MBP build % make
[  2%] Building C object CMakeFiles/utils.dir/src/filesystem.c.o
[  4%] Building C object CMakeFiles/utils.dir/src/stack_line_reader.c.o
[  6%] Building C object CMakeFiles/utils.dir/src/string_view.c.o
[  6%] Built target utils
[  9%] Building C object CMakeFiles/unix_based_hardware_detection.dir/src/hwcaps.c.o
[  9%] Built target unix_based_hardware_detection
[ 11%] Building C object CMakeFiles/cpu_features.dir/src/impl_aarch64_linux_or_android.c.o
[ 13%] Building C object CMakeFiles/cpu_features.dir/src/impl_arm_linux_or_android.c.o
[ 15%] Building C object CMakeFiles/cpu_features.dir/src/impl_mips_linux_or_android.c.o
[ 18%] Building C object CMakeFiles/cpu_features.dir/src/impl_ppc_linux.c.o
[ 20%] Building C object CMakeFiles/cpu_features.dir/src/impl_x86_freebsd.c.o
[ 22%] Building C object CMakeFiles/cpu_features.dir/src/impl_x86_linux_or_android.c.o
[ 25%] Building C object CMakeFiles/cpu_features.dir/src/impl_x86_macos.c.o
[ 27%] Building C object CMakeFiles/cpu_features.dir/src/impl_x86_windows.c.o
[ 29%] Linking C static library libcpu_features.a
[ 29%] Built target cpu_features
[ 31%] Building C object CMakeFiles/list_cpu_features.dir/src/utils/list_cpu_features.c.o
[ 34%] Linking C executable list_cpu_features
Undefined symbols for architecture arm64:
  "_GetAarch64FeaturesEnumName", referenced from:
      _main in list_cpu_features.c.o
  "_GetAarch64FeaturesEnumValue", referenced from:
      _main in list_cpu_features.c.o
  "_GetAarch64Info", referenced from:
      _main in list_cpu_features.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [list_cpu_features] Error 1
make[1]: *** [CMakeFiles/list_cpu_features.dir/all] Error 2
make: *** [all] Error 2

So, the architecture here is arm64 not aarch64, which is unfortunate, but a fact of life.
I imagine the easiest fix might be to patch that up to alias. There was at least one other patch to do that, #150, which has been open for over a year.
And, because the world is what it is, this means that building MacOS installers for electron apps no longer works.
Just sayin'.

@Mizux Mizux added the Apple M1 Apple M1 related issues label Dec 22, 2021
@Mizux
Copy link
Collaborator

Mizux commented Dec 22, 2021

Feel free to send us a patch to:

#elif defined(CPU_FEATURES_ARCH_AARCH64)
DEFINE_ADD_FLAGS(GetAarch64FeaturesEnumValue, GetAarch64FeaturesEnumName,
Aarch64Features, AARCH64_LAST_)

here we should split this code in

#elif defined(CPU_FEATURES_ARCH_AARCH64)  && defined(CPU_FEATURES_OS_MACOS)
....
#elif defined(CPU_FEATURES_ARCH_AARCH64)  && !defined(CPU_FEATURES_OS_MACOS)
...

ref:

#if (defined(__apple__) || defined(__APPLE__) || defined(__MACH__))
// From https://stackoverflow.com/a/49560690
#include "TargetConditionals.h"
#if defined(TARGET_OS_OSX)
#define CPU_FEATURES_OS_MACOS
#endif
#if defined(TARGET_OS_IPHONE)
// This is set for any non-Mac Apple products (IOS, TV, WATCH)
#define CPU_FEATURES_OS_IPHONE
#endif
#endif

Otherwise CMake seems to correctly detect arm64 architecture and build for it.
note: You should consider to use cmake -S. -Bbuild && cmake --build build -v instead of creating the build dir by hand and call make directly....

@Mizux Mizux changed the title Doesn't build with cmake 3.22 on Apple MacBook list_cpu_feature doesn't build on Apple M1 Dec 22, 2021
@Mizux
Copy link
Collaborator

Mizux commented Dec 22, 2021

ugly workaround: disable the build of list_cpu_features
aka comment out the lines:

cpu_features/CMakeLists.txt

Lines 149 to 151 in 69d3993

add_executable(list_cpu_features ${PROJECT_SOURCE_DIR}/src/utils/list_cpu_features.c)
target_link_libraries(list_cpu_features PRIVATE cpu_features)
add_executable(CpuFeature::list_cpu_features ALIAS list_cpu_features)

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

No branches or pull requests

2 participants