Improve find_llvm on MacOS (#1124)

By looking for explicitly versioned Homebrew formulae for LLVM
This commit is contained in:
Marco Cavenati 2023-03-07 03:23:46 +01:00 committed by GitHub
parent c8254dbd0e
commit b96e194812
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,14 +39,23 @@ fn find_llvm_config_brew() -> Result<PathBuf, String> {
if brew_cellar_location.is_empty() {
return Err("Empty return from brew --cellar".to_string());
}
let cellar_glob = format!("{brew_cellar_location}/llvm/*/bin/llvm-config");
let glob_results = glob(&cellar_glob).unwrap_or_else(|err| {
panic!("Could not read glob path {} ({err})", &cellar_glob);
let location_suffix = "*/bin/llvm-config";
let cellar_glob = vec![
// location for explicitly versioned brew formulae
format!("{brew_cellar_location}/llvm@*/{location_suffix}"),
// location for current release brew formulae
format!("{brew_cellar_location}/llvm/{location_suffix}"),
];
let glob_results = cellar_glob.iter().flat_map(|location| {
glob(location).unwrap_or_else(|err| {
panic!("Could not read glob path {location} ({err})");
})
});
match glob_results.last() {
Some(path) => Ok(path.unwrap()),
None => Err(format!(
"No llvm-config found in brew cellar with pattern {cellar_glob}"
"No llvm-config found in brew cellar with patterns {}",
cellar_glob.join(" ")
)),
}
}