-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix Compiling from nargo
on M2 Mac
#1
Conversation
Assume `libomp` installed with `brew`.
barretenberg_wrapper/build.rs
Outdated
if let OS::Linux = select_os() { | ||
let llvm_dir = find_llvm_linux_path(); | ||
println!("cargo:rustc-link-search={}/lib", llvm_dir); | ||
} else if let ARM_APPLE = select_toolchain() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're just checking string equality we don't need to use pattern matching here. Should be else if ARM_APPLE == select_toolchain()
or the reverse select_toolchain() == ARM_APPLE
Edit: Looks like you wrote it this way because of the OS::Linux / ARM_LINUX lines above/below, I'd prefer if both were updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Rewrote matching in the new commit though to include Homebrew path for Intel Macs.
- Add Intel Mac Homebrew path - Optimise toolchain equality checks / matching - Reformat comments
let llvm_dir = find_llvm_linux_path(); | ||
println!("cargo:rustc-link-search={}/lib", llvm_dir) | ||
} | ||
INTEL_APPLE => println!("cargo:rustc-link-search=/usr/local/lib"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add Intel Mac Homebrew path
// Link lib OMP | ||
link_lib_omp(); | ||
// Link lib OpenMP | ||
link_lib_omp(toolchain); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass retrieved toolchain
down to minimise runs of select_toolchain()
.
nargo
on M2 Mac
@@ -33,14 +31,14 @@ fn select_arch() -> Arch { | |||
let arch = std::env::consts::ARCH; | |||
match arch { | |||
"arm" => Arch::Arm, | |||
"aarch64" => Arch::Arm, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helps M2 Macs with returned architecture of aarch64
(instead of arm
) to pick the correct toolchain.
It prevents them running on the fallback x86_64 config that brings compilation involving assembly code, which would lead to the unknown token in expression
error when ran on ARM (described in more details here).
println!("cargo:rustc-link-search={}/lib", llvm_dir) | ||
} | ||
INTEL_APPLE => println!("cargo:rustc-link-search=/usr/local/lib"), | ||
ARM_APPLE => println!("cargo:rustc-link-search=/opt/homebrew/lib"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the error from clang
on macOS failing to find lomp
when no search path is provided:
error: linking with `cc` failed: exit status: 1
= note: ld: library not found for -lomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Cmake changes/fixes and some nix changes
This fixes the errors encountered when
cargo install
ing nargo on M2 (which goes through build.rs).Assume
libomp
installed withbrew
.