forked from AztecProtocol/aztec-connect
-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,9 @@ pub enum Arch { | |
X86_64, | ||
Arm, | ||
} | ||
// These constants correspond to the filenames | ||
// in cmake/toolchains | ||
// These constants correspond to the filenames in cmake/toolchains | ||
// | ||
// There are currently no toolchains for windows | ||
// Please use WSL | ||
// There are currently no toolchain for windows, please use WSL | ||
const INTEL_APPLE: &str = "x86_64-apple-clang"; | ||
const INTEL_LINUX: &str = "x86_64-linux-clang"; | ||
const ARM_APPLE: &str = "arm-apple-clang"; | ||
|
@@ -41,7 +39,6 @@ fn select_arch() -> Arch { | |
} | ||
} | ||
} | ||
|
||
fn select_os() -> OS { | ||
let os = std::env::consts::OS; | ||
match os { | ||
|
@@ -55,18 +52,16 @@ fn select_os() -> OS { | |
} | ||
} | ||
fn select_cpp_stdlib() -> &'static str { | ||
// The name of the c++ stdlib depends on the | ||
// operating system | ||
// The name of the c++ stdlib depends on the OS | ||
match select_os() { | ||
OS::Linux => "stdc++", | ||
OS::Apple => "c++", | ||
} | ||
} | ||
fn set_brew_env_var() { | ||
// The cmake file for macos uses an environment | ||
// variable to figure out where to find | ||
// certain programs installed via brew | ||
if let OS::Apple = select_os() { | ||
fn set_brew_env_var(toolchain: &'static str) { | ||
// The cmake file for macos uses an environment variable | ||
// to figure out where to find certain programs installed via brew | ||
if toolchain == INTEL_APPLE || toolchain == ARM_APPLE { | ||
let output = std::process::Command::new("brew") | ||
.arg("--prefix") | ||
.stdout(std::process::Stdio::piped()) | ||
|
@@ -76,9 +71,9 @@ fn set_brew_env_var() { | |
let stdout = String::from_utf8(output.stdout).unwrap(); | ||
|
||
env::set_var("BREW_PREFIX", stdout.trim()); | ||
// | ||
} | ||
} | ||
|
||
fn main() { | ||
// Builds the project in ../barretenberg into dst | ||
println!("cargo:rerun-if-changed=../barretenberg"); | ||
|
@@ -90,7 +85,7 @@ fn main() { | |
// TODO: We could check move this to a bash script along with | ||
// TODO: checks that check that all the necessary dependencies are | ||
// TODO installed via llvm | ||
set_brew_env_var(); | ||
set_brew_env_var(toolchain); | ||
|
||
let dst = cmake::Config::new("../barretenberg") | ||
.very_verbose(true) | ||
|
@@ -105,8 +100,8 @@ fn main() { | |
|
||
// Link C++ std lib | ||
println!("cargo:rustc-link-lib={}", select_cpp_stdlib()); | ||
// Link lib OMP | ||
link_lib_omp(); | ||
// Link lib OpenMP | ||
link_lib_omp(toolchain); | ||
|
||
// println!( | ||
// "cargo:rustc-link-search={}/build/src/aztec/bb", | ||
|
@@ -203,7 +198,6 @@ fn main() { | |
println!("cargo:rustc-link-lib=static=stdlib_pedersen"); | ||
|
||
// Generate bindings from a header file and place them in a bindings.rs file | ||
|
||
let bindings = bindgen::Builder::default() | ||
// Clang args so that we can use relative include paths | ||
.clang_args(&["-I../barretenberg/src/aztec", "-I../..", "-I../", "-xc++"]) | ||
|
@@ -216,17 +210,18 @@ fn main() { | |
.expect("Couldn't write bindings"); | ||
} | ||
|
||
fn link_lib_omp() { | ||
// | ||
// we are using clang, so we need to tell the linker where | ||
// to search for lomp. | ||
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() { | ||
println!("cargo:rustc-link-search=/opt/homebrew/lib") | ||
fn link_lib_omp(toolchain: &'static str) { | ||
// We are using clang, so we need to tell the linker where to search for lomp | ||
match toolchain { | ||
INTEL_LINUX | ARM_LINUX => { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Add Intel Mac Homebrew path |
||
ARM_APPLE => println!("cargo:rustc-link-search=/opt/homebrew/lib"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes the error from
|
||
&_ => unimplemented!("lomp linking of {} is not supported", toolchain), | ||
} | ||
if let ARM_LINUX = select_toolchain() { | ||
if toolchain == ARM_LINUX { | ||
// only arm linux uses gcc | ||
println!("cargo:rustc-link-lib=gomp") | ||
} else { | ||
|
@@ -238,7 +233,6 @@ fn find_llvm_linux_path() -> String { | |
// Most linux systems will have the `find` application | ||
// | ||
// This assumes that there is a single llvm-X folder in /usr/lib | ||
|
||
let output = std::process::Command::new("sh") | ||
.arg("-c") | ||
.arg("find /usr/lib -type d -name \"*llvm-*\" -print -quit") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ofselect_toolchain()
.