You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by di...@apache.org on 2020/11/27 22:59:07 UTC
[incubator-teaclave-sgx-sdk] branch newer-compiler-11-26 updated:
compiler: remove version-check
This is an automated email from the ASF dual-hosted git repository.
dingyu pushed a commit to branch newer-compiler-11-26
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-sgx-sdk.git
The following commit(s) were added to refs/heads/newer-compiler-11-26 by this push:
new 4f31985 compiler: remove version-check
4f31985 is described below
commit 4f319850241d71f4c5603d5631624b27b3dd8c74
Author: Yu Ding <di...@gmail.com>
AuthorDate: Fri Nov 27 14:58:54 2020 -0800
compiler: remove version-check
---
sgx_tstd/Cargo.toml | 3 ---
sgx_tstd/build.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/sgx_tstd/Cargo.toml b/sgx_tstd/Cargo.toml
index 5dfe6fd..cb42c1b 100644
--- a/sgx_tstd/Cargo.toml
+++ b/sgx_tstd/Cargo.toml
@@ -38,6 +38,3 @@ package = "hashbrown_tstd"
path = "./hashbrown"
default-features = false
features = ['rustc-dep-of-std']
-
-[build-dependencies]
-version_check = "0.9"
diff --git a/sgx_tstd/build.rs b/sgx_tstd/build.rs
index b29efc6..1a5488d 100644
--- a/sgx_tstd/build.rs
+++ b/sgx_tstd/build.rs
@@ -16,6 +16,7 @@
// under the License..
use std::env;
+use std::process::Command;
fn main() {
if cfg!(feature = "backtrace") {
@@ -36,7 +37,58 @@ fn main() {
// since nightly-2020-11-26 (rustc 2020-11-25), auto_traits replaced
// optin_builtin_traits
// see https://github.com/rust-lang/rust/commit/810324d1f31eb8d75e8f0044df720652986ef133
- if let Some(true) = version_check::is_min_date("2020-11-25") {
+ if let Some(true) = is_min_date("2020-11-25") {
println!("cargo:rustc-cfg=enable_auto_traits");
}
}
+
+// code below copied from crate version_check
+// we want to remove the build dependencies to make the dependency tree
+// as clean as possible. the following codes credit to SergioBenitez
+#[derive(Debug, PartialEq, Eq, Copy, Clone, PartialOrd, Ord)]
+struct Date(u32);
+
+impl Date {
+ fn read() -> Option<Date> {
+ get_version_and_date()
+ .and_then(|(_, date)| date)
+ .and_then(|date| Date::parse(&date))
+ }
+
+ fn parse(date: &str) -> Option<Date> {
+ let ymd: Vec<u32> = date.split("-")
+ .filter_map(|s| s.parse::<u32>().ok())
+ .collect();
+
+ if ymd.len() != 3 {
+ return None
+ }
+
+ let (y, m, d) = (ymd[0], ymd[1], ymd[2]);
+ Some(Date((y << 9) | ((m & 0xF) << 5) | (d & 0x1F)))
+ }
+}
+
+fn get_version_and_date() -> Option<(Option<String>, Option<String>)> {
+ env::var("RUSTC").ok()
+ .and_then(|rustc| Command::new(rustc).arg("--version").output().ok())
+ .or_else(|| Command::new("rustc").arg("--version").output().ok())
+ .and_then(|output| String::from_utf8(output.stdout).ok())
+ .map(|s| version_and_date_from_rustc_version(&s))
+}
+
+fn version_and_date_from_rustc_version(s: &str) -> (Option<String>, Option<String>) {
+ let last_line = s.lines().last().unwrap_or(s);
+ let mut components = last_line.trim().split(" ");
+ let version = components.nth(1);
+ let date = components.filter(|c| c.ends_with(')')).next()
+ .map(|s| s.trim_end().trim_end_matches(")").trim_start().trim_start_matches('('));
+ (version.map(|s| s.to_string()), date.map(|s| s.to_string()))
+}
+
+fn is_min_date(min_date: &str) -> Option<bool> {
+ match (Date::read(), Date::parse(min_date)) {
+ (Some(rustc_date), Some(min_date)) => Some(rustc_date >= min_date),
+ _ => None
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org