-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathMakefile
More file actions
201 lines (159 loc) · 6.82 KB
/
Makefile
File metadata and controls
201 lines (159 loc) · 6.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# 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.
######## SGX SDK Settings ########
SGX_SDK ?= /opt/intel/sgxsdk
SGX_MODE ?= HW
SGX_ARCH ?= x64
TOP_DIR := ../..
include $(TOP_DIR)/buildenv.mk
ifeq ($(shell getconf LONG_BIT), 32)
SGX_ARCH := x86
else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32)
SGX_ARCH := x86
endif
ifeq ($(SGX_ARCH), x86)
SGX_COMMON_CFLAGS := -m32
SGX_LIBRARY_PATH := $(SGX_SDK)/lib
SGX_BIN_PATH := $(SGX_SDK)/bin/x86
else
SGX_COMMON_CFLAGS := -m64
SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
SGX_BIN_PATH := $(SGX_SDK)/bin/x64
endif
ifeq ($(SGX_DEBUG), 1)
SGX_COMMON_CFLAGS += -O0 -g
Rust_Build_Flags :=
Rust_Build_Out := debug
else
SGX_COMMON_CFLAGS += -O2
Rust_Build_Flags := --release
Rust_Build_Out := release
endif
SGX_EDGER8R := $(SGX_BIN_PATH)/sgx_edger8r
ifneq ($(SGX_MODE), HYPER)
SGX_ENCLAVE_SIGNER := $(SGX_BIN_PATH)/sgx_sign
else
SGX_ENCLAVE_SIGNER := $(SGX_BIN_PATH)/sgx_sign_hyper
SGX_EDGER8R_MODE := --sgx-mode $(SGX_MODE)
endif
######## CUSTOM Settings ########
CUSTOM_LIBRARY_PATH := ./lib
CUSTOM_BIN_PATH := ./bin
CUSTOM_SYSROOT_PATH := ./sysroot
CUSTOM_EDL_PATH := $(ROOT_DIR)/sgx_edl/edl
CUSTOM_COMMON_PATH := $(ROOT_DIR)/common
######## EDL Settings ########
Enclave_EDL_Files := enclave/enclave_t.c enclave/enclave_t.h app/enclave_u.c app/enclave_u.h
######## APP Settings ########
App_Rust_Flags := $(Rust_Build_Flags)
App_Src_Files := $(shell find app/ -type f -name '*.rs') $(shell find app/ -type f -name 'Cargo.toml')
App_Include_Paths := -I ./app -I$(SGX_SDK)/include -I$(CUSTOM_COMMON_PATH)/inc -I$(CUSTOM_EDL_PATH)
App_C_Flags := $(CFLAGS) $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths)
App_Rust_Path := ./app/target/$(Rust_Build_Out)
App_Enclave_u_Object := $(CUSTOM_LIBRARY_PATH)/libenclave_u.a
App_Name := $(CUSTOM_BIN_PATH)/app
######## Enclave Settings ########
# BUILD_STD=no use no_std
# BUILD_STD=cargo use cargo-std-aware
# BUILD_STD=xargo use xargo
BUILD_STD ?= cargo
Rust_Build_Target := x86_64-unknown-linux-sgx
Rust_Target_Path := $(ROOT_DIR)/rustlib
ifneq ($(BUILD_STD), cargo)
ifneq ($(BUILD_STD), xargo)
$(error Only supports building with build_std strategy!!)
endif
endif
ifeq ($(BUILD_STD), cargo)
Rust_Build_Std := $(Rust_Build_Flags) -Zbuild-std=core,alloc
Rust_Std_Features := --features net,thread,untrusted_time,untrusted_fs,unsupported_process
Rust_Target_Flags := --target $(Rust_Target_Path)/$(Rust_Build_Target).json
Rust_Sysroot_Path := $(CURDIR)/sysroot
Rust_Sysroot_Flags := RUSTFLAGS="--sysroot $(Rust_Sysroot_Path)"
else
Rust_Unstable_Flags := RUSTFLAGS="-Z force-unstable-if-unmarked"
endif
RustEnclave_Build_Flags := $(Rust_Build_Flags)
RustEnclave_Src_Files := $(shell find enclave/ -type f -name '*.rs') $(shell find enclave/ -type f -name 'Cargo.toml')
RustEnclave_Include_Paths := -I$(CUSTOM_COMMON_PATH)/inc -I$(CUSTOM_COMMON_PATH)/inc/tlibc -I$(CUSTOM_EDL_PATH)
RustEnclave_Link_Libs := -L$(CUSTOM_LIBRARY_PATH) -lenclave
RustEnclave_C_Flags := $(CFLAGS) $(ENCLAVE_CFLAGS) $(SGX_COMMON_CFLAGS) $(RustEnclave_Include_Paths)
RustEnclave_Link_Flags := -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles \
-Wl,--start-group $(RustEnclave_Link_Libs) -Wl,--end-group \
-Wl,--version-script=enclave/enclave.lds \
$(ENCLAVE_LDFLAGS)
RustEnclave_Out_Path := ./enclave/target/$(Rust_Build_Target)/$(Rust_Build_Out)
RustEnclave_Lib_Name := $(RustEnclave_Out_Path)/libhttps.a
RustEnclave_Name := $(CUSTOM_BIN_PATH)/enclave.so
RustEnclave_Signed_Name := $(CUSTOM_BIN_PATH)/enclave.signed.so
.PHONY: all
all: $(Enclave_EDL_Files) $(App_Name) $(RustEnclave_Signed_Name)
######## EDL Objects ########
$(Enclave_EDL_Files): $(SGX_EDGER8R) enclave/enclave.edl
$(SGX_EDGER8R) $(SGX_EDGER8R_MODE) --trusted enclave/enclave.edl --search-path $(CUSTOM_COMMON_PATH)/inc --search-path $(CUSTOM_EDL_PATH) --trusted-dir enclave
$(SGX_EDGER8R) $(SGX_EDGER8R_MODE) --untrusted enclave/enclave.edl --search-path $(CUSTOM_COMMON_PATH)/inc --search-path $(CUSTOM_EDL_PATH) --untrusted-dir app
@echo "GEN => $(Enclave_EDL_Files)"
######## App Objects ########
app/enclave_u.o: $(Enclave_EDL_Files)
@$(CC) $(App_C_Flags) -c app/enclave_u.c -o $@
$(App_Enclave_u_Object): app/enclave_u.o
@mkdir -p $(CUSTOM_LIBRARY_PATH)
@$(AR) rcsD $@ $^
$(App_Name): $(App_Enclave_u_Object) app
@mkdir -p $(CUSTOM_BIN_PATH)
@cp $(App_Rust_Path)/app $(CUSTOM_BIN_PATH)
@echo "LINK => $@"
######## Enclave Objects ########
enclave/enclave_t.o: $(Enclave_EDL_Files)
@$(CC) $(RustEnclave_C_Flags) -c enclave/enclave_t.c -o $@
$(RustEnclave_Name): enclave/enclave_t.o enclave
@mkdir -p $(CUSTOM_LIBRARY_PATH)
@mkdir -p $(CUSTOM_BIN_PATH)
@cp $(RustEnclave_Lib_Name) $(CUSTOM_LIBRARY_PATH)/libenclave.a
@$(CXX) enclave/enclave_t.o -o $@ $(RustEnclave_Link_Flags)
@echo "LINK => $@"
$(RustEnclave_Signed_Name): $(RustEnclave_Name) enclave/config.xml
@$(SGX_ENCLAVE_SIGNER) sign -key enclave/private.pem -enclave $(RustEnclave_Name) -out $@ -config enclave/config.xml
@echo "SIGN => $@"
######## Build App ########
.PHONY: app
app:
@cd app && SGX_SDK=$(SGX_SDK) cargo build $(App_Rust_Flags)
######## Build Enclave ########
.PHONY: enclave
enclave:
ifeq ($(BUILD_STD), cargo)
@cd $(Rust_Target_Path)/std && cargo build $(Rust_Build_Std) $(Rust_Target_Flags) $(Rust_Std_Features)
@rm -rf $(Rust_Sysroot_Path)
@mkdir -p $(Rust_Sysroot_Path)/lib/rustlib/$(Rust_Build_Target)/lib
@cp -r $(Rust_Target_Path)/std/target/$(Rust_Build_Target)/$(Rust_Build_Out)/deps/* $(Rust_Sysroot_Path)/lib/rustlib/$(Rust_Build_Target)/lib
@cd enclave && $(Rust_Sysroot_Flags) cargo build $(Rust_Target_Flags) $(RustEnclave_Build_Flags)
else
@cd enclave && $(Rust_Unstable_Flags) RUST_TARGET_PATH=$(Rust_Target_Path) xargo build --target $(Rust_Build_Target) $(RustEnclave_Build_Flags)
endif
######## Run Enclave ########
.PHONY: run
run: $(App_Name) $(RustEnclave_Signed_Name)
@echo -e '\n===== Run Enclave =====\n'
@cd bin && ./app
.PHONY: clean
clean:
@rm -f $(App_Name) $(RustEnclave_Name) $(RustEnclave_Signed_Name) enclave/*_t.* app/*_u.*
@cd enclave && cargo clean
@cd app && cargo clean
@cd $(Rust_Target_Path)/std && cargo clean
@rm -rf $(CUSTOM_BIN_PATH) $(CUSTOM_LIBRARY_PATH) $(CUSTOM_SYSROOT_PATH)