-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
126 lines (98 loc) · 3.18 KB
/
Makefile
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
BUILD_PROFILE ?= release
TOP_DIR := ./
include $(TOP_DIR)/buildenv.mk
FEATURES ?=
FEATURES_U += $(FEATURES)
FEATURES_U := $(strip $(FEATURES_U))
DOCKER_TAG := 0.8.2
USER_ID := $(shell id -u)
USER_GROUP = $(shell id -g)
DLL_EXT = ""
ifeq ($(OS),Windows_NT)
DLL_EXT = dll
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
DLL_EXT = so
endif
ifeq ($(UNAME_S),Darwin)
DLL_EXT = dylib
endif
endif
SGX_SDK ?= $(HOME)/opt/sgxsdk
ifeq ($(SGX_ARCH), x86)
SGX_COMMON_CFLAGS := -m32
SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r
else
SGX_COMMON_CFLAGS := -m64
SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r
endif
ifeq ($(SGX_DEBUG), 1)
SGX_COMMON_CFLAGS += -O0 -g
else
SGX_COMMON_CFLAGS += -O2
endif
SGX_COMMON_CFLAGS += -fstack-protector
CUSTOM_EDL_PATH := deps/incubator-teaclave-sgx-sdk/sgx_edl/edl
App_Include_Paths := -I./ -I./include -I$(SGX_SDK)/include -I$(CUSTOM_EDL_PATH)
App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths)
Enclave_Path := packages/enclave
Enclave_EDL_Products := lib/enclave/Enclave_u.c lib/enclave/Enclave_u.h
.PHONY: all
all: build cmd
.PHONY: build
build: build-rust
.PHONY: build-rust
build-rust: build-enclave
cargo build -Z unstable-options --profile $(BUILD_PROFILE) --features "$(FEATURES_U)"
cp target/$(BUILD_PROFILE)/librandom_api.so api
@ #this pulls out ELF symbols, 80% size reduction!
.PHONY: build-enclave
build-enclave: tendermint_enclave.signed.so lib/libEnclave_u.a
tendermint_enclave.signed.so: inner-build-enclave
cp $(Enclave_Path)/$@ ./
.PHONY: inner-build-enclave
inner-build-enclave:
FEATURES="$(FEATURES)" $(MAKE) -C $(Enclave_Path) enclave
# This file will be picked up by the crate's build script and linked into the library.
lib/libEnclave_u.a: $(Enclave_EDL_Products)
$(CC) $(App_C_Flags) -c lib/enclave/Enclave_u.c -o lib/enclave/Enclave_u.o
$(AR) rcsD $@ lib/enclave/Enclave_u.o
# We make sure that the enclave is built before we compile the edl,
# because the EDL depends on a header file that is generated in that process.
$(Enclave_EDL_Products): $(Enclave_Path)/Enclave.edl
mkdir -p "lib/enclave"
$(SGX_EDGER8R) --untrusted $< --search-path $(SGX_SDK)/include --search-path $(CUSTOM_EDL_PATH) --untrusted-dir ./lib/enclave
# implement stripping based on os
.PHONY: strip
ifeq ($(DLL_EXT),so)
strip:
strip api/libgo_cosmwasm.so
else
# TODO: add for windows and osx
strip:
endif
.PHONY: build-go
build-go:
go build -tags 'sgx' -ldflags '-r $(SGX_SDK)/lib64/' -o main ./cmd
.PHONY: cmd
cmd:
RUST_BACKTRACE=1 go build -tags 'sgx' -ldflags '-r $(SGX_SDK)/lib64/' -o main ./cmd
.PHONY: docker-image-alpine
docker-image-alpine:
docker build . -t cosmwasm/go-ext-builder:test-alpine
# and use them to compile release builds
.PHONY: release
release:
rm -rf target/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v /opt/intel/sgxsdk:/opt/intel/sgxsdk -v $(shell pwd):/code/code/ -v $(shell pwd)/../../deps:/deps cosmwasm/go-ext-builder:test-alpine
.PHONY: test-safety
test-safety:
GODEBUG=cgocheck=2 go test -race -v -count 1 ./api
.PHONY: clean
clean:
rm -rf lib $(Enclave_EDL_Products) $(Query_Enclave_EDL_Products) *.o *.so *.h
cargo clean
.PHONY: clean-all
clean-all: clean
$(MAKE) -C $(Enclave_Path) clean