@@ -108,6 +108,7 @@ pub struct Build {
108
108
cpp_set_stdlib : Option < Arc < str > > ,
109
109
cuda : bool ,
110
110
cudart : Option < Arc < str > > ,
111
+ std : Option < Arc < str > > ,
111
112
target : Option < Arc < str > > ,
112
113
host : Option < Arc < str > > ,
113
114
out_dir : Option < Arc < Path > > ,
@@ -314,6 +315,7 @@ impl Build {
314
315
cpp_set_stdlib : None ,
315
316
cuda : false ,
316
317
cudart : None ,
318
+ std : None ,
317
319
target : None ,
318
320
host : None ,
319
321
out_dir : None ,
@@ -708,6 +710,37 @@ impl Build {
708
710
self
709
711
}
710
712
713
+ /// Specify the C or C++ language standard version.
714
+ ///
715
+ /// These values are common to modern versions of GCC, Clang and MSVC:
716
+ /// - `c11` for ISO/IEC 9899:2011
717
+ /// - `c17` for ISO/IEC 9899:2018
718
+ /// - `c++14` for ISO/IEC 14882:2014
719
+ /// - `c++17` for ISO/IEC 14882:2017
720
+ /// - `c++20` for ISO/IEC 14882:2020
721
+ ///
722
+ /// Other values have less broad support, e.g. MSVC does not support `c++11`
723
+ /// (`c++14` is the minimum), `c89` (omit the flag instead) or `c99`.
724
+ ///
725
+ /// For compiling C++ code, you should also set `.cpp(true)`.
726
+ ///
727
+ /// The default is that no standard flag is passed to the compiler, so the
728
+ /// language version will be the compiler's default.
729
+ ///
730
+ /// # Example
731
+ ///
732
+ /// ```no_run
733
+ /// cc::Build::new()
734
+ /// .file("src/modern.cpp")
735
+ /// .cpp(true)
736
+ /// .std("c++17")
737
+ /// .compile("modern");
738
+ /// ```
739
+ pub fn std ( & mut self , std : & str ) -> & mut Build {
740
+ self . std = Some ( std. into ( ) ) ;
741
+ self
742
+ }
743
+
711
744
/// Set warnings into errors flag.
712
745
///
713
746
/// Disabled by default.
@@ -1613,6 +1646,14 @@ impl Build {
1613
1646
println ! ( "Info: default compiler flags are disabled" ) ;
1614
1647
}
1615
1648
1649
+ if let Some ( ref std) = self . std {
1650
+ let separator = match cmd. family {
1651
+ ToolFamily :: Msvc { .. } => ':' ,
1652
+ ToolFamily :: Gnu | ToolFamily :: Clang => '=' ,
1653
+ } ;
1654
+ cmd. push_cc_arg ( format ! ( "-std{}{}" , separator, std) . into ( ) ) ;
1655
+ }
1656
+
1616
1657
if let Ok ( flags) = self . envflags ( if self . cpp { "CXXFLAGS" } else { "CFLAGS" } ) {
1617
1658
for arg in flags {
1618
1659
cmd. push_cc_arg ( arg. into ( ) ) ;
0 commit comments