AztecProtocol / aztec-2.0

C++ elliptic curve library
134 stars 37 forks source link

Patch M1 compilation error #100

Closed ilitteri closed 1 year ago

ilitteri commented 1 year ago

Motivation

Not all M1 Macs have clang and clang++ on /opt/homebrew/opt/llvm/bin/clang and /opt/homebrew/opt/llvm/bin/clang++ respectively. It shouldn't be necessary to install llvm with brew.

This PR intends to fix a compilation error related to https://github.com/AztecProtocol/barretenberg/issues/66 that causes this crate building to fail when trying to compile noir with the following message:

error: failed to run custom build command for `barretenberg_wrapper v0.1.0 (https://github.com/AztecProtocol/barretenberg?rev=804c7dcf21111acd1302a768a8fa2f453dcec50f#804c7dcf)`

Caused by:
  process didn't exit successfully: `/Users/ivanlitteri/Entropy1729/noir/target/debug/build/barretenberg_wrapper-2caf2ba50008991d/build-script-build` (exit status: 101)
  --- stdout
  CMAKE_TOOLCHAIN_FILE_aarch64-apple-darwin = None
  CMAKE_TOOLCHAIN_FILE_aarch64_apple_darwin = None
  HOST_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_aarch64-apple-darwin = None
  CMAKE_GENERATOR_aarch64_apple_darwin = None
  HOST_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_aarch64-apple-darwin = None
  CMAKE_PREFIX_PATH_aarch64_apple_darwin = None
  HOST_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_aarch64-apple-darwin = None
  CMAKE_aarch64_apple_darwin = None
  HOST_CMAKE = None
  CMAKE = None
  running: "cmake" "/Users/ivanlitteri/.cargo/git/checkouts/barretenberg-6ce83dfea69613eb/804c7dc/barretenberg_wrapper/../barretenberg" "-DAPPLE_M1=1" "-DCMAKE_INSTALL_PREFIX=/Users/ivanlitteri/Entropy1729/noir/target/debug/build/barretenberg_wrapper-2a7f03394f609275/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -arch arm64" "-DCMAKE_C_COMPILER=/usr/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -arch arm64" "-DCMAKE_CXX_COMPILER=/usr/bin/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -arch arm64" "-DCMAKE_ASM_COMPILER=/usr/bin/cc" "-DCMAKE_BUILD_TYPE=Debug"
  -- The CXX compiler identification is unknown
  -- The C compiler identification is unknown
  -- Configuring incomplete, errors occurred!
  See also "/Users/ivanlitteri/Entropy1729/noir/target/debug/build/barretenberg_wrapper-2a7f03394f609275/out/build/CMakeFiles/CMakeOutput.log".
  See also "/Users/ivanlitteri/Entropy1729/noir/target/debug/build/barretenberg_wrapper-2a7f03394f609275/out/build/CMakeFiles/CMakeError.log".

  --- stderr
  CMake Error at CMakeLists.txt:9 (project):
    The CMAKE_CXX_COMPILER:

      /opt/homebrew/opt/llvm/bin/clang++

    is not a full path to an existing compiler tool.

    Tell CMake where to find the compiler by setting either the environment
    variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
    to the compiler, or to the compiler name if it is in the PATH.

  CMake Error at CMakeLists.txt:9 (project):
    The CMAKE_C_COMPILER:

      /opt/homebrew/opt/llvm/bin/clang

    is not a full path to an existing compiler tool.

    Tell CMake where to find the compiler by setting either the environment
    variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
    the compiler, or to the compiler name if it is in the PATH.

  thread 'main' panicked at '
  command did not execute successfully, got: exit status: 1

  build script failed, must exit now', /Users/ivanlitteri/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.48/src/lib.rs:975:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

Notes

The aztec_backend's rev in noir's crates/nargo/Cargo.toml is pointing to https://github.com/noir-lang/aztec_backend/commit/01b922adcb5a9d70b2d12304e1cb7487d9f28188 (see the code) which has a Cargo.toml with the dependency barretenberg_wrapper pointing to the rev https://github.com/AztecProtocol/barretenberg/commit/804c7dcf21111acd1302a768a8fa2f453dcec50f (see the code) of the branch kw/noir-dsl-mac of this repo.

To be faithful with the actual implementation I made the changes on kw/noir-dsl-mac (hence this PR pointing to it) and the changes that I mention in the next section will be made branching out of the revs noted in the previous paragraph.

Related PRs

There are no yet related PRs to this one but I'm working on the proper changes to get this fix up to noir's repo.

For the moment I would need to update the following dependencies:


Feedback is more than welcome and let me know if this is not the place for this PR.

jfecher commented 1 year ago

This used to be the default but I believe we wanted to force homebrew clang as the default shipped clang did not include libomp on mac. Since it is possible to have several different homebrew clang versions in different directories though, I think we can change back to this approach to give users more flexibility. Anecdotally speaking on an M1 Mac, I am not encountering the libomp error anymore when building with either apple clang or homebrew clang but I cannot confirm if it is fixed for everyone. Nevertheless, for the reasons above we can merge this PR.