sccommunity / crates-sgx

crates-sgx is a monorepo of all Rust crates ported for Teaclave SGX SDK targeting Intel SGX.
https://sccommunity.github.io/crates-sgx
Apache License 2.0
12 stars 2 forks source link

Add serde 1.0.106 #12

Closed mssun closed 4 years ago

mssun commented 4 years ago

Add serde 1.0.106

Description

Add serde 1.0.106

Crate Meta

Diff of Changes

diff --git a/serde/Cargo.toml b/serde/Cargo.toml
index d35fedf8..b2f0222f 100644
--- a/serde/Cargo.toml
+++ b/serde/Cargo.toml
@@ -19,6 +19,7 @@ appveyor = { repository = "serde-rs/serde" }

 [dependencies]
 serde_derive = { version = "=1.0.106", optional = true, path = "../serde_derive" }
+sgx_tstd = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk", tag = "v1.1.1", optional = true }

 [dev-dependencies]
 serde_derive = { version = "1.0", path = "../serde_derive" }
@@ -33,7 +34,8 @@ targets = ["x86_64-unknown-linux-gnu"]
 ### FEATURES #################################################################

 [features]
-default = ["std"]
+default = ["std", "mesalock_sgx"]
+mesalock_sgx = ["sgx_tstd", "std"]

 # Provide derive(Serialize, Deserialize) macros.
 derive = ["serde_derive"]
diff --git a/serde/src/lib.rs b/serde/src/lib.rs
index b7f2a1e9..6557bdb5 100644
--- a/serde/src/lib.rs
+++ b/serde/src/lib.rs
@@ -127,6 +127,14 @@
 #![forbid(unsafe_code)]
 #![deny(missing_docs, unused_imports)]

+#![cfg_attr(all(feature = "mesalock_sgx",
+                not(target_env = "sgx")), no_std)]
+#![cfg_attr(all(target_env = "sgx", target_vendor = "mesalock"),
+            feature(rustc_private))]
+#[cfg(all(feature = "mesalock_sgx", not(target_env = "sgx")))]
+#[macro_use]
+extern crate sgx_tstd as std;
+
 ////////////////////////////////////////////////////////////////////////////////

 #[cfg(feature = "alloc")]
@@ -208,8 +216,8 @@ mod lib {
     pub use std::num::Wrapping;
     #[cfg(feature = "std")]
     pub use std::path::{Path, PathBuf};
-    #[cfg(feature = "std")]
-    pub use std::sync::{Mutex, RwLock};
+    #[cfg(all(feature = "std", feature = "mesalock_sgx"))]
+    pub use std::sync::{SgxMutex as Mutex, SgxRwLock as RwLock};
     #[cfg(feature = "std")]
     pub use std::time::{SystemTime, UNIX_EPOCH};

diff --git a/serde_derive/Cargo.toml b/serde_derive/Cargo.toml
index 29df5df0..23c1cafc 100644
--- a/serde_derive/Cargo.toml
+++ b/serde_derive/Cargo.toml
@@ -29,7 +29,7 @@ quote = "1.0"
 syn = { version = "1.0", features = ["visit"] }

 [dev-dependencies]
-serde = { version = "1.0", path = "../serde" }
+serde = { version = "1.0", path = "../serde", default-features = false, features = ["std"] }

 [package.metadata.docs.rs]
 targets = ["x86_64-unknown-linux-gnu"]
diff --git a/serde_test/Cargo.toml b/serde_test/Cargo.toml
index 24ba7a0e..9adc3699 100644
--- a/serde_test/Cargo.toml
+++ b/serde_test/Cargo.toml
@@ -11,8 +11,13 @@ keywords = ["serde", "serialization"]
 readme = "crates-io.md"
 include = ["Cargo.toml", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]

+[features]
+default = ["mesalock_sgx"]
+mesalock_sgx = ["sgx_tstd"]
+
 [dependencies]
 serde = { version = "1.0.60", path = "../serde" }
+sgx_tstd = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk", tag = "v1.1.1", optional = true }

 [dev-dependencies]
 serde = { version = "1.0", path = "../serde" }
diff --git a/serde_test/src/configure.rs b/serde_test/src/configure.rs
index fb962c39..def62971 100644
--- a/serde_test/src/configure.rs
+++ b/serde_test/src/configure.rs
@@ -1,3 +1,5 @@
+#[cfg(feature = "mesalock_sgx")]
+use std::prelude::v1::*;
 use std::fmt;

 use serde::ser::{
diff --git a/serde_test/src/de.rs b/serde_test/src/de.rs
index c9bcee5b..d3c2af5c 100644
--- a/serde_test/src/de.rs
+++ b/serde_test/src/de.rs
@@ -1,3 +1,4 @@
+use std::borrow::ToOwned;
 use serde::de::value::{MapAccessDeserializer, SeqAccessDeserializer};
 use serde::de::{
     self, Deserialize, DeserializeSeed, EnumAccess, IntoDeserializer, MapAccess, SeqAccess,
diff --git a/serde_test/src/error.rs b/serde_test/src/error.rs
index 54a71d2d..c169cf3a 100644
--- a/serde_test/src/error.rs
+++ b/serde_test/src/error.rs
@@ -1,3 +1,5 @@
+#[cfg(feature = "mesalock_sgx")]
+use std::prelude::v1::*;
 use std::error;
 use std::fmt::{self, Display};

diff --git a/serde_test/src/lib.rs b/serde_test/src/lib.rs
index ca980527..83da5822 100644
--- a/serde_test/src/lib.rs
+++ b/serde_test/src/lib.rs
@@ -163,6 +163,14 @@
     )
 )]

+#![cfg_attr(all(feature = "mesalock_sgx",
+                not(target_env = "sgx")), no_std)]
+#![cfg_attr(all(target_env = "sgx", target_vendor = "mesalock"),
+            feature(rustc_private))]
+#[cfg(all(feature = "mesalock_sgx", not(target_env = "sgx")))]
+#[macro_use]
+extern crate sgx_tstd as std;
+
 #[macro_use]
 extern crate serde;

diff --git a/serde_test/src/ser.rs b/serde_test/src/ser.rs
index 0ff6c828..ba1b55b6 100644
--- a/serde_test/src/ser.rs
+++ b/serde_test/src/ser.rs
@@ -1,3 +1,5 @@
+#[cfg(feature = "mesalock_sgx")]
+use std::prelude::v1::*;
 use serde::{ser, Serialize};

 use error::Error;
mssun commented 4 years ago

Serde has a plenty of tests. I just ported some of them. We need a better way (scripts or macro) to transfer existing tests to SGX one.