Skip to content

Commit 0eeafcc

Browse files
parthsanealexcrichton
authored andcommitted
Added public function to add flags to archiver
1 parent 047bf5b commit 0eeafcc

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/lib.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub struct Build {
9494
flags: Vec<String>,
9595
flags_supported: Vec<String>,
9696
known_flag_support_status: Arc<Mutex<HashMap<String, bool>>>,
97+
ar_flags: Vec<String>,
9798
no_default_flags: bool,
9899
files: Vec<PathBuf>,
99100
cpp: bool,
@@ -283,6 +284,7 @@ impl Build {
283284
flags: Vec::new(),
284285
flags_supported: Vec::new(),
285286
known_flag_support_status: Arc::new(Mutex::new(HashMap::new())),
287+
ar_flags: Vec::new(),
286288
no_default_flags: false,
287289
files: Vec::new(),
288290
shared_flag: None,
@@ -369,6 +371,23 @@ impl Build {
369371
self
370372
}
371373

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+
372391
fn ensure_check_file(&self) -> Result<PathBuf, Error> {
373392
let out_dir = self.get_out_dir()?;
374393
let src = if self.cuda {
@@ -1668,6 +1687,9 @@ impl Build {
16681687
let mut out = OsString::from("-out:");
16691688
out.push(dst);
16701689
cmd.arg(out).arg("-nologo");
1690+
for flag in self.ar_flags.iter() {
1691+
cmd.arg(flag);
1692+
}
16711693

16721694
// Similar to https://github.com/rust-lang/rust/pull/47507
16731695
// and https://github.com/rust-lang/rust/pull/48548
@@ -1754,7 +1776,9 @@ impl Build {
17541776
// In any case if this doesn't end up getting read, it shouldn't
17551777
// cause that many issues!
17561778
ar.env("ZERO_AR_DATE", "1");
1757-
1779+
for flag in self.ar_flags.iter() {
1780+
ar.arg(flag);
1781+
}
17581782
run(
17591783
ar.arg("crs").arg(dst).args(&objects).args(&self.objects),
17601784
&cmd,

0 commit comments

Comments
 (0)