Skip to content

Commit

Permalink
Preserve optimization flags
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Mar 3, 2025
1 parent 38ddd27 commit 4ddcbb0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions aws-lc-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ impl CmakeBuilder {
env::set_var("CFLAGS", cflags);
}

// cmake-rs has logic that strip Optimization/Debug options that be passed via CFLAGS.
// This breaks the build for build configurations that generate warnings when optimizations
// are disabled.
self.preserve_cflag_optimization_flags(&mut cmake_cfg);

// Allow environment to specify CMake toolchain.
let toolchain_var_name = format!("CMAKE_TOOLCHAIN_FILE_{}", target_underscored());
if let Some(toolchain) =
Expand Down Expand Up @@ -206,6 +211,18 @@ impl CmakeBuilder {
cmake_cfg
}

fn preserve_cflag_optimization_flags(&self, cmake_cfg: &mut cmake::Config) {
if let Ok(cflags) = env::var("CFLAGS") {
let split = cflags.split("\\s+");
for arg in split {
if arg.starts_with("-O") || arg.starts_with("/O") {
emit_warning(&format!("Preserving optimization flag: {arg}"));
cmake_cfg.cflag(arg);
}
}
}
}

#[allow(clippy::unused_self)]
fn configure_android(&self, _cmake_cfg: &mut cmake::Config) {
// If we leave CMAKE_SYSTEM_PROCESSOR unset, then cmake-rs should handle properly setting
Expand Down

0 comments on commit 4ddcbb0

Please sign in to comment.