-
Notifications
You must be signed in to change notification settings - Fork 45
/
Makefile
234 lines (178 loc) · 7.72 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
CC_TEST_REPORTER_ID := c09efa7c67c269bfdc6f8a356785d8f7ed55c9dc2b9a1d07b78c384f55c4e527
GO_HTML_COV := ./coverage.html
GO_TEST_OUTFILE := ./c.out
CC_PREFIX := github.com/waku-org/go-waku
SHELL := bash # the shell used internally by Make
GOCMD ?= $(shell which go)
.PHONY: all build lint lint-full test coverage build-example static-library dynamic-library test-c test-c-template mobile-android mobile-ios
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
detected_OS := Windows
else
detected_OS := $(strip $(shell uname))
endif
ifeq ($(detected_OS),Darwin)
GOBIN_SHARED_LIB_EXT := dylib
TEST_REPORTER_URL := https://codeclimate.com/downloads/test-reporter/test-reporter-latest-darwin-amd64
else ifeq ($(detected_OS),Windows)
# on Windows need `--export-all-symbols` flag else expected symbols will not be found in libgowaku.dll
GOBIN_SHARED_LIB_CGO_LDFLAGS := CGO_LDFLAGS="-Wl,--export-all-symbols"
GOBIN_SHARED_LIB_EXT := dll
else
TEST_REPORTER_URL := https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
GOBIN_SHARED_LIB_EXT := so
GOBIN_SHARED_LIB_CGO_LDFLAGS := CGO_LDFLAGS="-Wl,-soname,libgowaku.so.0"
endif
GIT_COMMIT = $(shell git rev-parse --short HEAD)
VERSION = $(shell cat ./VERSION)
UID := $(shell id -u)
GID := $(shell id -g)
BUILD_FLAGS ?= $(shell echo "-ldflags='\
-X github.com/waku-org/go-waku/waku/v2/node.GitCommit=$(GIT_COMMIT) \
-X github.com/waku-org/go-waku/waku/v2/node.Version=$(VERSION)'")
ANDROID_TARGET ?= 23
# control rln code compilation
ifeq ($(NO_RLN), true)
BUILD_TAGS := gowaku_no_rln
endif
all: build
deps: lint-install
build-with-race:
${GOCMD} build -race -tags="${BUILD_TAGS}" $(BUILD_FLAGS) -o build/waku ./cmd/waku
build:
${GOCMD} build -tags="${BUILD_TAGS}" $(BUILD_FLAGS) -o build/waku ./cmd/waku
chat2:
pushd ./examples/chat2 && \
${GOCMD} build -o ../../build/chat2 . && \
popd
vendor:
${GOCMD} mod tidy
lint-install:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
bash -s -- -b $(shell ${GOCMD} env GOPATH)/bin v1.59.1
lint:
@echo "lint"
@golangci-lint run ./...
lint-full:
@echo "lint"
@golangci-lint run ./... --config=./.golangci.full.yaml
test-with-race:
${GOCMD} test -race -timeout 300s ./waku/... ./cmd/waku/server/...
test:
${GOCMD} test -timeout 300s ./waku/... ./cmd/waku/server/... -coverprofile=${GO_TEST_OUTFILE}.tmp -coverpkg ./...
cat ${GO_TEST_OUTFILE}.tmp | grep -v ".pb.go" > ${GO_TEST_OUTFILE}
${GOCMD} tool cover -html=${GO_TEST_OUTFILE} -o ${GO_HTML_COV}
COVERAGE_FILE := ./coverage/cc-test-reporter
$(COVERAGE_FILE):
curl -sfL $(TEST_REPORTER_URL) --output ./coverage/cc-test-reporter #TODO: Support windows
chmod +x ./coverage/cc-test-reporter
_before-cc: $(COVERAGE_FILE)
CC_TEST_REPORTER_ID=${CC_TEST_REPORTER_ID} ./coverage/cc-test-reporter before-build
_after-cc:
GIT_COMMIT=$(git log | grep -m1 -oE '[^ ]+$') CC_TEST_REPORTER_ID=${CC_TEST_REPORTER_ID} ./coverage/cc-test-reporter after-build --prefix ${CC_PREFIX}
test-ci: _before-cc test _after-cc
generate:
${GOCMD} generate ./...
coverage:
${GOCMD} test -count 1 -coverprofile=coverage.out ./...
${GOCMD} tool cover -html=coverage.out -o=coverage.html
# build a docker image for the fleet
docker-image: DOCKER_IMAGE_TAG ?= latest
docker-image: DOCKER_IMAGE_NAME ?= wakuorg/go-waku:$(DOCKER_IMAGE_TAG)
docker-image:
docker build --tag $(DOCKER_IMAGE_NAME) \
--build-arg="GIT_COMMIT=$(shell git rev-parse HEAD)" .
build-example-basic-relay:
cd examples/basic-relay && $(MAKE)
build-example-basic-light-client:
cd examples/basic-light-client && $(MAKE)
build-example-chat-2:
cd examples/chat2 && $(MAKE)
build-example-filter2:
cd examples/filter2 && $(MAKE)
build-example-c-bindings:
cd examples/c-bindings && $(MAKE)
build-example-noise:
cd examples/noise && $(MAKE)
build-example-rln:
cd examples/rln && $(MAKE)
build-example: build-example-basic-relay build-example-basic-light-client build-example-chat-2 build-example-filter2 build-example-c-bindings build-example-noise build-example-rln
static-library:
@echo "Building static library..."
${GOCMD} build \
-buildmode=c-archive \
-tags="${BUILD_TAGS} gowaku_no_rln" \
-o ./build/lib/libgowaku.a \
./library/c/
@echo "Static library built:"
ifeq ($(detected_OS),Darwin)
sed -i '' -e "s/#include <cgo_utils.h>//gi" ./build/lib/libgowaku.h
else
sed -i "s/#include <cgo_utils.h>//gi" ./build/lib/libgowaku.h
endif
@ls -la ./build/lib/libgowaku.*
dynamic-library:
@echo "Building shared library..."
rm -f ./build/lib/libgowaku.$(GOBIN_SHARED_LIB_EXT)*
$(GOBIN_SHARED_LIB_CFLAGS) $(GOBIN_SHARED_LIB_CGO_LDFLAGS) ${GOCMD} build \
-buildmode=c-shared \
-tags="${BUILD_TAGS} gowaku_no_rln" \
-o ./build/lib/libgowaku.$(GOBIN_SHARED_LIB_EXT) \
./library/c/
ifeq ($(detected_OS),Darwin)
sed -i '' -e "s/#include <cgo_utils.h>//gi" ./build/lib/libgowaku.h
else
sed -i "s/#include <cgo_utils.h>//gi" ./build/lib/libgowaku.h
endif
ifeq ($(detected_OS),Linux)
cd ./build/lib && \
mv ./libgowaku.$(GOBIN_SHARED_LIB_EXT) ./libgowaku.$(GOBIN_SHARED_LIB_EXT).0 && \
ln -s ./libgowaku.$(GOBIN_SHARED_LIB_EXT).0 ./libgowaku.$(GOBIN_SHARED_LIB_EXT)
endif
@echo "Shared library built:"
@ls -la ./build/lib/libgowaku.*
mobile-android:
@echo "Android target: ${ANDROID_TARGET} (override with ANDROID_TARGET var)"
gomobile init && \
${GOCMD} get -d golang.org/x/mobile/cmd/gomobile && \
CGO=1 gomobile bind -v -target=android -androidapi=${ANDROID_TARGET} -ldflags="-s -w" -tags="${BUILD_TAGS} gowaku_no_rln" $(BUILD_FLAGS) -o ./build/lib/gowaku.aar ./library/mobile
@echo "Android library built:"
@ls -la ./build/lib/*.aar ./build/lib/*.jar
mobile-ios:
gomobile init && \
${GOCMD} get -d golang.org/x/mobile/cmd/gomobile && \
gomobile bind -target=ios -ldflags="-s -w" -tags="nowatchdog ${BUILD_TAGS} gowaku_no_rln" $(BUILD_FLAGS) -o ./build/lib/Gowaku.xcframework ./library/mobile
@echo "IOS library built:"
@ls -la ./build/lib/*.xcframework
install-xtools:
${GOCMD} install golang.org/x/tools/[email protected]
install-bindata:
${GOCMD} install github.com/kevinburke/go-bindata/[email protected]
install-gomobile: install-xtools
${GOCMD} install golang.org/x/mobile/cmd/[email protected]
${GOCMD} install golang.org/x/mobile/cmd/[email protected]
build-linux-pkg:
docker build --build-arg UID=${UID} --build-arg GID=${GID} -f ./scripts/linux/Dockerfile -t wakuorg/gowaku-linux-pkgs:latest .
./scripts/linux/docker-run.sh
ls -la ./build/*.rpm ./build/*.deb
TEST_MNEMONIC="swim relax risk shy chimney please usual search industry board music segment"
start-ganache:
docker run -p 8545:8545 --name ganache-cli --rm -d trufflesuite/ganache-cli:latest -m ${TEST_MNEMONIC}
stop-ganache:
docker stop ganache-cli
test-onchain: BUILD_TAGS += include_onchain_tests
test-onchain:
${GOCMD} test -v -count 1 -tags="${BUILD_TAGS}" github.com/waku-org/go-waku/waku/v2/protocol/rln
test-onchain-with-race:
${GOCMD} test -race -v -count 1 -tags="${BUILD_TAGS}" github.com/waku-org/go-waku/waku/v2/protocol/rln
test-postgres: PG_BUILD_TAGS = ${BUILD_TAGS} include_postgres_tests
test-postgres:
${GOCMD} test -p 1 -v -count 1 -tags="${PG_BUILD_TAGS}" github.com/waku-org/go-waku/waku/persistence/...
test-postgres-with-race:
${GOCMD} test -race -p 1 -v -count 1 -tags="${PG_BUILD_TAGS}" github.com/waku-org/go-waku/waku/persistence/...
test-filter:
${GOCMD} test -v github.com/waku-org/go-waku/waku/v2/protocol/filter -run TestFilterSuite -count=1
test-filter-api:
${GOCMD} test -v github.com/waku-org/go-waku/waku/v2/api -run TestFilterApiSuite
TEST_STOREV3_NODE ?=
test-storev3:
TEST_STOREV3_NODE=${TEST_STOREV3_NODE} ${GOCMD} test -p 1 -v -count 1 -tags="${BUILD_TAGS} include_storev3_tests" github.com/waku-org/go-waku/waku/v2/protocol/store/...