Skip to content

Commit

Permalink
Continue looping if candidate cxx isn't found in verify_fips_clang_ve…
Browse files Browse the repository at this point in the history
…rsion

A basic LLVM 12 build provides clang-12 but not clang++-12, but
it does provide both clang and clang++, so we shouldn't hard fail
when first checking for clang-12 and clang++-12.
  • Loading branch information
nox committed Oct 16, 2023
1 parent 1a50651 commit bad1c21
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions boring-sys/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,20 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
/// See "Installation Instructions" under section 12.1.
// TODO: maybe this should also verify the Go and Ninja versions? But those haven't been an issue in practice ...
fn verify_fips_clang_version() -> (&'static str, &'static str) {
fn version(tool: &str) -> String {
fn version(tool: &str) -> Option<String> {
let output = match Command::new(tool).arg("--version").output() {
Ok(o) => o,
Err(e) => {
eprintln!("warning: missing {}, trying other compilers: {}", tool, e);
// NOTE: hard-codes that the loop below checks the version
return String::new();
return None;
}
};
if !output.status.success() {
return String::new();
return Some(String::new());
}
let output = std::str::from_utf8(&output.stdout).expect("invalid utf8 output");
output.lines().next().expect("empty output").to_string()
Some(output.lines().next().expect("empty output").to_string())
}

const REQUIRED_CLANG_VERSION: &str = "12.0.0";
Expand All @@ -317,10 +317,13 @@ fn verify_fips_clang_version() -> (&'static str, &'static str) {
("clang", "clang++"),
("cc", "c++"),
] {
let cc_version = version(cc);
let (Some(cc_version), Some(cxx_version)) = (version(cc), version(cxx)) else {
continue;
};

if cc_version.contains(REQUIRED_CLANG_VERSION) {
assert!(
version(cxx).contains(REQUIRED_CLANG_VERSION),
cxx_version.contains(REQUIRED_CLANG_VERSION),
"mismatched versions of cc and c++"
);
return (cc, cxx);
Expand Down

0 comments on commit bad1c21

Please sign in to comment.