@@ -108,6 +108,7 @@ pub struct Build {
108108 cpp_set_stdlib : Option < Arc < str > > ,
109109 cuda : bool ,
110110 cudart : Option < Arc < str > > ,
111+ std : Option < Arc < str > > ,
111112 target : Option < Arc < str > > ,
112113 host : Option < Arc < str > > ,
113114 out_dir : Option < Arc < Path > > ,
@@ -314,6 +315,7 @@ impl Build {
314315 cpp_set_stdlib : None ,
315316 cuda : false ,
316317 cudart : None ,
318+ std : None ,
317319 target : None ,
318320 host : None ,
319321 out_dir : None ,
@@ -708,6 +710,37 @@ impl Build {
708710 self
709711 }
710712
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+
711744 /// Set warnings into errors flag.
712745 ///
713746 /// Disabled by default.
@@ -1613,6 +1646,14 @@ impl Build {
16131646 println ! ( "Info: default compiler flags are disabled" ) ;
16141647 }
16151648
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+
16161657 if let Ok ( flags) = self . envflags ( if self . cpp { "CXXFLAGS" } else { "CFLAGS" } ) {
16171658 for arg in flags {
16181659 cmd. push_cc_arg ( arg. into ( ) ) ;
0 commit comments