Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions optee-utee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ serde_json = { version = "1.0.133" }
optee-utee-sys = { version = "0.7.0", path = "optee-utee-sys", features = ["no_link"] }
optee-utee-mock = { version = "0.7.0", path = "optee-utee-mock" }

[build-dependencies]
version_check = "0.9.5"

[features]
default = []
std = ["optee-utee-sys/std", "optee-utee-macros/std"]
Expand Down
40 changes: 40 additions & 0 deletions optee-utee/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use std::fs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a valid license header.


/// Outputs unstable #[feature = "foo"] iff the rustc version is older than $version
macro_rules! maybe_feat {
($out:expr, $feat:literal, $version:literal) => {{
let filename = $out.join(concat!($feat, ".rs"));

let s = if version_check::is_min_version($version).unwrap_or(false) {
String::new()
} else {
format!("#![feature({})]\n", $feat)
};
fs::write(filename, s).expect("failed to write to {filename:?}");
}};
}

fn main() {
let out = std::path::PathBuf::from(std::env::var("OUT_DIR").expect("infallible"));

// The custom patched std version is currently on 1.80. When we upgrade, we should
// bump the MSRV accordingly and remove any of these features that are stablized.
maybe_feat!(out, "error_in_core", "1.81.0");
}
15 changes: 14 additions & 1 deletion optee-utee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@
// under the License.

#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(error_in_core))]

#[allow(unused_macros)]
/// Cargo will complain if your source file contains `#![features = ..]` even
/// whe the current cfg wouldn't enable the attribute. To get around this, we
/// `include!()` a source file with the offending attr *only* present when the compiler
/// is too old.
macro_rules! enable_feat {
($feature:literal) => {
include!(concat!(env!("OUT_DIR"), "/", $feature, ".rs"));
}
}

#[cfg(not(feature = "std"))]
enable_feat!("error_in_core");

// Requires `alloc`.
#[macro_use]
Expand Down