@@ -94,6 +94,7 @@ pub struct Build {
94
94
flags : Vec < String > ,
95
95
flags_supported : Vec < String > ,
96
96
known_flag_support_status : Arc < Mutex < HashMap < String , bool > > > ,
97
+ ar_flags : Vec < String > ,
97
98
no_default_flags : bool ,
98
99
files : Vec < PathBuf > ,
99
100
cpp : bool ,
@@ -283,6 +284,7 @@ impl Build {
283
284
flags : Vec :: new ( ) ,
284
285
flags_supported : Vec :: new ( ) ,
285
286
known_flag_support_status : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
287
+ ar_flags : Vec :: new ( ) ,
286
288
no_default_flags : false ,
287
289
files : Vec :: new ( ) ,
288
290
shared_flag : None ,
@@ -369,6 +371,23 @@ impl Build {
369
371
self
370
372
}
371
373
374
+ /// Add an arbitrary flag to the invocation of the compiler
375
+ ///
376
+ /// # Example
377
+ ///
378
+ /// ```no_run
379
+ /// cc::Build::new()
380
+ /// .file("src/foo.c")
381
+ /// .file("src/bar.c")
382
+ /// .ar_flag("/NODEFAULTLIB:libc.dll")
383
+ /// .compile("foo");
384
+ /// ```
385
+
386
+ pub fn ar_flag ( & mut self , flag : & str ) -> & mut Build {
387
+ self . ar_flags . push ( flag. to_string ( ) ) ;
388
+ self
389
+ }
390
+
372
391
fn ensure_check_file ( & self ) -> Result < PathBuf , Error > {
373
392
let out_dir = self . get_out_dir ( ) ?;
374
393
let src = if self . cuda {
@@ -1668,6 +1687,9 @@ impl Build {
1668
1687
let mut out = OsString :: from ( "-out:" ) ;
1669
1688
out. push ( dst) ;
1670
1689
cmd. arg ( out) . arg ( "-nologo" ) ;
1690
+ for flag in self . ar_flags . iter ( ) {
1691
+ cmd. arg ( flag) ;
1692
+ }
1671
1693
1672
1694
// Similar to https://github.com/rust-lang/rust/pull/47507
1673
1695
// and https://github.com/rust-lang/rust/pull/48548
@@ -1754,7 +1776,9 @@ impl Build {
1754
1776
// In any case if this doesn't end up getting read, it shouldn't
1755
1777
// cause that many issues!
1756
1778
ar. env ( "ZERO_AR_DATE" , "1" ) ;
1757
-
1779
+ for flag in self . ar_flags . iter ( ) {
1780
+ ar. arg ( flag) ;
1781
+ }
1758
1782
run (
1759
1783
ar. arg ( "crs" ) . arg ( dst) . args ( & objects) . args ( & self . objects ) ,
1760
1784
& cmd,
0 commit comments