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

Cross-compiling for x86_64 on arm mac fails #970

Closed
michaeleisel opened this issue Jun 4, 2021 · 5 comments · Fixed by #1086
Closed

Cross-compiling for x86_64 on arm mac fails #970

michaeleisel opened this issue Jun 4, 2021 · 5 comments · Fixed by #1086
Labels

Comments

@michaeleisel
Copy link

michaeleisel commented Jun 4, 2021

Describe the bug

When I try to cross-compile for x86_64 from an ARM mac, it fails with error: unknown target CPU 'armv8-a+crypto'. It appears that ABSL_RANDOM_HWAES_ARM64_FLAGS has -march=armv8-a+crypto and is the cause of this problem.

Steps to reproduce the bug

Run cmake -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.14 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 && make ... on an ARM mac.

What version of Abseil are you using?

Latest LTS, 20210324.2

What operating system and version are you using

macOS 11.2.3

What compiler and version are you using?

Apple clang version 12.0.5 (clang-1205.0.22.9)
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

What build system are you using?

cmake version 3.20.3

@ksophocleous
Copy link

is there any workaround for this issue?

@derekmauro
Copy link
Member

I don't have a machine with the specific configuration needed to test this one.

Can someone affected by this issue try derekmauro@6d09f76?

@doctorpangloss
Copy link

doctorpangloss commented Dec 25, 2021

I don't have a machine with the specific configuration needed to test this one.

Can someone affected by this issue try derekmauro@6d09f76?

The workaround does not work.

@derekmauro
Copy link
Member

I don't have a machine with the specific configuration needed to test this one.
Can someone affected by this issue try derekmauro@6d09f76?

The workaround does not work.

Can you share the failing command and the error message?

@doctorpangloss
Copy link

doctorpangloss commented Dec 28, 2021

I see the same error: error: unknown target CPU 'armv8-a+crypto'.

My objective was to get things working for Unity Apple Silicon, which uses libgrpc_csharp_ext and is blocked by this bug.

Workaround:

Patching AbseilConfigureCopts.cmake with the following resolves the issue:

diff --git a/absl/copts/AbseilConfigureCopts.cmake b/absl/copts/AbseilConfigureCopts.cmake
index 9cd6fd1..143f2de 100644
--- a/absl/copts/AbseilConfigureCopts.cmake
+++ b/absl/copts/AbseilConfigureCopts.cmake
@@ -19,7 +19,9 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
     set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_X64_FLAGS}")
   endif()
 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*|aarch64")
-  if (CMAKE_SIZEOF_VOID_P STREQUAL "8")
+  if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
+    set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_X64_FLAGS}")
+  elseif(CMAKE_SIZEOF_VOID_P STREQUAL "8")
     set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_ARM64_FLAGS}")
   elseif(CMAKE_SIZEOF_VOID_P STREQUAL "4")
     set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_ARM32_FLAGS}")

Copy the above using the GitHub copy button, then inside the abseil-cpp directory in grpc/src/third_party use the following command on a macOS terminal:

pbpaste | git apply -

As you can see I'm special casing a single architecture build here. I use the following command:

arch=x86_64
mkdir -pv ../build
cmake -B ../build/cmake-build-release-$arch -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=$arch -G Xcode -DCMAKE_CXX_FLAGS="-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
cmake --build  ../build/cmake-build-release-$arch --config Release

Re: grpc/grpc#28433

To create the multi-arch binaries for grpc I use lipo. This is better for Unity because it's simpler to replace the one binary file and not touch the [DllImport ... ] glue code.

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

Successfully merging a pull request may close this issue.

4 participants