File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,9 @@ serde_json = { version = "1.0.133" }
4242optee-utee-sys = { version = " 0.7.0" , path = " optee-utee-sys" , features = [" no_link" ] }
4343optee-utee-mock = { version = " 0.7.0" , path = " optee-utee-mock" }
4444
45+ [build-dependencies ]
46+ version_check = " 0.9.5"
47+
4548[features ]
4649default = []
4750std = [" optee-utee-sys/std" , " optee-utee-macros/std" ]
Original file line number Diff line number Diff line change 1+ use std:: fs;
2+
3+ /// Outputs unstable #[feature = "foo"] iff the rustc version is older than $version
4+ macro_rules! maybe_feat {
5+ ( $out: expr, $feat: literal, $version: literal) => {
6+ {
7+ let filename = $out. join( concat!( $feat, ".rs" ) ) ;
8+
9+ let s = if version_check:: is_min_version( $version) . unwrap_or( false ) {
10+ String :: new( )
11+ } else {
12+ format!( "#![feature = \" {}\" ]\n " , $feat)
13+ } ;
14+ fs:: write( filename, s) . expect( "failed to write to {filename:?}" ) ;
15+ }
16+ }
17+ }
18+
19+ fn main ( ) {
20+ let out = std:: path:: PathBuf :: from ( std:: env:: var ( "OUT_DIR" ) . expect ( "infallible" ) ) ;
21+
22+ // The custom patched std version is currently on 1.80. When we upgrade, we should
23+ // bump the MSRV accordingly and remove any of these features that are stablized.
24+ maybe_feat ! ( out, "error_in_core" , "1.81.0" ) ;
25+ }
26+
27+
Original file line number Diff line number Diff line change 1616// under the License.
1717
1818#![ cfg_attr( not( feature = "std" ) , no_std) ]
19- #![ cfg_attr( not( feature = "std" ) , feature( error_in_core) ) ]
19+
20+ #[ allow( unused_macros) ]
21+ /// Cargo will complain if your source file contains `#![features = ..]` even
22+ /// whe the current cfg wouldn't enable the attribute. To get around this, we
23+ /// `include!()` a source file with the offending attr *only* present when the compiler
24+ /// is too old.
25+ macro_rules! enable_feat {
26+ ( $feature: literal) => {
27+ include!( concat!( env!( "OUT_DIR" ) , "/" , $feature, ".rs" ) ) ;
28+ }
29+ }
30+
31+ #[ cfg( not( feature = "std" ) ) ]
32+ enable_feat ! ( "error_in_core" ) ;
2033
2134// Requires `alloc`.
2235#[ macro_use]
You can’t perform that action at this time.
0 commit comments