@@ -45,6 +45,18 @@ fn parse_mappings(mut mappings: &'static str) -> Vec<Mapping> {
45
45
result
46
46
}
47
47
48
+ type Cfg = Option < & ' static str > ;
49
+ type Date = & ' static str ;
50
+ /// A `ConditionalCfg` is basically a list of optional feature names
51
+ /// (`Cfg`s) separated by `Date`s. The dates specify ranges of compiler
52
+ /// versions for which to enable particular features.
53
+ type ConditionalCfg = ( Cfg , & ' static [ ( Date , Cfg ) ] ) ;
54
+ const CONDITIONAL_CFGS : & ' static [ ConditionalCfg ] = & [
55
+ ( None , & [ ( "2018-01-01" , Some ( "core_memchr" ) ) ] ) ,
56
+ ( None , & [ ( "2017-06-15" , Some ( "no_collections" ) ) ] ) ,
57
+ ( Some ( "rustc_unicode" ) , & [ ( "2016-12-15" , Some ( "std_unicode" ) ) , ( "2017-03-03" , None ) ] ) ,
58
+ ] ;
59
+
48
60
fn main ( ) {
49
61
let ver=rustc_version:: version_meta ( ) ;
50
62
@@ -59,18 +71,17 @@ fn main() {
59
71
}
60
72
} ;
61
73
62
- if ver. commit_date . as_ref ( ) . map_or ( false , |d| & * * d>="2018-01-01" ) {
63
- println ! ( "cargo:rustc-cfg=core_memchr" ) ;
64
- }
65
-
66
- if ver. commit_date . as_ref ( ) . map_or ( false , |d| & * * d>="2017-06-15" ) {
67
- println ! ( "cargo:rustc-cfg=no_collections" ) ;
68
- }
69
-
70
- if ver. commit_date . as_ref ( ) . map_or ( false , |d| & * * d<"2016-12-15" ) {
71
- println ! ( "cargo:rustc-cfg=rustc_unicode" ) ;
72
- } else if ver. commit_date . as_ref ( ) . map_or ( false , |d| & * * d<"2017-03-03" ) {
73
- println ! ( "cargo:rustc-cfg=std_unicode" ) ;
74
+ for & ( mut curcfg, rest) in CONDITIONAL_CFGS {
75
+ for & ( date, nextcfg) in rest {
76
+ // if no commit_date is provided, assume compiler is current
77
+ if ver. commit_date . as_ref ( ) . map_or ( false , |d| & * * d<date) {
78
+ break ;
79
+ }
80
+ curcfg = nextcfg;
81
+ }
82
+ if let Some ( cfg) = curcfg {
83
+ println ! ( "cargo:rustc-cfg={}" , cfg) ;
84
+ }
74
85
}
75
86
76
87
let mut dest_path=PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) ;
0 commit comments