From 0eeafcc903059507f1e5a2ef2c2cb008cce26b02 Mon Sep 17 00:00:00 2001 From: Parth Sane Date: Mon, 14 Oct 2019 13:04:39 +0530 Subject: [PATCH] Added public function to add flags to archiver --- src/lib.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d546bda..4c485fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,6 +94,7 @@ pub struct Build { flags: Vec, flags_supported: Vec, known_flag_support_status: Arc>>, + ar_flags: Vec, no_default_flags: bool, files: Vec, cpp: bool, @@ -283,6 +284,7 @@ impl Build { flags: Vec::new(), flags_supported: Vec::new(), known_flag_support_status: Arc::new(Mutex::new(HashMap::new())), + ar_flags: Vec::new(), no_default_flags: false, files: Vec::new(), shared_flag: None, @@ -369,6 +371,23 @@ impl Build { self } + /// Add an arbitrary flag to the invocation of the compiler + /// + /// # Example + /// + /// ```no_run + /// cc::Build::new() + /// .file("src/foo.c") + /// .file("src/bar.c") + /// .ar_flag("/NODEFAULTLIB:libc.dll") + /// .compile("foo"); + /// ``` + + pub fn ar_flag(&mut self, flag: &str) -> &mut Build { + self.ar_flags.push(flag.to_string()); + self + } + fn ensure_check_file(&self) -> Result { let out_dir = self.get_out_dir()?; let src = if self.cuda { @@ -1668,6 +1687,9 @@ impl Build { let mut out = OsString::from("-out:"); out.push(dst); cmd.arg(out).arg("-nologo"); + for flag in self.ar_flags.iter() { + cmd.arg(flag); + } // Similar to https://github.com/rust-lang/rust/pull/47507 // and https://github.com/rust-lang/rust/pull/48548 @@ -1754,7 +1776,9 @@ impl Build { // In any case if this doesn't end up getting read, it shouldn't // cause that many issues! ar.env("ZERO_AR_DATE", "1"); - + for flag in self.ar_flags.iter() { + ar.arg(flag); + } run( ar.arg("crs").arg(dst).args(&objects).args(&self.objects), &cmd,