File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -209,6 +209,12 @@ impl CmakeBuilder {
209209 cmake_cfg. define ( "ASAN" , "1" ) ;
210210 }
211211
212+ // cmake-rs has logic that strips Optimization/Debug options that are passed via CFLAGS:
213+ // https://github.com/rust-lang/cmake-rs/issues/240
214+ // This breaks build configurations that generate warnings when optimizations
215+ // are disabled.
216+ Self :: preserve_cflag_optimization_flags ( & mut cmake_cfg) ;
217+
212218 // Allow environment to specify CMake toolchain.
213219 if let Some ( toolchain) = option_env ( "CMAKE_TOOLCHAIN_FILE" ) . or ( option_env ( format ! (
214220 "CMAKE_TOOLCHAIN_FILE_{}" ,
@@ -277,6 +283,18 @@ impl CmakeBuilder {
277283 cmake_cfg
278284 }
279285
286+ fn preserve_cflag_optimization_flags ( cmake_cfg : & mut cmake:: Config ) {
287+ if let Ok ( cflags) = env:: var ( "CFLAGS" ) {
288+ let split = cflags. split_whitespace ( ) ;
289+ for arg in split {
290+ if arg. starts_with ( "-O" ) || arg. starts_with ( "/O" ) {
291+ emit_warning ( & format ! ( "Preserving optimization flag: {arg}" ) ) ;
292+ cmake_cfg. cflag ( arg) ;
293+ }
294+ }
295+ }
296+ }
297+
280298 fn verify_compiler_support ( compiler : & cc:: Tool ) -> Option < bool > {
281299 let compiler_path = compiler. path ( ) ;
282300
You can’t perform that action at this time.
0 commit comments