Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
163 lines (123 loc) · 4.91 KB
/
Copy pathMakefile
File metadata and controls
163 lines (123 loc) · 4.91 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
######## LCP Build Settings ########
ZK_PROVER_CUDA ?= 0
APP_CARGO_FLAGS ?=
######## SGX SDK Settings ########
SGX_SDK ?= /opt/sgxsdk
SGX_MODE ?= HW
SGX_DEBUG ?= 0
SGX_ENCLAVE_CONFIG ?= "enclave/Enclave.config.xml"
SGX_SIGN_KEY ?= "enclave/Enclave_private.pem"
SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign
include buildenv.mk
ifeq ($(SGX_DEBUG), 1)
# debug build
CARGO_TARGET :=
OUTPUT_PATH := debug
else
CARGO_TARGET := --release
OUTPUT_PATH := release
endif
######## CUSTOM Settings ########
CUSTOM_LIBRARY_PATH := ./lib
CUSTOM_BIN_PATH := ./bin
######## APP Settings ########
APP_CARGO_FEATURES = --features=default
ifneq ($(SGX_MODE), HW)
APP_CARGO_FEATURES = --features=default,sgx-sw
endif
ifeq ($(ZK_PROVER_CUDA), 1)
APP_CARGO_FEATURES = --features=default,cuda
endif
App_Rust_Flags := $(CARGO_TARGET) $(APP_CARGO_FEATURES) $(APP_CARGO_FLAGS)
App_SRC_Files := $(shell find app/ -type f -name '*.rs') $(shell find app/ -type f -name 'Cargo.toml')
App_Rust_Path := ./target/$(OUTPUT_PATH)
App_Name := lcp
App_Path := $(CUSTOM_BIN_PATH)/$(App_Name)
######## Enclave Settings ########
RustEnclave_Name := enclave/target/x86_64-unknown-unknown-sgx/$(OUTPUT_PATH)/enclave.so
Signed_RustEnclave_Name := bin/enclave.signed.so
######## Targets ########
.PHONY: all
all: $(App_Path) $(Signed_RustEnclave_Name)
.PHONY: clean
clean:
@rm -f $(CUSTOM_LIBRARY_PATH)/* $(CUSTOM_BIN_PATH)/* $(RustEnclave_Name) $(Signed_RustEnclave_Name) enclave/*_t.* app/*_u.*
@cargo clean
@cd enclave && cargo clean
@cd enclave-modules && cargo clean
######## App Objects ########
$(App_Path): $(App_SRC_Files)
@cd app && SGX_SDK=$(SGX_SDK) SGX_MODE=$(SGX_MODE) cargo build $(App_Rust_Flags)
@echo "Cargo => $@"
mkdir -p bin
cp $(App_Rust_Path)/$(App_Name) ./bin
######## Enclave Objects ########
$(Signed_RustEnclave_Name): enclave
mkdir -p bin
@$(SGX_ENCLAVE_SIGNER) sign -key enclave/Enclave_private.pem -enclave $(RustEnclave_Name) -out $@ -config $(SGX_ENCLAVE_CONFIG)
@echo "SIGN => $@"
Enclave_Target_Spec := $(CURDIR)/enclave/x86_64-unknown-unknown-sgx.json
CARGO_SGX_TAG := v0.1.0
.PHONY: enclave-tools
enclave-tools:
@rustup component add rust-src
@command -v cargo-sgx >/dev/null 2>&1 || \
cargo install --git https://github.com/datachainlab/sgx-sdk-rs --tag $(CARGO_SGX_TAG) cargo-sgx --locked
.PHONY: enclave
enclave: enclave-tools
@cd enclave && SGX_SDK=$(SGX_SDK) SGX_MODE=$(SGX_MODE) \
CARGO_UNSTABLE_BUILD_STD=core,alloc \
cargo sgx build --target $(Enclave_Target_Spec) $(CARGO_TARGET)
######## Code generator ########
.PHONY: proto
proto:
@cd proto-compiler && cargo run -- compile --ibc /tmp/cosmos/ibc --out ../proto/src/prost --descriptor ../proto/src/descriptor.bin
######## Lint ########
.PHONY: lint-tools
lint-tools:
rustup component add rustfmt clippy
cargo +nightly install cargo-machete
.PHONY: fmt
fmt:
@cargo fmt --all $(CARGO_FMT_OPT)
@$(TEST_ENCLAVE_CARGO) fmt --all $(CARGO_FMT_OPT)
@cd ./enclave && cargo fmt --all $(CARGO_FMT_OPT)
@cargo fmt --manifest-path tests/integration/Cargo.toml --all $(CARGO_FMT_OPT)
@cargo fmt --manifest-path tools/nodes-runner/Cargo.toml --all $(CARGO_FMT_OPT)
.PHONY: lint
lint:
@$(MAKE) CARGO_FMT_OPT=--check fmt
@cargo clippy --locked --tests $(CARGO_TARGET) -- -D warnings
@$(TEST_ENCLAVE_CARGO) clippy --locked --tests $(CARGO_TARGET) -- -D warnings
@cargo clippy --manifest-path tests/integration/Cargo.toml --locked --tests $(CARGO_TARGET) -- -D warnings
@cargo clippy --manifest-path tools/nodes-runner/Cargo.toml --locked --tests $(CARGO_TARGET) -- -D warnings
@cargo machete
.PHONY: udeps
udeps:
@cargo +nightly install cargo-udeps --locked
@cargo +nightly udeps --locked --lib --tests $(CARGO_TARGET)
######## Tools ########
.PHONY: nodes-runner
nodes-runner:
@cargo build $(CARGO_TARGET) --manifest-path tools/nodes-runner/Cargo.toml
######## Tests ########
TEST_ENCLAVE_RUSTFLAGS="-L $(SGX_SDK)/lib64"
TEST_ENCLAVE_CARGO=RUSTFLAGS=$(TEST_ENCLAVE_RUSTFLAGS) cargo -Z unstable-options -C enclave-modules
TEST_ENCLAVE_CARGO_TEST=$(TEST_ENCLAVE_CARGO) test $(CARGO_TARGET)
GAIAD_VERSION ?= v7.0.3
.PHONY: test
test:
@cargo test $(CARGO_TARGET) --workspace
@$(TEST_ENCLAVE_CARGO_TEST) -p ecall-handler
@$(TEST_ENCLAVE_CARGO_TEST) -p enclave-environment
@$(TEST_ENCLAVE_CARGO_TEST) -p host-api
@$(TEST_ENCLAVE_CARGO_TEST) -p enclave-runtime
@$(TEST_ENCLAVE_CARGO_TEST) -p enclave-utils
.PHONY: integration-test
integration-test: $(Signed_RustEnclave_Name) bin/gaiad
@PATH=${PATH}:$(CURDIR)/bin cargo test $(CARGO_TARGET) --manifest-path tests/integration/Cargo.toml $(APP_CARGO_FEATURES)
.PHONY: test-nodes
test-setup-nodes: bin/gaiad
@PATH=${PATH}:$(CURDIR)/bin cargo run --manifest-path tools/nodes-runner/Cargo.toml --bin test_setup_with_binary_channel
bin/gaiad:
curl -o ./bin/gaiad -LO https://github.com/cosmos/gaia/releases/download/$(GAIAD_VERSION)/gaiad-$(GAIAD_VERSION)-linux-amd64 && chmod +x ./bin/gaiad