diff --git a/barretenberg-sys/build.rs b/barretenberg-sys/build.rs index b07ac1f9..bf874944 100644 --- a/barretenberg-sys/build.rs +++ b/barretenberg-sys/build.rs @@ -129,8 +129,20 @@ fn link_lib_omp(os: &OS) { // We are using clang, so we need to tell the linker where to search for lomp match os { OS::Linux => { - let llvm_dir = find_llvm_linux_path(); - println!("cargo:rustc-link-search={llvm_dir}/lib") + let clang_path_string = + which_clang("clang").expect("Err: Expected to find clang installation on $PATH"); + let clang_path = std::path::Path::new(clang_path_string.as_str()); + let llvm_path = clang_path + .parent() + .expect("Expected to find parent directory of {clang_path_string}"); + let llvm_lib_path = llvm_path.join("lib"); + llvm_path + .try_exists() + .expect("Err: Clang lib path does not exist."); + println!( + "cargo:rustc-link-search={}", + llvm_lib_path.to_str().unwrap() + ); } OS::Apple => { if let Some(brew_prefix) = find_brew_prefix() { @@ -141,19 +153,19 @@ fn link_lib_omp(os: &OS) { println!("cargo:rustc-link-lib=omp"); } -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") - .stdout(std::process::Stdio::piped()) +fn which_clang(clang_command: &'static str) -> Option { + let which_clang_command = std::process::Command::new("which") + .arg(clang_command) .output() - .expect("Failed to execute command to run `find`"); - // This should be the path to llvm - let path_to_llvm = String::from_utf8(output.stdout).unwrap(); - path_to_llvm.trim().to_owned() + .expect("Failed to execute which clang command"); + + if which_clang_command.status.success() { + let path = + String::from_utf8(which_clang_command.stdout).expect("Invalid UTF-8 output from which"); + Some(path.trim().to_owned()) + } else { + None + } } fn find_brew_prefix() -> Option { diff --git a/flake.nix b/flake.nix index 2014a12a..27bd88d5 100644 --- a/flake.nix +++ b/flake.nix @@ -129,11 +129,24 @@ packages.default = barretenberg-backend; - devShells.default = pkgs.mkShell ({ + # llvmPackages should be aligned to selection from libbarretenberg + # better if we get rid of llvm targets and override them from input + devShells.default = pkgs.mkShell.override { stdenv = pkgs.llvmPackages.stdenv; } ({ inputsFrom = builtins.attrValues self.checks; buildInputs = packages.default.buildInputs; - nativeBuildInputs = packages.default.nativeBuildInputs; + nativeBuildInputs = with pkgs; packages.default.nativeBuildInputs ++ [ + which + starship + git + cargo + rustc + ]; + + shellHook = '' + eval "$(starship init bash)" + ''; + } // environment); }); }