Skip to content

Commit

Permalink
Fix compiler checks
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Mar 3, 2025
1 parent 2008eda commit 38ddd27
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions aws-lc-sys/builder/cc_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl CcBuilder {
build_options.push(BuildOption::std("c11"));
}
CStdRequested::None => {
if self.compiler_check("c11", "") {
if self.compiler_check("c11") {
build_options.push(BuildOption::std("c11"));
} else {
build_options.push(BuildOption::std("c99"));
Expand Down Expand Up @@ -356,7 +356,7 @@ impl CcBuilder {
for flag in lib.flags {
cc_build.flag(flag);
}
self.run_compiler_checks();
self.run_compiler_checks(&mut cc_build);

if let Some(prefix) = &self.build_prefix {
cc_build.compile(format!("{}_crypto", prefix.as_str()).as_str());
Expand All @@ -368,10 +368,9 @@ impl CcBuilder {
// This performs basic checks of compiler capabilities and sets an appropriate flag on success.
// This should be kept in alignment with the checks performed by AWS-LC's CMake build.
// See: https://github.com/search?q=repo%3Aaws%2Faws-lc%20check_compiler&type=code
fn compiler_check(&self, basename: &str, flag: &str) -> bool {
fn compiler_check(&self, basename: &str) -> bool {
let mut ret_val = false;
let output_dir = self.out_dir.join(format!("out-{basename}"));
let mut cc_build = self.create_builder();
let source_file = self
.manifest_dir
.join("aws-lc")
Expand All @@ -389,6 +388,7 @@ impl CcBuilder {
emit_warning("######");
emit_warning("######");
}
let mut cc_build = cc::Build::default();
cc_build
.file(source_file)
.warnings_into_errors(true)
Expand All @@ -401,9 +401,6 @@ impl CcBuilder {
let result = cc_build.try_compile_intermediates();

if result.is_ok() {
if !flag.is_empty() {
cc_build.define(flag, "1");
}
ret_val = true;
}
if fs::remove_dir_all(&output_dir).is_err() {
Expand Down Expand Up @@ -485,9 +482,13 @@ impl CcBuilder {
}
let _ = fs::remove_file(exec_path);
}
fn run_compiler_checks(&self) {
self.compiler_check("stdalign_check", "AWS_LC_STDALIGN_AVAILABLE");
self.compiler_check("builtin_swap_check", "AWS_LC_BUILTIN_SWAP_SUPPORTED");
fn run_compiler_checks(&self, cc_build: &mut cc::Build) {
if self.compiler_check("stdalign_check") {
cc_build.define("AWS_LC_STDALIGN_AVAILABLE", Some("1"));
}
if self.compiler_check("builtin_swap_check") {
cc_build.define("AWS_LC_BUILTIN_SWAP_SUPPORTED", Some("1"));
}
self.memcmp_check();
}
}
Expand Down

0 comments on commit 38ddd27

Please sign in to comment.