@@ -265,6 +265,8 @@ pub struct Build {
265265 known_flag_support_status : Arc < Mutex < HashMap < String , bool > > > ,
266266 ar_flags : Vec < Arc < str > > ,
267267 asm_flags : Vec < Arc < str > > ,
268+ c_flags : Vec < Arc < str > > ,
269+ cpp_flags : Vec < Arc < str > > ,
268270 no_default_flags : bool ,
269271 files : Vec < Arc < Path > > ,
270272 cpp : bool ,
@@ -388,6 +390,8 @@ impl Build {
388390 known_flag_support_status : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
389391 ar_flags : Vec :: new ( ) ,
390392 asm_flags : Vec :: new ( ) ,
393+ c_flags : Vec :: new ( ) ,
394+ cpp_flags : Vec :: new ( ) ,
391395 no_default_flags : false ,
392396 files : Vec :: new ( ) ,
393397 shared_flag : None ,
@@ -564,6 +568,36 @@ impl Build {
564568 self
565569 }
566570
571+ /// Add an arbitrary flag to the invocation of the compiler for c files
572+ ///
573+ /// # Example
574+ ///
575+ /// ```no_run
576+ /// cc::Build::new()
577+ /// .file("src/foo.c")
578+ /// .c_flag("-std=c99")
579+ /// .compile("foo");
580+ /// ```
581+ pub fn c_flag ( & mut self , flag : & str ) -> & mut Build {
582+ self . c_flags . push ( flag. into ( ) ) ;
583+ self
584+ }
585+
586+ /// Add an arbitrary flag to the invocation of the compiler for cpp files
587+ ///
588+ /// # Example
589+ ///
590+ /// ```no_run
591+ /// cc::Build::new()
592+ /// .file("src/foo.cpp")
593+ /// .cpp_flag("-std=c++17")
594+ /// .compile("foo");
595+ /// ```
596+ pub fn cpp_flag ( & mut self , flag : & str ) -> & mut Build {
597+ self . cpp_flags . push ( flag. into ( ) ) ;
598+ self
599+ }
600+
567601 fn ensure_check_file ( & self ) -> Result < PathBuf , Error > {
568602 let out_dir = self . get_out_dir ( ) ?;
569603 let src = if self . cuda {
@@ -1790,6 +1824,14 @@ impl Build {
17901824 cmd. push_cc_arg ( warnings_to_errors_flag) ;
17911825 }
17921826
1827+ for flag in self . c_flags . iter ( ) {
1828+ cmd. c_args . push ( ( * * flag) . into ( ) ) ;
1829+ }
1830+
1831+ for flag in self . cpp_flags . iter ( ) {
1832+ cmd. cpp_args . push ( ( * * flag) . into ( ) ) ;
1833+ }
1834+
17931835 Ok ( cmd)
17941836 }
17951837
0 commit comments