@@ -265,6 +265,8 @@ pub struct Build {
265
265
known_flag_support_status : Arc < Mutex < HashMap < String , bool > > > ,
266
266
ar_flags : Vec < Arc < str > > ,
267
267
asm_flags : Vec < Arc < str > > ,
268
+ c_flags : Vec < Arc < str > > ,
269
+ cpp_flags : Vec < Arc < str > > ,
268
270
no_default_flags : bool ,
269
271
files : Vec < Arc < Path > > ,
270
272
cpp : bool ,
@@ -388,6 +390,8 @@ impl Build {
388
390
known_flag_support_status : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
389
391
ar_flags : Vec :: new ( ) ,
390
392
asm_flags : Vec :: new ( ) ,
393
+ c_flags : Vec :: new ( ) ,
394
+ cpp_flags : Vec :: new ( ) ,
391
395
no_default_flags : false ,
392
396
files : Vec :: new ( ) ,
393
397
shared_flag : None ,
@@ -564,6 +568,36 @@ impl Build {
564
568
self
565
569
}
566
570
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
+
567
601
fn ensure_check_file ( & self ) -> Result < PathBuf , Error > {
568
602
let out_dir = self . get_out_dir ( ) ?;
569
603
let src = if self . cuda {
@@ -1790,6 +1824,14 @@ impl Build {
1790
1824
cmd. push_cc_arg ( warnings_to_errors_flag) ;
1791
1825
}
1792
1826
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
+
1793
1835
Ok ( cmd)
1794
1836
}
1795
1837
0 commit comments