Skip to content

Commit f50ff26

Browse files
Add flags method to cc::Build for adding multiple flags (#1466)
1 parent 0342d85 commit f50ff26

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,27 @@ impl Build {
561561
self
562562
}
563563

564+
/// Add multiple flags to the invocation of the compiler.
565+
/// This is equivalent to calling [`flag`](Self::flag) for each item in the iterator.
566+
///
567+
/// # Example
568+
/// ```no_run
569+
/// cc::Build::new()
570+
/// .file("src/foo.c")
571+
/// .flags(["-Wall", "-Wextra"])
572+
/// .compile("foo");
573+
/// ```
574+
pub fn flags<Iter>(&mut self, flags: Iter) -> &mut Build
575+
where
576+
Iter: IntoIterator,
577+
Iter::Item: AsRef<OsStr>,
578+
{
579+
for flag in flags {
580+
self.flag(flag);
581+
}
582+
self
583+
}
584+
564585
/// Removes a compiler flag that was added by [`Build::flag`].
565586
///
566587
/// Will not remove flags added by other means (default flags,

0 commit comments

Comments
 (0)