@@ -270,6 +270,8 @@ pub struct Build {
270
270
known_flag_support_status_cache : Arc < Mutex < HashMap < CompilerFlag , bool > > > ,
271
271
ar_flags : Vec < Arc < str > > ,
272
272
asm_flags : Vec < Arc < str > > ,
273
+ c_flags : Vec < Arc < str > > ,
274
+ cpp_flags : Vec < Arc < str > > ,
273
275
no_default_flags : bool ,
274
276
files : Vec < Arc < Path > > ,
275
277
cpp : bool ,
@@ -393,6 +395,8 @@ impl Build {
393
395
known_flag_support_status_cache : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
394
396
ar_flags : Vec :: new ( ) ,
395
397
asm_flags : Vec :: new ( ) ,
398
+ c_flags : Vec :: new ( ) ,
399
+ cpp_flags : Vec :: new ( ) ,
396
400
no_default_flags : false ,
397
401
files : Vec :: new ( ) ,
398
402
shared_flag : None ,
@@ -569,6 +573,36 @@ impl Build {
569
573
self
570
574
}
571
575
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
+
572
606
fn ensure_check_file ( & self ) -> Result < PathBuf , Error > {
573
607
let out_dir = self . get_out_dir ( ) ?;
574
608
let src = if self . cuda {
@@ -1828,6 +1862,14 @@ impl Build {
1828
1862
cmd. push_cc_arg ( warnings_to_errors_flag) ;
1829
1863
}
1830
1864
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
+
1831
1873
Ok ( cmd)
1832
1874
}
1833
1875
0 commit comments