@@ -202,7 +202,7 @@ pub struct Config {
202
202
pub llvm_use_libcxx : bool ,
203
203
204
204
// rust codegen options
205
- pub rust_optimize : bool ,
205
+ pub rust_optimize : RustOptimize ,
206
206
pub rust_codegen_units : Option < u32 > ,
207
207
pub rust_codegen_units_std : Option < u32 > ,
208
208
pub rust_debug_assertions : bool ,
@@ -875,17 +875,55 @@ impl Default for StringOrBool {
875
875
}
876
876
}
877
877
878
+ #[ derive( Clone , Debug , Deserialize , PartialEq , Eq ) ]
879
+ #[ serde( untagged) ]
880
+ pub enum RustOptimize {
881
+ #[ serde( deserialize_with = "deserialize_and_validate_opt_level" ) ]
882
+ String ( String ) ,
883
+ Bool ( bool ) ,
884
+ }
885
+
886
+ impl Default for RustOptimize {
887
+ fn default ( ) -> RustOptimize {
888
+ RustOptimize :: Bool ( false )
889
+ }
890
+ }
891
+
892
+ fn deserialize_and_validate_opt_level < ' de , D > ( d : D ) -> Result < String , D :: Error >
893
+ where
894
+ D : serde:: de:: Deserializer < ' de > ,
895
+ {
896
+ let v = String :: deserialize ( d) ?;
897
+ if [ "0" , "1" , "2" , "3" , "s" , "z" ] . iter ( ) . find ( |x| * * x == v) . is_some ( ) {
898
+ Ok ( v)
899
+ } else {
900
+ Err ( format ! ( r#"unrecognized option for rust optimize: "{}", expected one of "0", "1", "2", "3", "s", "z""# , v) ) . map_err ( serde:: de:: Error :: custom)
901
+ }
902
+ }
903
+
904
+ impl RustOptimize {
905
+ pub ( crate ) fn is_release ( & self ) -> bool {
906
+ if let RustOptimize :: Bool ( true ) | RustOptimize :: String ( _) = & self { true } else { false }
907
+ }
908
+
909
+ pub ( crate ) fn get_opt_level ( & self ) -> Option < String > {
910
+ match & self {
911
+ RustOptimize :: String ( s) => Some ( s. clone ( ) ) ,
912
+ RustOptimize :: Bool ( _) => None ,
913
+ }
914
+ }
915
+ }
916
+
878
917
#[ derive( Deserialize ) ]
879
918
#[ serde( untagged) ]
880
919
enum StringOrInt < ' a > {
881
920
String ( & ' a str ) ,
882
921
Int ( i64 ) ,
883
922
}
884
-
885
923
define_config ! {
886
924
/// TOML representation of how the Rust build is configured.
887
925
struct Rust {
888
- optimize: Option <bool > = "optimize" ,
926
+ optimize: Option <RustOptimize > = "optimize" ,
889
927
debug: Option <bool > = "debug" ,
890
928
codegen_units: Option <u32 > = "codegen-units" ,
891
929
codegen_units_std: Option <u32 > = "codegen-units-std" ,
@@ -971,7 +1009,7 @@ impl Config {
971
1009
config. ninja_in_file = true ;
972
1010
config. llvm_static_stdcpp = false ;
973
1011
config. backtrace = true ;
974
- config. rust_optimize = true ;
1012
+ config. rust_optimize = RustOptimize :: Bool ( true ) ;
975
1013
config. rust_optimize_tests = true ;
976
1014
config. submodules = None ;
977
1015
config. docs = true ;
@@ -1546,7 +1584,7 @@ impl Config {
1546
1584
config. llvm_assertions = llvm_assertions. unwrap_or ( false ) ;
1547
1585
config. llvm_tests = llvm_tests. unwrap_or ( false ) ;
1548
1586
config. llvm_plugins = llvm_plugins. unwrap_or ( false ) ;
1549
- config. rust_optimize = optimize. unwrap_or ( true ) ;
1587
+ config. rust_optimize = optimize. unwrap_or ( RustOptimize :: Bool ( true ) ) ;
1550
1588
1551
1589
let default = debug == Some ( true ) ;
1552
1590
config. rust_debug_assertions = debug_assertions. unwrap_or ( default) ;
0 commit comments