Skip to content

Commit cd0ab51

Browse files
committed
Make aws-lc-fips-sys's config CMAKE_BUILD_TYPE logic same with aws-lc-sys
1 parent ce17e88 commit cd0ab51

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

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

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -121,46 +121,37 @@ impl CmakeBuilder {
121121
}
122122

123123
let cc_build = cc::Build::new();
124-
let opt_level = cargo_env("OPT_LEVEL");
125-
if opt_level.ne("0") {
126-
if opt_level.eq("1") || opt_level.eq("2") {
127-
cmake_cfg.define("CMAKE_BUILD_TYPE", "relwithdebinfo");
128-
} else {
129-
if opt_level.eq("s") || opt_level.eq("z") {
130-
cmake_cfg.define("CMAKE_BUILD_TYPE", "minsizerel");
131-
} else {
132-
cmake_cfg.define("CMAKE_BUILD_TYPE", "release");
133-
}
134-
// TODO: Due to the nature of the FIPS build (e.g., its dynamic generation of
135-
// assembly files and its custom compilation commands within CMake), not all
136-
// source paths are stripped from the resulting binary.
137-
emit_warning(
138-
"NOTICE: Build environment source paths might be visible in release binary.",
139-
);
140-
if let Some(parent_dir) = self.manifest_dir.parent() {
141-
if target_family() == "unix" || target_env() == "gnu" {
142-
let flag = format!("\"-ffile-prefix-map={}=\"", parent_dir.display());
124+
let cmake_prefile = cmake_cfg.get_profile();
125+
if matches!(cmake_prefile, "Release" | "MinSizeRel") {
126+
// TODO: Due to the nature of the FIPS build (e.g., its dynamic generation of
127+
// assembly files and its custom compilation commands within CMake), not all
128+
// source paths are stripped from the resulting binary.
129+
emit_warning(
130+
"NOTICE: Build environment source paths might be visible in release binary.",
131+
);
132+
if let Some(parent_dir) = self.manifest_dir.parent() {
133+
if target_family() == "unix" || target_env() == "gnu" {
134+
let flag = format!("\"-ffile-prefix-map={}=\"", parent_dir.display());
135+
if let Ok(true) = cc_build.is_flag_supported(&flag) {
136+
emit_warning(&format!("Using flag: {}", &flag));
137+
cmake_cfg.asmflag(&flag);
138+
cmake_cfg.cflag(&flag);
139+
} else {
140+
let flag = format!("\"-fdebug-prefix-map={}=\"", parent_dir.display());
143141
if let Ok(true) = cc_build.is_flag_supported(&flag) {
144142
emit_warning(&format!("Using flag: {}", &flag));
145143
cmake_cfg.asmflag(&flag);
146144
cmake_cfg.cflag(&flag);
147-
} else {
148-
let flag = format!("\"-fdebug-prefix-map={}=\"", parent_dir.display());
149-
if let Ok(true) = cc_build.is_flag_supported(&flag) {
150-
emit_warning(&format!("Using flag: {}", &flag));
151-
cmake_cfg.asmflag(&flag);
152-
cmake_cfg.cflag(&flag);
153-
}
154145
}
155146
}
156147
}
157148
}
158-
} else if target_os() == "windows" {
149+
}
150+
151+
if target_os() == "windows" {
159152
// The Windows/FIPS build rejects "debug" profile
160153
// https://github.com/aws/aws-lc/blob/main/CMakeLists.txt#L656
161-
cmake_cfg.define("CMAKE_BUILD_TYPE", "relwithdebinfo");
162-
} else {
163-
cmake_cfg.define("CMAKE_BUILD_TYPE", "debug");
154+
cmake_cfg.profile("RelWithDebInfo");
164155
}
165156

166157
if is_crt_static() {

0 commit comments

Comments
 (0)