Polish build and install process

Remove redundent files and make processes for SGX simulation mode and hardware mode.
This commit is contained in:
Hui, Chunyang 2020-07-08 06:12:23 +00:00
parent bf736ff09d
commit 406f30ec7a
10 changed files with 55 additions and 83 deletions

@ -18,10 +18,11 @@ else
OCCLUM_GIT_OPTIONS +=
endif
# Enclaves using by tools are running in simulation mode by default to run faster.
# If a user really wants to run the tools in SGX hardware mode, please use command
# `OCCLUM_TOOLS_SIM_MODE_ONLY=N make submodule`.
OCCLUM_TOOLS_SIM_MODE_ONLY ?= Y
# Occlum major version
MAJOR_VER_NUM = $(shell grep '\#define OCCLUM_MAJOR_VERSION' ./src/pal/include/occlum_version.h | awk '{print $$3}')
# Exclude files when install
EXCLUDE_FILES = "libocclum-libos.so.$(MAJOR_VER_NUM)\$$|libocclum-pal.so.$(MAJOR_VER_NUM)\$$|libocclum-pal.so\$$|.a\$$|occlum-protect-integrity.so.*"
submodule: githooks
git submodule init
@ -30,29 +31,13 @@ submodule: githooks
cd deps/rust-sgx-sdk && git apply ../rust-sgx-sdk.patch >/dev/null 2>&1 || git apply ../rust-sgx-sdk.patch -R --check
cd deps/serde-json-sgx && git apply ../serde-json-sgx.patch >/dev/null 2>&1 || git apply ../serde-json-sgx.patch -R --check
ifeq ($(OCCLUM_TOOLS_SIM_MODE_ONLY), Y)
@# Tools and sefs-fuse are used in SIM mode by default
@# Enclaves used by tools are running in simulation mode by default to run faster.
@rm -rf build build_sim
@$(MAKE) SGX_MODE=SIM --no-print-directory -C tools
@$(MAKE) --no-print-directory -C deps/sefs/sefs-fuse clean
@$(MAKE) SGX_MODE=SIM --no-print-directory -C deps/sefs/sefs-fuse
@cp deps/sefs/sefs-fuse/bin/sefs-fuse build_sim/bin
@cp deps/sefs/sefs-fuse/lib/libsefs-fuse.signed.so build_sim/lib
@cp -r build_sim build
else
@# Tools and sefs-fuse are built for both HW mode and SIM mode
@rm -rf build build_sim
@$(MAKE) SGX_MODE=HW --no-print-directory -C tools
@$(MAKE) --no-print-directory -C deps/sefs/sefs-fuse clean
@$(MAKE) SGX_MODE=HW --no-print-directory -C deps/sefs/sefs-fuse
@cp deps/sefs/sefs-fuse/bin/sefs-fuse build/bin
@cp deps/sefs/sefs-fuse/lib/libsefs-fuse.signed.so build/lib
@$(MAKE) SGX_MODE=SIM --no-print-directory -C tools
@$(MAKE) --no-print-directory -C deps/sefs/sefs-fuse clean
@$(MAKE) SGX_MODE=SIM --no-print-directory -C deps/sefs/sefs-fuse
@cp deps/sefs/sefs-fuse/bin/sefs-fuse build_sim/bin
@cp deps/sefs/sefs-fuse/lib/libsefs-fuse.signed.so build_sim/lib
endif
src:
@$(MAKE) --no-print-directory -C src
@ -66,17 +51,12 @@ install:
@$(MAKE) SGX_MODE=HW --no-print-directory -C src
@$(MAKE) SGX_MODE=SIM --no-print-directory -C src
@echo "Install libraries for SGX hardware mode ..."
@echo "Install libraries ..."
@mkdir -p $(OCCLUM_PREFIX)/build/bin/
@cp build/bin/* $(OCCLUM_PREFIX)/build/bin
@mkdir -p $(OCCLUM_PREFIX)/build/lib/
@cp --no-dereference build/lib/* $(OCCLUM_PREFIX)/build/lib/
@echo "Install libraries for SGX simulation mode ..."
@mkdir -p $(OCCLUM_PREFIX)/build_sim/bin/
@cp build_sim/bin/* $(OCCLUM_PREFIX)/build_sim/bin
@mkdir -p $(OCCLUM_PREFIX)/build_sim/lib/
@cp --no-dereference build_sim/lib/* $(OCCLUM_PREFIX)/build_sim/lib/
@# Don't copy libos library and pal library symbolic files to install dir
@cd build/lib && cp --no-dereference `ls | grep -Ev $(EXCLUDE_FILES)` $(OCCLUM_PREFIX)/build/lib/ && cd -
@echo "Install headers and miscs ..."
@mkdir -p $(OCCLUM_PREFIX)/include/

@ -1,5 +1,4 @@
extern crate protoc_rust_grpc;
use std::env;
fn main() {
protoc_rust_grpc::Codegen::new()
@ -9,16 +8,6 @@ fn main() {
.run()
.expect("protoc-rust-grpc");
let sdk_dir = env::var("SGX_SDK").unwrap_or_else(|_| "/opt/intel/sgxsdk".to_string());
let sgx_mode = env::var("SGX_MODE").unwrap_or_else(|_| "HW".to_string());
match sgx_mode.as_ref() {
"SW" | "SIM" => {
println!("cargo:rustc-link-search=native={}/sdk_libs", sdk_dir);
println!("cargo:rustc-link-search=native=../../build_sim/lib");
println!("cargo:rustc-link-lib=dylib=sgx_uae_service_sim");
println!("cargo:rustc-link-lib=dylib=sgx_urts_sim")
}
"HW" | _ => println!("cargo:rustc-link-search=native=../../build/lib"), // Treat undefined as HW
}
println!("cargo:rustc-link-search=native=../../build/lib");
println!("cargo:rustc-link-lib=dylib=occlum-pal");
}

@ -43,9 +43,14 @@ include ../sgxenv.mk
# be printed.
LIBOS_LOG ?= error
LIBOS_SO := $(BUILD_DIR)/lib/libocclum-libos.so
LIBOS_SONAME := $(LIBOS_SO).$(MAJOR_VER_NUM)
LIBOS_SO_REAL := $(LIBOS_SO).$(VERSION_NUM)
LIBOS_SONAME := libocclum-libos.so.$(MAJOR_VER_NUM)
ifneq ($(SGX_MODE), HW)
LIBOS_SO_REAL := $(BUILD_DIR)/lib/libocclum-libos_sim.so.$(VERSION_NUM)
else
LIBOS_SO_REAL := $(BUILD_DIR)/lib/libocclum-libos.so.$(VERSION_NUM)
endif
LIBOS_CORE_A := $(BUILD_DIR)/lib/libocclum-libos-core.a
LIBOS_CORE_RS_A := $(BUILD_DIR)/lib/libocclum_libos_core_rs.a
@ -85,7 +90,6 @@ LIBOS_SO_DEPS := $(LIBOS_CORE_A) $(LIBCOMPILER_RT_PATCH_A)
$(LIBOS_SO_REAL): $(LIBOS_CORE_A) $(LIBCOMPILER_RT_PATCH_A)
@$(CC) $(LIBOS_SO_DEPS) -o $@ $(LINK_FLAGS) -Wl,-soname=$(LIBOS_SONAME)
@cd $(BUILD_DIR)/lib && ln -sf $(notdir $(LIBOS_SO_REAL)) $(notdir $(LIBOS_SONAME))
@echo "LINK => $@"
$(LIBOS_CORE_A): $(LIBOS_CORE_RS_A) $(C_OBJS) $(CXX_OBJS) $(S_OBJS) $(EDL_C_OBJS)
@ -124,6 +128,6 @@ $(BUILD_DIR)/src/libos/%.o: %.S
@echo "AS <= $@"
clean:
@-$(RM) -f $(LIBOS_SONAME) $(LIBOS_SO_REAL) $(LIBOS_CORE_A) $(LIBOS_CORE_RS_A) \
@-$(RM) -f $(LIBOS_SO_REAL) $(LIBOS_CORE_A) $(LIBOS_CORE_RS_A) \
$(EDL_C_OBJS) $(EDL_C_SRCS) $(C_OBJS) $(CXX_OBJS) $(S_OBJS)
@-$(RM) -rf $(RUST_TARGET_DIR)

@ -1,8 +1,13 @@
include ../sgxenv.mk
LIBOCCLUM_PAL_SO := $(BUILD_DIR)/lib/libocclum-pal.so
LIBOCCLUM_PAL_SONAME := $(LIBOCCLUM_PAL_SO).$(MAJOR_VER_NUM)
LIBOCCLUM_PAL_SO_REAL := $(LIBOCCLUM_PAL_SO).$(VERSION_NUM)
LIBOCCLUM_PAL_SONAME := libocclum-pal.so.$(MAJOR_VER_NUM)
ifneq ($(SGX_MODE), HW)
LIBOCCLUM_PAL_SO_REAL := $(BUILD_DIR)/lib/libocclum-pal_sim.so.$(VERSION_NUM)
else
LIBOCCLUM_PAL_SO_REAL := $(BUILD_DIR)/lib/libocclum-pal.so.$(VERSION_NUM)
endif
# A dependency on Rust SGX SDK
LIBSGX_USTDC_A := $(BUILD_DIR)/lib/libsgx_ustdc.a
@ -21,7 +26,7 @@ CXX_FLAGS := $(C_COMMON_FLAGS) $(SGX_CXXFLAGS_U)
LINK_FLAGS := $(SGX_LFLAGS_U) -shared -L$(RUST_SGX_SDK_DIR)/sgx_ustdc/ -lsgx_ustdc -lsgx_uprotected_fs
LINK_FLAGS += -Wl,--version-script=pal.lds
ALL_BUILD_SUBDIRS := $(sort $(patsubst %/,%,$(dir $(LIBOCCLUM_PAL_SO) $(EDL_C_OBJS) $(C_OBJS) $(CXX_OBJS))))
ALL_BUILD_SUBDIRS := $(sort $(patsubst %/,%,$(dir $(LIBOCCLUM_PAL_SO_REAL) $(EDL_C_OBJS) $(C_OBJS) $(CXX_OBJS))))
.PHONY: all format format-check clean
@ -32,6 +37,7 @@ $(ALL_BUILD_SUBDIRS):
$(LIBOCCLUM_PAL_SO_REAL): $(LIBSGX_USTDC_A) $(EDL_C_OBJS) $(C_OBJS) $(CXX_OBJS)
@$(CXX) $^ -o $@ $(LINK_FLAGS) -Wl,-soname=$(LIBOCCLUM_PAL_SONAME)
@# Create symbolic files because occlum run and exec will need it when linking.
@cd $(BUILD_DIR)/lib && ln -sf $(notdir $(LIBOCCLUM_PAL_SO_REAL)) $(notdir $(LIBOCCLUM_PAL_SONAME)) && \
ln -sf $(notdir $(LIBOCCLUM_PAL_SONAME)) $(notdir $(LIBOCCLUM_PAL_SO))
@echo "LINK => $@"

@ -14,11 +14,7 @@ VERSION_NUM = $(MAJOR_VER_NUM).$(MINOR_VER_NUM).$(PATCH_VER_NUM)
C_FORMATTER := $(PROJECT_DIR)/tools/c_formatter
ifneq ($(SGX_MODE), HW)
BUILD_DIR := $(PROJECT_DIR)/build_sim
else
BUILD_DIR := $(PROJECT_DIR)/build
endif
BUILD_DIR := $(PROJECT_DIR)/build
# If OCCLUM_RELEASE_BUILD equals to 1, y, or yes, then build in release mode
OCCLUM_RELEASE_BUILD ?= 0

@ -7,11 +7,7 @@ CXX_SRCS := $(wildcard */*.cc)
C_FORMATTER := $(PROJECT_DIR)/tools/c_formatter
ifneq ($(SGX_MODE), HW)
BUILD_DIR := $(PROJECT_DIR)/build_sim
else
BUILD_DIR := $(PROJECT_DIR)/build
endif
BUILD_DIR := $(PROJECT_DIR)/build
PASS_LOG = $(BUILD_DIR)/test/.pass
FAIL_LOG = $(BUILD_DIR)/test/.fail

