Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid fips MacOS failure due to -Woverriding-option #678

Merged
merged 4 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions aws-lc-fips-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

use crate::OutputLib::{Crypto, RustWrapper, Ssl};
use crate::{
cargo_env, emit_rustc_cfg, emit_warning, execute_command, is_cpu_jitter_entropy, is_no_asm,
option_env, target, target_arch, target_env, target_family, target_os, target_underscored,
target_vendor, OutputLibType, TestCommandResult,
cargo_env, effective_target, emit_rustc_cfg, emit_warning, execute_command,
is_cpu_jitter_entropy, is_no_asm, option_env, target_arch, target_env, target_family,
target_os, target_underscored, target_vendor, OutputLibType, TestCommandResult,
};
use std::collections::HashMap;
use std::env;
Expand Down Expand Up @@ -111,6 +111,15 @@ impl CmakeBuilder {
emit_rustc_cfg("cpu_jitter_entropy");
}

if let Some(cc) = option_env!("AWS_LC_FIPS_SYS_CC") {
env::set_var("CC", cc);
emit_warning(&format!("Setting CC: {}", cc));
}
if let Some(cxx) = option_env!("AWS_LC_FIPS_SYS_CXX") {
env::set_var("CXX", cxx);
emit_warning(&format!("Setting CXX: {}", cxx));
}

let cc_build = cc::Build::new();
let opt_level = cargo_env("OPT_LEVEL");
if opt_level.ne("0") {
Expand Down Expand Up @@ -207,12 +216,13 @@ impl CmakeBuilder {
return cmake_cfg;
}

// If the build environment vendor is Apple
#[cfg(target_vendor = "apple")]
{
const NO_OVERRIDE_T_OPTION: &str = "-Wno-overriding-t-option";
if let Ok(true) = cc_build.is_flag_supported(NO_OVERRIDE_T_OPTION) {
cmake_cfg.cflag(NO_OVERRIDE_T_OPTION);
if target_vendor() == "apple" {
let disable_warnings: [&str; 2] =
["-Wno-overriding-t-option", "-Wno-overriding-option"];
for disabler in disable_warnings {
if let Ok(true) = cc_build.is_flag_supported(disabler) {
cmake_cfg.cflag(disabler);
}
}
if target_arch() == "aarch64" {
cmake_cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64");
Expand All @@ -222,12 +232,11 @@ impl CmakeBuilder {
cmake_cfg.define("CMAKE_OSX_ARCHITECTURES", "x86_64");
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "x86_64");
}
}

if target_vendor() == "apple" && target_os().trim() == "ios" {
cmake_cfg.define("CMAKE_SYSTEM_NAME", "iOS");
if target().trim().ends_with("-ios-sim") {
cmake_cfg.define("CMAKE_OSX_SYSROOT", "iphonesimulator");
if target_os().trim() == "ios" {
cmake_cfg.define("CMAKE_SYSTEM_NAME", "iOS");
if effective_target().trim().ends_with("-ios-sim") {
cmake_cfg.define("CMAKE_OSX_SYSROOT", "iphonesimulator");
}
}
}

Expand Down Expand Up @@ -268,6 +277,7 @@ impl CmakeBuilder {
if major > 13 {
// TODO: Update when FIPS GCC 14 build is fixed
emit_warning("WARNING: FIPS build is known to fail on GCC >= 14. See: https://github.com/aws/aws-lc-rs/issues/569");
emit_warning("Consider specifying a different compiler in your environment by setting `CC` or: `export AWS_LC_FIPS_SYS_CC=clang`");
return Some(false);
}
}
Expand Down Expand Up @@ -307,7 +317,7 @@ impl CmakeBuilder {
);
let mut cflags = vec!["-Wno-unused-command-line-argument"];
let mut asmflags = vec![];
match target().as_str() {
match effective_target().as_str() {
"aarch64-unknown-linux-ohos" => {}
"armv7-unknown-linux-ohos" => {
const ARM7_FLAGS: [&str; 6] = [
Expand Down
20 changes: 15 additions & 5 deletions aws-lc-fips-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ fn prefix_string() -> String {

#[cfg(feature = "bindgen")]
fn target_platform_prefix(name: &str) -> String {
format!("{}_{}", target().replace('-', "_"), name)
format!("{}_{}", effective_target().replace('-', "_"), name)
}

pub(crate) struct TestCommandResult {
Expand Down Expand Up @@ -327,14 +327,24 @@ fn target_vendor() -> String {
cargo_env("CARGO_CFG_TARGET_VENDOR")
}

#[allow(unused)]
fn effective_target() -> String {
let target = target();
match target.as_str() {
"x86_64-alpine-linux-musl" => "x86_64-unknown-linux-musl".to_string(),
"aarch64-alpine-linux-musl" => "aarch64-unknown-linux-musl".to_string(),
_ => target,
}
}

#[allow(unused)]
fn target() -> String {
cargo_env("TARGET")
}

#[allow(unused)]
fn target_underscored() -> String {
target().replace('-', "_")
effective_target().replace('-', "_")
}

fn out_dir() -> PathBuf {
Expand Down Expand Up @@ -386,7 +396,7 @@ fn initialize() {
|| is_pregenerating_bindings()
{
// We only set the PREGENERATED flag when we know pregenerated bindings are available.
let target = target();
let target = effective_target();
let supported_platform = match target.as_str() {
"x86_64-unknown-linux-gnu"
| "aarch64-unknown-linux-gnu"
Expand Down Expand Up @@ -470,7 +480,7 @@ bindgen_available!(
if internal_bindgen_supported() && !is_external_bindgen() {
emit_warning(&format!(
"Generating bindings - internal bindgen. Platform: {}",
target()
effective_target()
));
let gen_bindings_path = out_dir().join("bindings.rs");
generate_bindings(manifest_dir, prefix, &gen_bindings_path);
Expand Down Expand Up @@ -703,7 +713,7 @@ fn invoke_external_bindgen(
verify_bindgen()?;
emit_warning(&format!(
"Generating bindings - external bindgen. Platform: '{}' Prefix: '{:?}'",
target(),
effective_target(),
&options.build_prefix
));

Expand Down
1 change: 1 addition & 0 deletions aws-lc-sys/builder/cc_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ impl CcBuilder {
// clang: error: overriding '-mmacosx-version-min=13.7' option with '--target=x86_64-apple-macosx14.2' [-Werror,-Woverriding-t-option]
// ```
cc_build.flag_if_supported("-Wno-overriding-t-option");
cc_build.flag_if_supported("-Wno-overriding-option");
}

cc_build
Expand Down
Loading