Skip to content

Commit ec74bef

Browse files
committed
chore: get rid of now-stabilized error_in_core feature
1 parent 71bafe0 commit ec74bef

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

optee-utee/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ serde_json = { version = "1.0.133" }
4242
optee-utee-sys = { version = "0.7.0", path = "optee-utee-sys", features = ["no_link"] }
4343
optee-utee-mock = { version = "0.7.0", path = "optee-utee-mock" }
4444

45+
[build-dependencies]
46+
version_check = "0.9.5"
47+
4548
[features]
4649
default = []
4750
std = ["optee-utee-sys/std", "optee-utee-macros/std"]

optee-utee/build.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+

optee-utee/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,20 @@
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]

0 commit comments

Comments
 (0)