From 3aaf91e03fc01f0cb12249f22dbcb007023f69d4 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Sun, 3 Sep 2023 22:21:19 +0100 Subject: [PATCH] fix: Adds Mac cross compile flags into barretenberg (#1954) When fixing https://github.com/AztecProtocol/aztec-packages/issues/1841 the flags were put in the cmake toolchains file for circuits which does not get inherited by the barretenberg toolchain files. --- .../cpp/cmake/toolchains/aarch64-darwin.cmake | 9 +++++++++ .../cpp/cmake/toolchains/x86_64-darwin.cmake | 9 +++++++++ circuits/cpp/cmake/toolchains/aarch64-darwin.cmake | 11 +++++++++-- circuits/cpp/cmake/toolchains/x86_64-darwin.cmake | 11 +++++++++-- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/cmake/toolchains/aarch64-darwin.cmake b/circuits/cpp/barretenberg/cpp/cmake/toolchains/aarch64-darwin.cmake index a3b8d52fa72..5cf78980483 100644 --- a/circuits/cpp/barretenberg/cpp/cmake/toolchains/aarch64-darwin.cmake +++ b/circuits/cpp/barretenberg/cpp/cmake/toolchains/aarch64-darwin.cmake @@ -1,2 +1,11 @@ set(CMAKE_SYSTEM_NAME Darwin) set(CMAKE_SYSTEM_PROCESSOR aarch64) + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Clang allows us to cross compile on Mac + # so we explicitly specify the arch to the compiler + # If you just select the arch toolchain and are on an + # x86_64, it will compile for x86_64 mac. + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch arm64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch arm64") +endif() \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/cmake/toolchains/x86_64-darwin.cmake b/circuits/cpp/barretenberg/cpp/cmake/toolchains/x86_64-darwin.cmake index 0aa93407fbd..47b58dcc854 100644 --- a/circuits/cpp/barretenberg/cpp/cmake/toolchains/x86_64-darwin.cmake +++ b/circuits/cpp/barretenberg/cpp/cmake/toolchains/x86_64-darwin.cmake @@ -1,2 +1,11 @@ set(CMAKE_SYSTEM_NAME Darwin) set(CMAKE_SYSTEM_PROCESSOR x86_64) + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Clang allows us to cross compile on Mac + # so we explicitly specify the arch to the compiler + # If you just select the x86_64 toolchain and are on an + # M1/arm64 mac, it will compile for arm64. + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch x86_64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch x86_64") +endif() diff --git a/circuits/cpp/cmake/toolchains/aarch64-darwin.cmake b/circuits/cpp/cmake/toolchains/aarch64-darwin.cmake index 8899c4b1c00..227680938b4 100644 --- a/circuits/cpp/cmake/toolchains/aarch64-darwin.cmake +++ b/circuits/cpp/cmake/toolchains/aarch64-darwin.cmake @@ -1,4 +1,11 @@ set(CMAKE_SYSTEM_NAME Darwin) set(CMAKE_SYSTEM_PROCESSOR aarch64) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch arm64") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch arm64") \ No newline at end of file + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Clang allows us to cross compile on Mac + # so we explicitly specify the arch to the compiler + # If you just select the arch toolchain and are on an + # x86_64, it will compile for x86_64 mac. + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch arm64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch arm64") +endif() diff --git a/circuits/cpp/cmake/toolchains/x86_64-darwin.cmake b/circuits/cpp/cmake/toolchains/x86_64-darwin.cmake index 535814275ba..47b58dcc854 100644 --- a/circuits/cpp/cmake/toolchains/x86_64-darwin.cmake +++ b/circuits/cpp/cmake/toolchains/x86_64-darwin.cmake @@ -1,4 +1,11 @@ set(CMAKE_SYSTEM_NAME Darwin) set(CMAKE_SYSTEM_PROCESSOR x86_64) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch x86_64") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch x86_64") + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Clang allows us to cross compile on Mac + # so we explicitly specify the arch to the compiler + # If you just select the x86_64 toolchain and are on an + # M1/arm64 mac, it will compile for arm64. + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch x86_64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch x86_64") +endif()