forked from scrtlabs/SecretNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
365 lines (294 loc) Β· 15 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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
PACKAGES=$(shell go list ./... | grep -v '/simulation')
VERSION ?= $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
LEDGER_ENABLED ?= true
BINDIR ?= $(GOPATH)/bin
BUILD_PROFILE ?= release
DEB_BIN_DIR ?= /usr/local/bin
DEB_LIB_DIR ?= /usr/lib
SGX_MODE ?= HW
BRANCH ?= develop
DEBUG ?= 0
DOCKER_TAG ?= latest
ifeq ($(SGX_MODE), HW)
ext := hw
else ifeq ($(SGX_MODE), SW)
ext := sw
else
$(error SGX_MODE must be either HW or SW)
endif
SGX_MODE ?= HW
BRANCH ?= develop
DEBUG ?= 0
DOCKER_TAG ?= latest
CUR_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
ifeq ($(SGX_MODE), HW)
ext := hw
else ifeq ($(SGX_MODE), SW)
ext := sw
else
$(error SGX_MODE must be either HW or SW)
endif
build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error "gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false")
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning "OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)")
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error "gcc not installed for ledger support, please install or set LEDGER_ENABLED=false")
else
build_tags += ledger
endif
endif
endif
endif
IAS_BUILD = sw
ifeq ($(SGX_MODE), HW)
ifneq (,$(findstring production,$(FEATURES)))
IAS_BUILD = production
else
IAS_BUILD = develop
endif
build_tags += hw
endif
build_tags += $(IAS_BUILD)
ifeq ($(WITH_CLEVELDB),yes)
build_tags += gcc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
whitespace :=
whitespace += $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
ldflags = -X github.com/enigmampc/cosmos-sdk/version.Name=SecretNetwork \
-X github.com/enigmampc/cosmos-sdk/version.ServerName=secretd \
-X github.com/enigmampc/cosmos-sdk/version.ClientName=secretcli \
-X github.com/enigmampc/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/enigmampc/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/enigmampc/cosmos-sdk/version.BuildTags=$(build_tags)"
ifeq ($(WITH_CLEVELDB),yes)
ldflags += -X github.com/enigmampc/cosmos-sdk/types.DBBackend=cleveldb
endif
ldflags += -s -w
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
GO_TAGS := $(build_tags)
# -ldflags
LD_FLAGS := $(ldflags)
all: build_all
vendor:
cargo vendor third_party/vendor --manifest-path third_party/build/Cargo.toml
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify
xgo_build_secretcli: go.sum
@echo "--> WARNING! This builds from origin/$(CURRENT_BRANCH)!"
xgo --go latest --targets $(XGO_TARGET) -tags="$(GO_TAGS) secretcli" -ldflags '$(LD_FLAGS)' --branch "$(CURRENT_BRANCH)" github.com/enigmampc/SecretNetwork/cmd/secretcli
build_local_cli:
go build -mod=readonly -tags "$(GO_TAGS) secretcli" -ldflags '$(LD_FLAGS)' ./cmd/secretcli
build_local_no_rust: build_local_cli bin-data-$(IAS_BUILD)
cp go-cosmwasm/target/release/libgo_cosmwasm.so go-cosmwasm/api
go build -mod=readonly -tags "$(GO_TAGS)" -ldflags '$(LD_FLAGS)' ./cmd/secretd
build-linux: vendor bin-data-$(IAS_BUILD)
BUILD_PROFILE=$(BUILD_PROFILE) $(MAKE) -C go-cosmwasm build-rust
cp go-cosmwasm/target/$(BUILD_PROFILE)/libgo_cosmwasm.so go-cosmwasm/api
# this pulls out ELF symbols, 80% size reduction!
go build -mod=readonly -tags "$(GO_TAGS)" -ldflags '$(LD_FLAGS)' ./cmd/secretd
go build -mod=readonly -tags "$(GO_TAGS) secretcli" -ldflags '$(LD_FLAGS)' ./cmd/secretcli
build_windows_cli:
$(MAKE) xgo_build_secretcli XGO_TARGET=windows/amd64
build_macos_cli:
$(MAKE) xgo_build_secretcli XGO_TARGET=darwin/amd64
build_linux_cli:
$(MAKE) xgo_build_secretcli XGO_TARGET=linux/amd64
build_linux_arm64_cli:
$(MAKE) xgo_build_secretcli XGO_TARGET=linux/arm64
build_all: build-linux build_windows_cli build_macos_cli build_linux_arm64_cli
deb: build-linux deb-no-compile
deb-no-compile:
ifneq ($(UNAME_S),Linux)
exit 1
endif
rm -rf /tmp/SecretNetwork
mkdir -p /tmp/SecretNetwork/deb/$(DEB_BIN_DIR)
mv -f ./secretcli /tmp/SecretNetwork/deb/$(DEB_BIN_DIR)/secretcli
mv -f ./secretd /tmp/SecretNetwork/deb/$(DEB_BIN_DIR)/secretd
chmod +x /tmp/SecretNetwork/deb/$(DEB_BIN_DIR)/secretd /tmp/SecretNetwork/deb/$(DEB_BIN_DIR)/secretcli
mkdir -p /tmp/SecretNetwork/deb/$(DEB_LIB_DIR)
cp -f ./go-cosmwasm/api/libgo_cosmwasm.so ./go-cosmwasm/librust_cosmwasm_enclave.signed.so /tmp/SecretNetwork/deb/$(DEB_LIB_DIR)/
chmod +x /tmp/SecretNetwork/deb/$(DEB_LIB_DIR)/lib*.so
mkdir -p /tmp/SecretNetwork/deb/DEBIAN
cp ./deployment/deb/control /tmp/SecretNetwork/deb/DEBIAN/control
printf "Version: " >> /tmp/SecretNetwork/deb/DEBIAN/control
printf "$(VERSION)" >> /tmp/SecretNetwork/deb/DEBIAN/control
echo "" >> /tmp/SecretNetwork/deb/DEBIAN/control
cp ./deployment/deb/postinst /tmp/SecretNetwork/deb/DEBIAN/postinst
chmod 755 /tmp/SecretNetwork/deb/DEBIAN/postinst
cp ./deployment/deb/postrm /tmp/SecretNetwork/deb/DEBIAN/postrm
chmod 755 /tmp/SecretNetwork/deb/DEBIAN/postrm
cp ./deployment/deb/triggers /tmp/SecretNetwork/deb/DEBIAN/triggers
chmod 755 /tmp/SecretNetwork/deb/DEBIAN/triggers
dpkg-deb --build /tmp/SecretNetwork/deb/ .
-rm -rf /tmp/SecretNetwork
rename_for_release:
-rename "s/windows-4.0-amd64/v${VERSION}-win64/" *.exe
-rename "s/darwin-10.6-amd64/v${VERSION}-osx64/" *darwin*
sign_for_release: rename_for_release
sha256sum enigma-blockchain*.deb > SHA256SUMS
-sha256sum secretd-* secretcli-* >> SHA256SUMS
gpg -u 91831DE812C6415123AFAA7B420BF1CB005FBCE6 --digest-algo sha256 --clearsign --yes SHA256SUMS
rm -f SHA256SUMS
release: sign_for_release
rm -rf ./release/
mkdir -p ./release/
cp enigma-blockchain_*.deb ./release/
cp secretcli-* ./release/
cp secretd-* ./release/
cp SHA256SUMS.asc ./release/
clean:
-rm -rf /tmp/SecretNetwork
-rm -f ./secretcli*
-rm -f ./secretd*
# -find -name librust_cosmwasm_enclave.signed.so -delete
# -find -name libgo_cosmwasm.so -delete
# -find -name '*.so' -delete
# -find -name 'target' -type d -exec rm -rf \;
-rm -f ./enigma-blockchain*.deb
-rm -f ./SHA256SUMS*
-rm -rf ./third_party/vendor/
-rm -rf ./.sgx_secrets/*
-rm -rf ./x/compute/internal/keeper/.sgx_secrets/*
-rm -rf ./*.der
-rm -rf ./x/compute/internal/keeper/*.der
-rm -rf ./cmd/secretd/ias_bin*
$(MAKE) -C go-cosmwasm clean-all
$(MAKE) -C cosmwasm/packages/wasmi-runtime clean
build-dev-image:
docker build --build-arg BUILD_VERSION=${VERSION} --build-arg SGX_MODE=SW --build-arg FEATURES="${FEATURES},debug-print" -f deployment/dockerfiles/base.Dockerfile -t rust-go-base-image .
docker build --build-arg SGX_MODE=SW --build-arg SECRET_NODE_TYPE=BOOTSTRAP -f deployment/dockerfiles/release.Dockerfile -t enigmampc/secret-network-sw-dev:${DOCKER_TAG} .
build-testnet: docker_base
@mkdir build 2>&3 || true
docker build --build-arg BUILD_VERSION=${VERSION} --build-arg SGX_MODE=HW --build-arg SECRET_NODE_TYPE=BOOTSTRAP -f deployment/dockerfiles/release.Dockerfile -t enigmampc/secret-network-bootstrap:v$(VERSION)-testnet .
docker build --build-arg BUILD_VERSION=${VERSION} --build-arg SGX_MODE=HW --build-arg SECRET_NODE_TYPE=NODE -f deployment/dockerfiles/release.Dockerfile -t enigmampc/secret-network-node:v$(VERSION)-testnet .
docker build --build-arg BUILD_VERSION=${VERSION} --build-arg SGX_MODE=HW -f deployment/dockerfiles/build-deb.Dockerfile -t deb_build .
docker run -e VERSION=${VERSION} -v $(CUR_DIR)/build:/build deb_build
build-mainnet:
@mkdir build 2>&3 || true
docker build --build-arg BUILD_VERSION=${VERSION} --build-arg SGX_MODE=HW --build-arg FEATURES=production -f deployment/dockerfiles/base.Dockerfile -t rust-go-base-image .
docker build --build-arg SGX_MODE=HW --build-arg SECRET_NODE_TYPE=BOOTSTRAP -f deployment/dockerfiles/release.Dockerfile -t enigmampc/secret-network-bootstrap:v$(VERSION)-mainnet .
docker build --build-arg SGX_MODE=HW --build-arg SECRET_NODE_TYPE=NODE -f deployment/dockerfiles/release.Dockerfile -t enigmampc/secret-network-node:v$(VERSION)-mainnet .
docker build --build-arg BUILD_VERSION=${VERSION} --build-arg SGX_MODE=HW -f deployment/dockerfiles/build-deb.Dockerfile -t deb_build .
docker run -e VERSION=${VERSION} -v $(CUR_DIR)/build:/build deb_build
docker_base:
docker build --build-arg FEATURES=${FEATURES} --build-arg SGX_MODE=${SGX_MODE} -f deployment/dockerfiles/base.Dockerfile -t rust-go-base-image .
docker_bootstrap: docker_base
docker build --build-arg SGX_MODE=${SGX_MODE} --build-arg SECRET_NODE_TYPE=BOOTSTRAP -f deployment/dockerfiles/local-node.Dockerfile -t enigmampc/secret-network-bootstrap-${ext}:${DOCKER_TAG} .
docker_node: docker_base
docker build --build-arg SGX_MODE=${SGX_MODE} --build-arg SECRET_NODE_TYPE=NODE -f deployment/dockerfiles/local-node.Dockerfile -t enigmampc/secret-network-node-${ext}:${DOCKER_TAG} .
docker_local_azure_hw: docker_base
docker build --build-arg SGX_MODE=HW --build-arg SECRET_NODE_TYPE=NODE -f deployment/dockerfiles/local-node.Dockerfile -t ci-enigma-sgx-node .
docker build --build-arg SGX_MODE=HW --build-arg SECRET_NODE_TYPE=BOOTSTRAP -f deployment/dockerfiles/local-node.Dockerfile -t ci-enigma-sgx-bootstrap .
docker_enclave_test:
docker build --build-arg FEATURES="test ${FEATURES}" --build-arg SGX_MODE=${SGX_MODE} -f deployment/dockerfiles/enclave-test.Dockerfile -t rust-enclave-test .
# while developing:
build-enclave: vendor
$(MAKE) -C cosmwasm/packages/wasmi-runtime
# while developing:
check-enclave:
$(MAKE) -C cosmwasm/packages/wasmi-runtime check
# while developing:
clippy-enclave:
$(MAKE) -C cosmwasm/packages/wasmi-runtime clippy
# while developing:
clean-enclave:
$(MAKE) -C cosmwasm/packages/wasmi-runtime clean
sanity-test:
SGX_MODE=SW $(MAKE) build-linux
cp ./cosmwasm/packages/wasmi-runtime/librust_cosmwasm_enclave.signed.so .
SGX_MODE=SW ./cosmwasm/testing/sanity-test.sh
sanity-test-hw:
$(MAKE) build-linux
cp ./cosmwasm/packages/wasmi-runtime/librust_cosmwasm_enclave.signed.so .
./cosmwasm/testing/sanity-test.sh
callback-sanity-test:
SGX_MODE=SW $(MAKE) build-linux
cp ./cosmwasm/packages/wasmi-runtime/librust_cosmwasm_enclave.signed.so .
SGX_MODE=SW ./cosmwasm/testing/callback-test.sh
build-test-contract:
# echo "" | sudo add-apt-repository ppa:hnakamur/binaryen
# sudo apt update
# sudo apt install -y binaryen
$(MAKE) -C ./x/compute/internal/keeper/testdata/test-contract
prep-go-tests: build-test-contract
# empty BUILD_PROFILE means debug mode which compiles faster
SGX_MODE=SW $(MAKE) build-linux
cp ./cosmwasm/packages/wasmi-runtime/librust_cosmwasm_enclave.signed.so ./x/compute/internal/keeper
go-tests: build-test-contract
# empty BUILD_PROFILE means debug mode which compiles faster
SGX_MODE=SW $(MAKE) build-linux
cp ./cosmwasm/packages/wasmi-runtime/librust_cosmwasm_enclave.signed.so ./x/compute/internal/keeper
rm -rf ./x/compute/internal/keeper/.sgx_secrets
mkdir -p ./x/compute/internal/keeper/.sgx_secrets
SGX_MODE=SW go test -timeout 1200s -p 1 -v ./x/compute/internal/... $(GO_TEST_ARGS)
go-tests-hw: build-test-contract
# empty BUILD_PROFILE means debug mode which compiles faster
SGX_MODE=HW $(MAKE) build-linux
cp ./cosmwasm/packages/wasmi-runtime/librust_cosmwasm_enclave.signed.so ./x/compute/internal/keeper
rm -rf ./x/compute/internal/keeper/.sgx_secrets
mkdir -p ./x/compute/internal/keeper/.sgx_secrets
SGX_MODE=HW go test -p 1 -v ./x/compute/internal/... $(GO_TEST_ARGS)
.PHONY: enclave-tests
enclave-tests:
$(MAKE) -C cosmwasm/packages/enclave-test run
build-all-test-contracts: build-test-contract
# echo "" | sudo add-apt-repository ppa:hnakamur/binaryen
# sudo apt update
# sudo apt install -y binaryen
cd ./cosmwasm/contracts/gov && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked
wasm-opt -Os ./cosmwasm/contracts/gov/target/wasm32-unknown-unknown/release/gov.wasm -o ./x/compute/internal/keeper/testdata/gov.wasm
cd ./cosmwasm/contracts/dist && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked
wasm-opt -Os ./cosmwasm/contracts/dist/target/wasm32-unknown-unknown/release/dist.wasm -o ./x/compute/internal/keeper/testdata/dist.wasm
cd ./cosmwasm/contracts/mint && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked
wasm-opt -Os ./cosmwasm/contracts/mint/target/wasm32-unknown-unknown/release/mint.wasm -o ./x/compute/internal/keeper/testdata/mint.wasm
cd ./cosmwasm/contracts/staking && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked
wasm-opt -Os ./cosmwasm/contracts/staking/target/wasm32-unknown-unknown/release/staking.wasm -o ./x/compute/internal/keeper/testdata/staking.wasm
cd ./cosmwasm/contracts/reflect && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked
wasm-opt -Os ./cosmwasm/contracts/reflect/target/wasm32-unknown-unknown/release/reflect.wasm -o ./x/compute/internal/keeper/testdata/reflect.wasm
cd ./cosmwasm/contracts/burner && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked
wasm-opt -Os ./cosmwasm/contracts/burner/target/wasm32-unknown-unknown/release/burner.wasm -o ./x/compute/internal/keeper/testdata/burner.wasm
cd ./cosmwasm/contracts/erc20 && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked
wasm-opt -Os ./cosmwasm/contracts/erc20/target/wasm32-unknown-unknown/release/cw_erc20.wasm -o ./x/compute/internal/keeper/testdata/erc20.wasm
cd ./cosmwasm/contracts/hackatom && RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked
wasm-opt -Os ./cosmwasm/contracts/hackatom/target/wasm32-unknown-unknown/release/hackatom.wasm -o ./x/compute/internal/keeper/testdata/contract.wasm
cat ./x/compute/internal/keeper/testdata/contract.wasm | gzip > ./x/compute/internal/keeper/testdata/contract.wasm.gzip
bin-data: bin-data-sw bin-data-develop bin-data-production
bin-data-sw:
cd ./cmd/secretd && go-bindata -o ias_bin_sw.go -prefix "../../ias_keys/sw_dummy/" -tags "!hw" ../../ias_keys/sw_dummy/...
bin-data-develop:
cd ./cmd/secretd && go-bindata -o ias_bin_dev.go -prefix "../../ias_keys/develop/" -tags "develop,hw" ../../ias_keys/develop/...
bin-data-production:
cd ./cmd/secretd && go-bindata -o ias_bin_prod.go -prefix "../../ias_keys/production/" -tags "production,hw" ../../ias_keys/production/...
secret-contract-optimizer:
docker build -f deployment/dockerfiles/secret-contract-optimizer.Dockerfile -t enigmampc/secret-contract-optimizer:${TAG} .
docker tag enigmampc/secret-contract-optimizer:${TAG} enigmampc/secret-contract-optimizer:latest
secretjs-build:
cd cosmwasm-js/packages/sdk && yarn && yarn build
# Before running this, first make sure:
# 1. To `npm login` with enigma-dev
# 2. The new version is updated in `cosmwasm-js/packages/sdk/package.json`
secretjs-publish-npm: secretjs-build
cd cosmwasm-js/packages/sdk && npm publish
aesm-image:
docker build -f deployment/dockerfiles/aesm.Dockerfile -t enigmampc/aesm .