Skip to content

Commit fa33226

Browse files
authored
Avoid fips MacOS failure due to -Woverriding-option (#678)
* Avoid fips MacOS failure due to -Woverriding-option * Also fix for aws-lc-sys * Map ???-alpine-linux-musl to an effective target * Allow environment to set crate-specific compiler
1 parent b37d2b5 commit fa33226

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

aws-lc-fips-sys/builder/cmake_builder.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
use crate::OutputLib::{Crypto, RustWrapper, Ssl};
55
use crate::{
6-
cargo_env, emit_rustc_cfg, emit_warning, execute_command, is_cpu_jitter_entropy, is_no_asm,
7-
option_env, target, target_arch, target_env, target_family, target_os, target_underscored,
8-
target_vendor, OutputLibType, TestCommandResult,
6+
cargo_env, effective_target, emit_rustc_cfg, emit_warning, execute_command,
7+
is_cpu_jitter_entropy, is_no_asm, option_env, target_arch, target_env, target_family,
8+
target_os, target_underscored, target_vendor, OutputLibType, TestCommandResult,
99
};
1010
use std::collections::HashMap;
1111
use std::env;
@@ -111,6 +111,15 @@ impl CmakeBuilder {
111111
emit_rustc_cfg("cpu_jitter_entropy");
112112
}
113113

114+
if let Some(cc) = option_env!("AWS_LC_FIPS_SYS_CC") {
115+
env::set_var("CC", cc);
116+
emit_warning(&format!("Setting CC: {}", cc));
117+
}
118+
if let Some(cxx) = option_env!("AWS_LC_FIPS_SYS_CXX") {
119+
env::set_var("CXX", cxx);
120+
emit_warning(&format!("Setting CXX: {}", cxx));
121+
}
122+
114123
let cc_build = cc::Build::new();
115124
let opt_level = cargo_env("OPT_LEVEL");
116125
if opt_level.ne("0") {
@@ -207,12 +216,13 @@ impl CmakeBuilder {
207216
return cmake_cfg;
208217
}
209218

210-
// If the build environment vendor is Apple
211-
#[cfg(target_vendor = "apple")]
212-
{
213-
const NO_OVERRIDE_T_OPTION: &str = "-Wno-overriding-t-option";
214-
if let Ok(true) = cc_build.is_flag_supported(NO_OVERRIDE_T_OPTION) {
215-
cmake_cfg.cflag(NO_OVERRIDE_T_OPTION);
219+
if target_vendor() == "apple" {
220+
let disable_warnings: [&str; 2] =
221+
["-Wno-overriding-t-option", "-Wno-overriding-option"];
222+
for disabler in disable_warnings {
223+
if let Ok(true) = cc_build.is_flag_supported(disabler) {
224+
cmake_cfg.cflag(disabler);
225+
}
216226
}
217227
if target_arch() == "aarch64" {
218228
cmake_cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64");
@@ -222,12 +232,11 @@ impl CmakeBuilder {
222232
cmake_cfg.define("CMAKE_OSX_ARCHITECTURES", "x86_64");
223233
cmake_cfg.define("CMAKE_SYSTEM_PROCESSOR", "x86_64");
224234
}
225-
}
226-
227-
if target_vendor() == "apple" && target_os().trim() == "ios" {
228-
cmake_cfg.define("CMAKE_SYSTEM_NAME", "iOS");
229-
if target().trim().ends_with("-ios-sim") {
230-
cmake_cfg.define("CMAKE_OSX_SYSROOT", "iphonesimulator");
235+
if target_os().trim() == "ios" {
236+
cmake_cfg.define("CMAKE_SYSTEM_NAME", "iOS");
237+
if effective_target().trim().ends_with("-ios-sim") {
238+
cmake_cfg.define("CMAKE_OSX_SYSROOT", "iphonesimulator");
239+
}
231240
}
232241
}
233242

@@ -268,6 +277,7 @@ impl CmakeBuilder {
268277
if major > 13 {
269278
// TODO: Update when FIPS GCC 14 build is fixed
270279
emit_warning("WARNING: FIPS build is known to fail on GCC >= 14. See: https://github.com/aws/aws-lc-rs/issues/569");
280+
emit_warning("Consider specifying a different compiler in your environment by setting `CC` or: `export AWS_LC_FIPS_SYS_CC=clang`");
271281
return Some(false);
272282
}
273283
}
@@ -307,7 +317,7 @@ impl CmakeBuilder {
307317
);
308318
let mut cflags = vec!["-Wno-unused-command-line-argument"];
309319
let mut asmflags = vec![];
310-
match target().as_str() {
320+
match effective_target().as_str() {
311321
"aarch64-unknown-linux-ohos" => {}
312322
"armv7-unknown-linux-ohos" => {
313323
const ARM7_FLAGS: [&str; 6] = [

aws-lc-fips-sys/builder/main.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ fn prefix_string() -> String {
212212

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

218218
pub(crate) struct TestCommandResult {
@@ -327,14 +327,24 @@ fn target_vendor() -> String {
327327
cargo_env("CARGO_CFG_TARGET_VENDOR")
328328
}
329329

330+
#[allow(unused)]
331+
fn effective_target() -> String {
332+
let target = target();
333+
match target.as_str() {
334+
"x86_64-alpine-linux-musl" => "x86_64-unknown-linux-musl".to_string(),
335+
"aarch64-alpine-linux-musl" => "aarch64-unknown-linux-musl".to_string(),
336+
_ => target,
337+
}
338+
}
339+
330340
#[allow(unused)]
331341
fn target() -> String {
332342
cargo_env("TARGET")
333343
}
334344

335345
#[allow(unused)]
336346
fn target_underscored() -> String {
337-
target().replace('-', "_")
347+
effective_target().replace('-', "_")
338348
}
339349

340350
fn out_dir() -> PathBuf {
@@ -386,7 +396,7 @@ fn initialize() {
386396
|| is_pregenerating_bindings()
387397
{
388398
// We only set the PREGENERATED flag when we know pregenerated bindings are available.
389-
let target = target();
399+
let target = effective_target();
390400
let supported_platform = match target.as_str() {
391401
"x86_64-unknown-linux-gnu"
392402
| "aarch64-unknown-linux-gnu"
@@ -470,7 +480,7 @@ bindgen_available!(
470480
if internal_bindgen_supported() && !is_external_bindgen() {
471481
emit_warning(&format!(
472482
"Generating bindings - internal bindgen. Platform: {}",
473-
target()
483+
effective_target()
474484
));
475485
let gen_bindings_path = out_dir().join("bindings.rs");
476486
generate_bindings(manifest_dir, prefix, &gen_bindings_path);
@@ -703,7 +713,7 @@ fn invoke_external_bindgen(
703713
verify_bindgen()?;
704714
emit_warning(&format!(
705715
"Generating bindings - external bindgen. Platform: '{}' Prefix: '{:?}'",
706-
target(),
716+
effective_target(),
707717
&options.build_prefix
708718
));
709719

aws-lc-sys/builder/cc_builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ impl CcBuilder {
194194
// clang: error: overriding '-mmacosx-version-min=13.7' option with '--target=x86_64-apple-macosx14.2' [-Werror,-Woverriding-t-option]
195195
// ```
196196
cc_build.flag_if_supported("-Wno-overriding-t-option");
197+
cc_build.flag_if_supported("-Wno-overriding-option");
197198
}
198199

199200
cc_build

0 commit comments

Comments
 (0)