Skip to content

Commit

Permalink
Check flag support before adding
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Oct 10, 2024
1 parent 75dff9b commit 0271f48
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
1 change: 1 addition & 0 deletions aws-lc-fips-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ bindgen = ["dep:bindgen"] # Generate the bindings on the targetted platform as a
cmake = "0.1.48"
dunce = "1.0"
fs_extra = "1.3"
cc = "1.0.100"

[target.'cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), any(target_os = "linux", target_os = "macos"), any(target_env = "gnu", target_env = "musl", target_env = "")))'.build-dependencies]
bindgen = { version = "0.69.2", optional = true }
Expand Down
28 changes: 23 additions & 5 deletions aws-lc-fips-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,29 @@ impl CmakeBuilder {
cmake_cfg.define("CMAKE_BUILD_TYPE", "relwithdebinfo");
} else {
cmake_cfg.define("CMAKE_BUILD_TYPE", "release");
if target_family() == "unix" || target_env() == "gnu" {
cmake_cfg.cflag(format!(
"-ffile-prefix-map={}=",
self.manifest_dir.display()
));
// TODO: Due to the nature of the FIPS build (e.g., its dynamic generation of
// assembly files and its custom compilation commands within CMake), not all
// source paths are stripped from the resulting binary.
emit_warning(
"NOTICE: Build environment source paths might be visible in release binary.",
);
let parent_dir = self.manifest_dir.parent();
if parent_dir.is_some() && (target_family() == "unix" || target_env() == "gnu") {
let parent_dir = parent_dir.unwrap();
let cc_build = cc::Build::new();
let flag = format!("-ffile-prefix-map={}=", parent_dir.display());
if let Ok(true) = cc_build.is_flag_supported(&flag) {
emit_warning(&format!("Using flag: {}", &flag));
cmake_cfg.asmflag(&flag);
cmake_cfg.cflag(&flag);
} else {
let flag = format!("-fdebug-prefix-map={}=", parent_dir.display());
if let Ok(true) = cc_build.is_flag_supported(&flag) {
emit_warning(&format!("Using flag: {}", &flag));
cmake_cfg.asmflag(&flag);
cmake_cfg.cflag(&flag);
}
}
}
}
} else if target_os() == "windows" {
Expand Down
20 changes: 12 additions & 8 deletions aws-lc-sys/builder/cc_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,19 @@ impl CcBuilder {
"AWS_LC_SYS_NO_ASM only allowed for debug builds!"
);
if compiler.is_like_gnu() || compiler.is_like_clang() {
let file_prefix_map_option =
format!("-ffile-prefix-map={}=", self.manifest_dir.display());
if let Ok(true) = cc_build.is_flag_supported(&file_prefix_map_option) {
cc_build.flag(file_prefix_map_option);
let flag = format!("-ffile-prefix-map={}=", self.manifest_dir.display());
if let Ok(true) = cc_build.is_flag_supported(&flag) {
emit_warning(&format!("Using flag: {}", &flag));
cc_build.flag(flag);
} else {
cc_build.flag_if_supported(format!(
"-fdebug-prefix-map={}=",
self.manifest_dir.display()
));
let flag = format!("-fdebug-prefix-map={}=", self.manifest_dir.display());
if let Ok(true) = cc_build.is_flag_supported(&flag) {
emit_warning("NOTICE: Build environment source paths might be visible in release binary.");
emit_warning(&format!("Using flag: {}", &flag));
cc_build.flag(flag);
} else {
emit_warning("NOTICE: Build environment source paths might be visible in release binary.");
}
}
}
}
Expand Down

0 comments on commit 0271f48

Please sign in to comment.