@@ -270,6 +270,8 @@ pub struct Build {
270270 known_flag_support_status_cache : Arc < Mutex < HashMap < CompilerFlag , bool > > > ,
271271 ar_flags : Vec < Arc < str > > ,
272272 asm_flags : Vec < Arc < str > > ,
273+ c_flags : Vec < Arc < str > > ,
274+ cpp_flags : Vec < Arc < str > > ,
273275 no_default_flags : bool ,
274276 files : Vec < Arc < Path > > ,
275277 cpp : bool ,
@@ -393,6 +395,8 @@ impl Build {
393395 known_flag_support_status_cache : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
394396 ar_flags : Vec :: new ( ) ,
395397 asm_flags : Vec :: new ( ) ,
398+ c_flags : Vec :: new ( ) ,
399+ cpp_flags : Vec :: new ( ) ,
396400 no_default_flags : false ,
397401 files : Vec :: new ( ) ,
398402 shared_flag : None ,
@@ -569,6 +573,36 @@ impl Build {
569573 self
570574 }
571575
576+ /// Add an arbitrary flag to the invocation of the compiler for c files
577+ ///
578+ /// # Example
579+ ///
580+ /// ```no_run
581+ /// cc::Build::new()
582+ /// .file("src/foo.c")
583+ /// .c_flag("-std=c99")
584+ /// .compile("foo");
585+ /// ```
586+ pub fn c_flag ( & mut self , flag : & str ) -> & mut Build {
587+ self . c_flags . push ( flag. into ( ) ) ;
588+ self
589+ }
590+
591+ /// Add an arbitrary flag to the invocation of the compiler for cpp files
592+ ///
593+ /// # Example
594+ ///
595+ /// ```no_run
596+ /// cc::Build::new()
597+ /// .file("src/foo.cpp")
598+ /// .cpp_flag("-std=c++17")
599+ /// .compile("foo");
600+ /// ```
601+ pub fn cpp_flag ( & mut self , flag : & str ) -> & mut Build {
602+ self . cpp_flags . push ( flag. into ( ) ) ;
603+ self
604+ }
605+
572606 fn ensure_check_file ( & self ) -> Result < PathBuf , Error > {
573607 let out_dir = self . get_out_dir ( ) ?;
574608 let src = if self . cuda {
@@ -1828,6 +1862,14 @@ impl Build {
18281862 cmd. push_cc_arg ( warnings_to_errors_flag) ;
18291863 }
18301864
1865+ for flag in self . c_flags . iter ( ) {
1866+ cmd. c_args . push ( ( * * flag) . into ( ) ) ;
1867+ }
1868+
1869+ for flag in self . cpp_flags . iter ( ) {
1870+ cmd. cpp_args . push ( ( * * flag) . into ( ) ) ;
1871+ }
1872+
18311873 Ok ( cmd)
18321874 }
18331875
0 commit comments