diff --git a/build.rs b/build.rs index df4ef93c7230383698db19c6da9f29cef51a6016..d6975572b730cb6104532cb0afd8becfd2cc17f6 100644 --- a/build.rs +++ b/build.rs @@ -102,6 +102,22 @@ fn locate_llvm_config() -> Option { } } + // On FreeBSD, LLVM binary packages install to /usr/local/llvm{version} (where version is "21", + // "20" and so forth down to 11 as the earliest available as of 2025-11-13) and aren't on PATH. + // Search for one of those if nothing else worked, newest first. + if target_os_is("freebsd") { + let mut prefix = PathBuf::from("/usr/local/"); + + for version in (11..=(CRATE_VERSION.major / 10)).rev() { + prefix.push(format!("llvm{version}/bin")); + if let Some(x) = llvm_compatible_binary_name(&prefix) { + return Some(x); + } + prefix.pop(); + prefix.pop(); + } + } + None }