@ -5,12 +5,7 @@ PROJECT_DIR := $(realpath $(CUR_DIR)/../../)
SGX_MODE ?= HW
EXTRA_ENV :=
ifneq ($(SGX_MODE), HW)
BUILD_DIR := $(PROJECT_DIR)/build_sim
else
BUILD_DIR := $(PROJECT_DIR)/build
endif
BUILD_DIR := $(PROJECT_DIR)/build
TEST_NAME := $(shell basename $(CUR_DIR))
IMAGE_DIR := $(BUILD_DIR)/test/image
BIN := $(IMAGE_DIR)/bin/$(TEST_NAME)

@ -1,10 +1,5 @@
SGX_MODE ?= HW
ifneq ($(SGX_MODE), HW)
BUILD_DIR := build_sim
else
BUILD_DIR := build
endif
BUILD_DIR := build
.PHONY: all format format-check clean

@ -2,7 +2,17 @@
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
occlum_dir="$( cd "$( dirname "$this_dir/../../../" )" >/dev/null 2>&1 && pwd )"
occlum_major_ver=0
if [[ "$occlum_dir" == "/opt/occlum" ]]; then
version_header=$occlum_dir/include/occlum_version.h
else
version_header=$occlum_dir/src/pal/include/occlum_version.h
fi
major_ver=`grep '\#define OCCLUM_MAJOR_VERSION' $version_header | awk '{print $3}'`
minor_ver=`grep '\#define OCCLUM_MINOR_VERSION' $version_header | awk '{print $3}'`
patch_ver=`grep '\#define OCCLUM_PATCH_VERSION' $version_header | awk '{print $3}'`
occlum_version="$major_ver.$minor_ver.$patch_ver"
if [ -z $OCCLUM_INSTANCE_DIR ];then
OCCLUM_INSTANCE_DIR=".occlum"
@ -139,6 +149,8 @@ cmd_build() {
check_has_init
build_dir=build
pal_lib=libocclum-pal.so
libos_lib=libocclum-libos.so
while [ -n "$1" ]; do
case "$1" in
@ -155,7 +167,8 @@ cmd_build() {
if [[ -n $SGX_MODE && "$SGX_MODE" != "HW" ]]; then
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SGX_SDK/sdk_libs
build_dir=build_sim
pal_lib=libocclum-pal_sim.so
libos_lib=libocclum-libos_sim.so
echo "SGX mode: $SGX_MODE"
else
echo "SGX mode: HW"
@ -168,9 +181,11 @@ cmd_build() {
rm -rf run
mkdir -p build/bin
cp "$occlum_dir/$build_dir/bin/occlum-run" build/bin/
ln -s $occlum_dir/$build_dir/bin/occlum-run $context_dir/build/bin/occlum-run
mkdir -p build/lib
cp "$occlum_dir/$build_dir/lib/libocclum-pal.so.$occlum_major_ver" build/lib/
cp "$occlum_dir/$build_dir/lib/$pal_lib.$occlum_version" build/lib/
cd build/lib && ln -sf "$pal_lib.$occlum_version" "libocclum-pal.so.$major_ver" && \
ln -sf "libocclum-pal.so.$major_ver" libocclum-pal.so && cd -
chmod 531 -R $working_dir/image/bin
chmod 531 -R $working_dir/image/lib
@ -200,9 +215,9 @@ cmd_build() {
echo "EXPORT => OCCLUM_BUILTIN_VM_USER_SPACE_SIZE = $OCCLUM_BUILTIN_VM_USER_SPACE_SIZE"
cd $context_dir/build/lib && \
cp "$occlum_dir/$build_dir/lib/libocclum-libos.so.$occlum_major_ver" .
cp "$occlum_dir/$build_dir/lib/$libos_lib.$occlum_version" . && ln -sf "$libos_lib.$occlum_version" "libocclum-libos.so.$major_ver"
echo -e "$OCCLUM_BUILTIN_CONF_FILE_MAC\c" > temp_mac_file && \
objcopy --update-section .builtin_config=temp_mac_file libocclum-libos.so.$occlum_major_ver && \
objcopy --update-section .builtin_config=temp_mac_file libocclum-libos.so.$major_ver && \
rm temp_mac_file
$occlum_dir/$build_dir/bin/gen_enclave_conf -i "$working_dir/Occlum.json" -o "$context_dir/build/Enclave.xml"
@ -210,7 +225,7 @@ cmd_build() {
$ENCLAVE_SIGN_TOOL sign \
-key $ENCLAVE_SIGN_KEY \
-config "$context_dir/build/Enclave.xml" \
-enclave "$context_dir/build/lib/libocclum-libos.so.$occlum_major_ver" \
-enclave "$context_dir/build/lib/libocclum-libos.so.$major_ver" \
-out "$context_dir/build/lib/libocclum-libos.signed.so"
rm -f "$context_dir/build/Enclave.xml"
cd "$context_dir"

@ -15,11 +15,7 @@ SGX_DEBUG ?= 1
C_FORMATTER := $(PROJECT_DIR)/tools/c_formatter
ifneq ($(SGX_MODE), HW)
BUILD_DIR := $(PROJECT_DIR)/build_sim
else
BUILD_DIR := $(PROJECT_DIR)/build
endif
BUILD_DIR := $(PROJECT_DIR)/build
OBJS_DIR := $(BUILD_DIR)/tools/protect-integrity
ifeq ($(shell getconf LONG_BIT), 32)