@@ -63,6 +63,25 @@ impl LlvmBuildStatus {
6363 }
6464}
6565
66+ /// Allows each step to add C/Cxx flags which are only used for a specific cmake invocation.
67+ #[ derive( Debug , Clone , Default ) ]
68+ struct CcFlags {
69+ /// Additional values for CMAKE_CC_FLAGS, to be added before all other values.
70+ cflags : OsString ,
71+ /// Additional values for CMAKE_CXX_FLAGS, to be added before all other values.
72+ cxxflags : OsString ,
73+ }
74+
75+ impl CcFlags {
76+ fn push_all ( & mut self , s : impl AsRef < OsStr > ) {
77+ let s = s. as_ref ( ) ;
78+ self . cflags . push ( " " ) ;
79+ self . cflags . push ( s) ;
80+ self . cxxflags . push ( " " ) ;
81+ self . cxxflags . push ( s) ;
82+ }
83+ }
84+
6685/// Linker flags to pass to LLVM's CMake invocation.
6786#[ derive( Debug , Clone , Default ) ]
6887struct LdFlags {
@@ -527,7 +546,7 @@ impl Step for Llvm {
527546 cfg. define ( "LLVM_VERSION_SUFFIX" , suffix) ;
528547 }
529548
530- configure_cmake ( builder, target, & mut cfg, true , ldflags, & [ ] ) ;
549+ configure_cmake ( builder, target, & mut cfg, true , ldflags, CcFlags :: default ( ) , & [ ] ) ;
531550 configure_llvm ( builder, target, & mut cfg) ;
532551
533552 for ( key, val) in & builder. config . llvm_build_config {
@@ -633,6 +652,7 @@ fn configure_cmake(
633652 cfg : & mut cmake:: Config ,
634653 use_compiler_launcher : bool ,
635654 mut ldflags : LdFlags ,
655+ ccflags : CcFlags ,
636656 suppressed_compiler_flag_prefixes : & [ & str ] ,
637657) {
638658 // Do not print installation messages for up-to-date files.
@@ -761,23 +781,21 @@ fn configure_cmake(
761781 . define ( "CMAKE_ASM_COMPILER" , sanitize_cc ( & cc) ) ;
762782
763783 cfg. build_arg ( "-j" ) . build_arg ( builder. jobs ( ) . to_string ( ) ) ;
784+ let mut cflags = ccflags. cflags . clone ( ) ;
764785 // FIXME(madsmtm): Allow `cmake-rs` to select flags by itself by passing
765786 // our flags via `.cflag`/`.cxxflag` instead.
766787 //
767788 // Needs `suppressed_compiler_flag_prefixes` to be gone, and hence
768789 // https://github.com/llvm/llvm-project/issues/88780 to be fixed.
769- let mut cflags : OsString = builder
790+ for flag in builder
770791 . cc_handled_clags ( target, CLang :: C )
771792 . into_iter ( )
772793 . chain ( builder. cc_unhandled_cflags ( target, GitRepo :: Llvm , CLang :: C ) )
773- . filter ( |flag| {
774- !suppressed_compiler_flag_prefixes
775- . iter ( )
776- . any ( |suppressed_prefix| flag. starts_with ( suppressed_prefix) )
777- } )
778- . collect :: < Vec < String > > ( )
779- . join ( " " )
780- . into ( ) ;
794+ . filter ( |flag| !suppressed_compiler_flag_prefixes. iter ( ) . any ( |p| flag. starts_with ( p) ) )
795+ {
796+ cflags. push ( " " ) ;
797+ cflags. push ( flag) ;
798+ }
781799 if let Some ( ref s) = builder. config . llvm_cflags {
782800 cflags. push ( " " ) ;
783801 cflags. push ( s) ;
@@ -789,7 +807,8 @@ fn configure_cmake(
789807 cflags. push ( format ! ( " --target={target}" ) ) ;
790808 }
791809 cfg. define ( "CMAKE_C_FLAGS" , cflags) ;
792- let mut cxxflags: OsString = builder
810+ let mut cxxflags = ccflags. cxxflags . clone ( ) ;
811+ for flag in builder
793812 . cc_handled_clags ( target, CLang :: Cxx )
794813 . into_iter ( )
795814 . chain ( builder. cc_unhandled_cflags ( target, GitRepo :: Llvm , CLang :: Cxx ) )
@@ -798,9 +817,10 @@ fn configure_cmake(
798817 . iter ( )
799818 . any ( |suppressed_prefix| flag. starts_with ( suppressed_prefix) )
800819 } )
801- . collect :: < Vec < String > > ( )
802- . join ( " " )
803- . into ( ) ;
820+ {
821+ cxxflags. push ( " " ) ;
822+ cxxflags. push ( flag) ;
823+ }
804824 if let Some ( ref s) = builder. config . llvm_cxxflags {
805825 cxxflags. push ( " " ) ;
806826 cxxflags. push ( s) ;
@@ -811,6 +831,7 @@ fn configure_cmake(
811831 if builder. config . llvm_clang_cl . is_some ( ) {
812832 cxxflags. push ( format ! ( " --target={target}" ) ) ;
813833 }
834+
814835 cfg. define ( "CMAKE_CXX_FLAGS" , cxxflags) ;
815836 if let Some ( ar) = builder. ar ( target)
816837 && ar. is_absolute ( )
@@ -970,7 +991,13 @@ impl Step for Enzyme {
970991
971992 builder. config . update_submodule ( "src/tools/enzyme" ) ;
972993 let mut cfg = cmake:: Config :: new ( builder. src . join ( "src/tools/enzyme/enzyme/" ) ) ;
973- configure_cmake ( builder, target, & mut cfg, true , LdFlags :: default ( ) , & [ ] ) ;
994+
995+ let mut cflags = CcFlags :: default ( ) ;
996+ // Enzyme devs maintain upstream compability, but only fix deprecations when they are about
997+ // to turn into a hard error. As such, Enzyme generates various warnings which could make it
998+ // hard to spot more relevant issues.
999+ cflags. push_all ( "-Wno-deprecated" ) ;
1000+ configure_cmake ( builder, target, & mut cfg, true , LdFlags :: default ( ) , cflags, & [ ] ) ;
9741001
9751002 // Re-use the same flags as llvm to control the level of debug information
9761003 // generated by Enzyme.
@@ -1090,7 +1117,7 @@ impl Step for Lld {
10901117 ldflags. push_all ( "-Wl,-rpath,'$ORIGIN/../../../'" ) ;
10911118 }
10921119
1093- configure_cmake ( builder, target, & mut cfg, true , ldflags, & [ ] ) ;
1120+ configure_cmake ( builder, target, & mut cfg, true , ldflags, CcFlags :: default ( ) , & [ ] ) ;
10941121 configure_llvm ( builder, target, & mut cfg) ;
10951122
10961123 // Re-use the same flags as llvm to control the level of debug information
@@ -1213,6 +1240,7 @@ impl Step for Sanitizers {
12131240 & mut cfg,
12141241 use_compiler_launcher,
12151242 LdFlags :: default ( ) ,
1243+ CcFlags :: default ( ) ,
12161244 suppressed_compiler_flag_prefixes,
12171245 ) ;
12181246
0 commit comments