File tree Expand file tree Collapse file tree 7 files changed +60
-8
lines changed
Expand file tree Collapse file tree 7 files changed +60
-8
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ matrix:
1111 - cargo bench
1212 - cargo test --features nightly
1313 - cargo bench --features nightly
14+ - CARGO_CFG_LAZY_STATIC_HEAP_IMPL=1 cargo test
15+ - CARGO_CFG_LAZY_STATIC_HEAP_IMPL=1 cargo bench
1416 - cargo test --features spin_no_std
1517 - cargo bench --features spin_no_std
1618 - cd compiletest
Original file line number Diff line number Diff line change @@ -13,10 +13,15 @@ repository = "https://github.com/rust-lang-nursery/lazy-static.rs"
1313keywords = [" macro" , " lazy" , " static" ]
1414categories = [ " no-std" , " rust-patterns" , " memory-management" ]
1515
16+ build = " build.rs"
17+
1618[dependencies .spin ]
1719version = " 0.4.6"
1820optional = true
1921
22+ [build-dependencies ]
23+ rustc_version = " 0.2.2"
24+
2025[features ]
2126nightly = []
2227spin_no_std = [" nightly" , " spin" ]
Original file line number Diff line number Diff line change 1+ extern crate rustc_version;
2+
3+ use rustc_version:: { version, Version } ;
4+
5+ fn main ( ) {
6+ let is_var_set = |s| std:: env:: var_os ( s) . is_some ( ) ;
7+
8+ // one can manually set a cfg to force an impl -- mostly useful for our own testing
9+ let force_heap_cfg = is_var_set ( "CARGO_CFG_LAZY_STATIC_HEAP_IMPL" ) ;
10+ let force_inline_cfg = is_var_set ( "CARGO_CFG_LAZY_STATIC_INLINE_IMPL" ) ;
11+ let force_spin_cfg = is_var_set ( "CARGO_CFG_LAZY_STATIC_SPIN_IMPL" ) ;
12+
13+ let impls_forced = [ force_heap_cfg, force_inline_cfg, force_spin_cfg]
14+ . into_iter ( )
15+ . filter ( |& & f| f)
16+ . count ( ) ;
17+
18+ assert ! (
19+ impls_forced <= 1 ,
20+ "lazy_static can only be built with one configuration at a time."
21+ ) ;
22+
23+ let nightly_feature_enabled = is_var_set ( "CARGO_FEATURE_NIGHTLY" ) ;
24+ let spin_feature_enabled = is_var_set ( "CARGO_FEATURE_SPIN_NO_STD" ) ;
25+
26+ let version_geq_127 = version ( ) . unwrap ( ) >= Version :: new ( 1 , 27 , 0 ) ;
27+ let unreachable_hint_supported = version_geq_127 || nightly_feature_enabled;
28+
29+ // precedence:
30+ // 1. explicit requests via cfg or spin_no_std feature
31+ // 2. inline impl with newer rustc version or nightly feature (latter for backcompat)
32+ // 3. fallback to allocating implementation
33+ let impl_name = if force_heap_cfg {
34+ "heap"
35+ } else if force_inline_cfg {
36+ "inline"
37+ } else if force_spin_cfg || spin_feature_enabled {
38+ "spin"
39+ } else if unreachable_hint_supported {
40+ "inline"
41+ } else {
42+ "heap"
43+ } ;
44+
45+ println ! ( "cargo:rustc-cfg=lazy_static_{}_impl" , impl_name) ;
46+ }
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change @@ -100,22 +100,23 @@ no guarantees can be made about them in regard to SemVer stability.
100100
101101*/
102102
103- #! [ cfg_attr ( feature= "spin_no_std" , feature ( const_fn ) ) ]
104- #![ cfg_attr( feature= "nightly" , feature( unreachable ) ) ]
103+ // NOTE: see build.rs for where these cfg values are set.
104+ #![ cfg_attr( lazy_static_spin_impl , feature( const_fn ) ) ]
105105
106106#![ doc( html_root_url = "https://docs.rs/lazy_static/1.0.1" ) ]
107107#![ no_std]
108108
109- #[ cfg( not( feature="nightly" ) ) ]
109+ #[ cfg( lazy_static_heap_impl) ]
110+ #[ path="heap_lazy.rs" ]
110111#[ doc( hidden) ]
111112pub mod lazy;
112113
113- #[ cfg( all ( feature= "nightly" , not ( feature= "spin_no_std" ) ) ) ]
114- #[ path="nightly_lazy .rs" ]
114+ #[ cfg( lazy_static_inline_impl ) ]
115+ #[ path="inline_lazy .rs" ]
115116#[ doc( hidden) ]
116117pub mod lazy;
117118
118- #[ cfg( all ( feature= "nightly" , feature= "spin_no_std" ) ) ]
119+ #[ cfg( lazy_static_spin_impl ) ]
119120#[ path="core_lazy.rs" ]
120121#[ doc( hidden) ]
121122pub mod lazy;
Original file line number Diff line number Diff line change 1- #![ cfg_attr( feature="nightly" , feature( const_fn) ) ]
2-
31#[ macro_use]
42extern crate lazy_static;
53use std:: collections:: HashMap ;
You can’t perform that action at this time.
0 commit comments