You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by ms...@apache.org on 2021/11/17 17:31:24 UTC

[incubator-teaclave] branch master updated: Support selectively including executors (#574)

This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git


The following commit(s) were added to refs/heads/master by this push:
     new d0f877e  Support selectively including executors (#574)
d0f877e is described below

commit d0f877e16df3ba3e0326ff0ce0cc4f5c3fb78845
Author: Mingshen Sun <bo...@mssun.me>
AuthorDate: Wed Nov 17 09:28:35 2021 -0800

    Support selectively including executors (#574)
    
    * Support to selectively include different executors
    * Fix the make format command
---
 CMakeLists.txt                 | 54 ++++++++++++++++++++++++++++++++----------
 cmake/TeaclaveGenVars.cmake    |  4 ++++
 cmake/UtilTargets.cmake        |  4 ++--
 cmake/scripts/sgx_link_sign.sh | 33 ++++++++++++++++----------
 docs/build-system.md           |  3 +++
 executor/src/lib.rs            | 22 +++++++++++------
 worker/src/worker.rs           |  5 +++-
 7 files changed, 90 insertions(+), 35 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 054dea5..a2f65db 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,6 +47,9 @@ option(SGX_SIM_MODE "Turn on/off sgx simulation mode" OFF)
 option(DCAP "Turn on/off DCAP attestation" OFF)
 option(GIT_SUBMODULE "Check submodules during build" ON)
 option(USE_PREBUILT_MESAPY "Use prebuilt MesaPy SGX executor" ON)
+option(EXECUTOR_BUILTIN "Compile with the Builtin executor" ON)
+option(EXECUTOR_MESAPY "Compile with the MesaPy executor" ON)
+option(EXECUTOR_WAMR "Compile with the WebAssembly Micro Runtime executor" ON)
 init_submodules()
 
 if(DCAP)
@@ -63,6 +66,19 @@ if(SGX_SIM_MODE)
 else()
   set(SGX_MODE "HW")
 endif()
+
+if(EXECUTOR_BUILTIN)
+  set(RUSTFLAGS "${RUSTFLAGS} --cfg executor_builtin")
+endif()
+
+if(EXECUTOR_MESAPY)
+  set(RUSTFLAGS "${RUSTFLAGS} --cfg executor_mesapy")
+endif()
+
+if(EXECUTOR_WAMR)
+  set(RUSTFLAGS "${RUSTFLAGS} --cfg executor_wamr")
+endif()
+
 # ======= VARIABLES FOR CMAKE -D{VAR}=VAL CONFIGURATION END =======
 
 # =============== VARIABLES FOR MANUAL CHANGE BEGIN ===============
@@ -238,18 +254,32 @@ foreach(_i RANGE ${SGX_LIB_LAST_INDEX})
   list(GET SGX_LIB_PATHS ${_i} _pkg_path)
   list(GET SGX_LIB_CATEGORIES ${_i} _category)
   list(GET EDL_LIB_NAMES ${_i} _edl_lib_name)
-  add_sgx_build_target(
-    ${_pkg_path}
-    ${_pkg_name}
-    DEPENDS
-    prep
-    mesapy
-    wamr
-    pycomponent
-    INSTALL_DIR
-    ${TEACLAVE_INSTALL_DIR}/${_category}
-    EDL_LIB_NAME
-    ${_edl_lib_name})
+  if(EXECUTOR_WAMR)
+    add_sgx_build_target(
+      ${_pkg_path}
+      ${_pkg_name}
+      DEPENDS
+      prep
+      mesapy
+      pycomponent
+      wamr
+      INSTALL_DIR
+      ${TEACLAVE_INSTALL_DIR}/${_category}
+      EDL_LIB_NAME
+      ${_edl_lib_name})
+  else()
+    add_sgx_build_target(
+      ${_pkg_path}
+      ${_pkg_name}
+      DEPENDS
+      prep
+      mesapy
+      pycomponent
+      INSTALL_DIR
+      ${TEACLAVE_INSTALL_DIR}/${_category}
+      EDL_LIB_NAME
+      ${_edl_lib_name})
+  endif()
 endforeach()
 
 # Dylib/staticlib of Teaclave Rust Client SDK
diff --git a/cmake/TeaclaveGenVars.cmake b/cmake/TeaclaveGenVars.cmake
index 107e61e..347ed06 100644
--- a/cmake/TeaclaveGenVars.cmake
+++ b/cmake/TeaclaveGenVars.cmake
@@ -135,6 +135,7 @@ set(TEACLAVE_COMMON_ENVS
     TEACLAVE_BUILD_CFG_DIR=${PROJECT_SOURCE_DIR}
     TEACLAVE_EDL_DIR=${TEACLAVE_EDL_DIR}
     TEACLAVE_SYMLINKS=${TEACLAVE_SYMLINKS}
+    TEACLAVE_EXECUTOR_WAMR=${EXECUTOR_WAMR}
     RUSTFLAGS=${RUSTFLAGS}
     SGX_SDK=${SGX_SDK}
     SGX_MODE=${SGX_MODE}
@@ -173,3 +174,6 @@ message("RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN}")
 message("DCAP=${DCAP}")
 message("BUILD_TYPE=${TARGET}")
 message("TEACLAVE_SYMLINKS=${TEACLAVE_SYMLINKS}")
+message("EXECUTOR_BUILTIN=${EXECUTOR_BUILTIN}")
+message("EXECUTOR_MESAPY=${EXECUTOR_MESAPY}")
+message("EXECUTOR_WAMR=${EXECUTOR_WAMR}")
diff --git a/cmake/UtilTargets.cmake b/cmake/UtilTargets.cmake
index de388a6..f2162d4 100644
--- a/cmake/UtilTargets.cmake
+++ b/cmake/UtilTargets.cmake
@@ -30,14 +30,14 @@ add_custom_target(
     -path ${TEACLAVE_PROJECT_ROOT}/third_party -prune -o
     -path ${TEACLAVE_PROJECT_ROOT}/.git -prune -o
     -path ${TEACLAVE_BUILD_ROOT} -prune
-    -o -name "*.rs" -exec rustfmt {} +
+    -o -name '*.rs' -exec rustfmt {} +
   COMMAND
     find ${TEACLAVE_PROJECT_ROOT}
     -path ${TEACLAVE_PROJECT_ROOT}/third_party -prune -o
     -path ${TEACLAVE_PROJECT_ROOT}/.git -prune -o
     -path ${TEACLAVE_PROJECT_ROOT}/services/access_control -prune -o
     -path ${TEACLAVE_BUILD_ROOT} -prune
-    -o -name "*.py" -exec yapf -i {} +
+    -o -name '*.py' -exec yapf -i {} +
   COMMENT "Formating every .rs and .py file with rustfmt and yapf"
   DEPENDS prep)
 
diff --git a/cmake/scripts/sgx_link_sign.sh b/cmake/scripts/sgx_link_sign.sh
index 670e7b6..3c44023 100755
--- a/cmake/scripts/sgx_link_sign.sh
+++ b/cmake/scripts/sgx_link_sign.sh
@@ -21,7 +21,7 @@ set -e
 REQUIRED_ENVS=("CMAKE_C_COMPILER" "CUR_PKG_NAME" "CUR_PKG_PATH"
 "CUR_INSTALL_DIR" "TEACLAVE_OUT_DIR" "TEACLAVE_PROJECT_ROOT" "Service_Library_Name"
 "SGX_COMMON_CFLAGS" "SGX_ENCLAVE_SIGNER" "SGX_LIBRARY_PATH" "TARGET" "Trts_Library_Name"
-"TRUSTED_TARGET_DIR")
+"TRUSTED_TARGET_DIR" "TEACLAVE_EXECUTOR_WAMR")
 for var in "${REQUIRED_ENVS[@]}"; do
     [ -z "${!var}" ] && echo "Please set ${var}" && exit -1
 done
@@ -44,21 +44,28 @@ if [ ! "$LIBENCLAVE_PATH" -nt "$SIGNED_PATH" ] \
     exit 0
 fi
 
+TEACLAVE_LINK_FLAGS="-L${TEACLAVE_OUT_DIR} -lpycomponent ffi.o -lpypy-c -lsgx_tlibc_ext -lffi"
+if [ "$TEACLAVE_EXECUTOR_WAMR" == "ON" ]; then
+    TEACLAVE_LINK_FLAGS+=" -lvmlib"
+fi
+ENCLAVE_LINK_FLAGS="-Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L${SGX_LIBRARY_PATH} \
+                   -Wl,--whole-archive -l${Trts_Library_Name} -Wl,--no-whole-archive \
+                   -Wl,--start-group \
+                   -l${Service_Library_Name} -lsgx_tprotected_fs -lsgx_tkey_exchange \
+                   -lsgx_tstdc -lsgx_tcxx -lsgx_tservice -lsgx_tcrypto \
+                   ${TEACLAVE_LINK_FLAGS} \
+                   -L${TRUSTED_TARGET_DIR}/${TARGET} -l${CUR_PKG_NAME} \
+                   -Wl,--end-group \
+                   -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
+                   -Wl,-pie,-eenclave_entry -Wl,--export-dynamic  \
+                   -Wl,--defsym,__ImageBase=0 \
+                   -Wl,--gc-sections \
+                   -Wl,--version-script=${TEACLAVE_PROJECT_ROOT}/cmake/scripts/Enclave.lds"
+
 cd ${TEACLAVE_OUT_DIR}
 ${CMAKE_C_COMPILER} "lib${edl_lib_name}.o" -o \
     ${TEACLAVE_OUT_DIR}/${CUR_PKG_NAME}.so ${SGX_COMMON_CFLAGS} \
-    -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles \
-    -L${SGX_LIBRARY_PATH} -Wl,--whole-archive -l${Trts_Library_Name} \
-    -Wl,--no-whole-archive -Wl,--start-group \
-    -l${Service_Library_Name} -lsgx_tprotected_fs -lsgx_tkey_exchange \
-    -lsgx_tstdc -lsgx_tcxx -lsgx_tservice -lsgx_tcrypto \
-    -L${TEACLAVE_OUT_DIR} -lpycomponent ffi.o -lpypy-c -lsgx_tlibc_ext -lffi -lvmlib\
-    -L${TRUSTED_TARGET_DIR}/${TARGET} -l${CUR_PKG_NAME} -Wl,--end-group \
-    -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
-    -Wl,-pie,-eenclave_entry -Wl,--export-dynamic  \
-    -Wl,--defsym,__ImageBase=0 \
-    -Wl,--gc-sections \
-    -Wl,--version-script=${TEACLAVE_PROJECT_ROOT}/cmake/scripts/Enclave.lds
+    ${ENCLAVE_LINK_FLAGS}
 ${SGX_ENCLAVE_SIGNER} sign -key ${TEACLAVE_PROJECT_ROOT}/keys/enclave_signing_key.pem \
     -enclave ${CUR_PKG_NAME}.so \
     -out ${CUR_INSTALL_DIR}/${CUR_PKG_NAME}.signed.so \
diff --git a/docs/build-system.md b/docs/build-system.md
index 08e18d4..2fe9305 100644
--- a/docs/build-system.md
+++ b/docs/build-system.md
@@ -65,6 +65,9 @@ To set a variable or option, you can pass `-DXXX=` to `cmake`. For example,
 - `DOC`: Generate document with `cargo doc` during the compilation. Defaults to OFF.
 - `USE_PREBUILT_MESAPY`: Whether to use the prebuilt MesaPy for SGX library. If
   set to OFF, will build the library from the source code. Defaults to ON.
+- `EXECUTOR_BUILTIN`: Compile with the Builtin executor. Defaults to ON.
+- `EXECUTOR_MESAPY`: Compile with the MesaPy executor. Defaults to ON.
+- `EXECUTOR_WAMR`: Compile with the WebAssembly Micro Runtime executor. Defaults to ON.
 
 ## Targets
 
diff --git a/executor/src/lib.rs b/executor/src/lib.rs
index 31e566e..d11933f 100644
--- a/executor/src/lib.rs
+++ b/executor/src/lib.rs
@@ -25,26 +25,34 @@ use std::prelude::v1::*;
 #[macro_use]
 extern crate log;
 
+#[cfg(executor_builtin)]
 mod builtin;
 mod context;
+#[cfg(executor_mesapy)]
 mod mesapy;
+#[cfg(executor_wamr)]
 mod wamr;
 
+#[cfg(executor_builtin)]
 pub use builtin::BuiltinFunctionExecutor;
+#[cfg(executor_mesapy)]
 pub use mesapy::MesaPy;
+#[cfg(executor_wamr)]
 pub use wamr::WAMicroRuntime;
 
 #[cfg(feature = "enclave_unit_test")]
 pub mod tests {
     use super::*;
-    use teaclave_test_utils::check_all_passed;
 
     pub fn run_tests() -> bool {
-        check_all_passed!(
-            context::tests::run_tests(),
-            mesapy::tests::run_tests(),
-            builtin::tests::run_tests(),
-            wamr::tests::run_tests(),
-        )
+        let mut v: Vec<bool> = Vec::new();
+        v.push(context::tests::run_tests());
+        #[cfg(executor_mesapy)]
+        v.push(mesapy::tests::run_tests());
+        #[cfg(executor_builtin)]
+        v.push(builtin::tests::run_tests());
+        #[cfg(executor_wamr)]
+        v.push(wamr::tests::run_tests());
+        v.iter().all(|&x| x)
     }
 }
diff --git a/worker/src/worker.rs b/worker/src/worker.rs
index 1f1ed1e..27cc419 100644
--- a/worker/src/worker.rs
+++ b/worker/src/worker.rs
@@ -23,7 +23,7 @@ use std::format;
 
 use teaclave_types::{Executor, ExecutorType, StagedFiles, StagedFunction};
 
-use teaclave_executor::{BuiltinFunctionExecutor, MesaPy, WAMicroRuntime};
+use teaclave_executor::*;
 use teaclave_runtime::DefaultRuntime;
 use teaclave_types::{TeaclaveExecutor, TeaclaveRuntime};
 
@@ -52,12 +52,15 @@ impl Default for Worker {
         });
 
         // Register supported executors
+        #[cfg(executor_mesapy)]
         worker.register_executor((ExecutorType::Python, Executor::MesaPy), || {
             Box::new(MesaPy::default())
         });
+        #[cfg(executor_builtin)]
         worker.register_executor((ExecutorType::Builtin, Executor::Builtin), || {
             Box::new(BuiltinFunctionExecutor::default())
         });
+        #[cfg(executor_wamr)]
         worker.register_executor(
             (ExecutorType::WAMicroRuntime, Executor::WAMicroRuntime),
             || Box::new(WAMicroRuntime::default()),

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org