Makefile 10.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
# Copyright (C) 2019-2020 Zilliz. All rights reserved.
#
# Licensed 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.

12 13 14 15
GO		  ?= go
PWD 	  := $(shell pwd)
GOPATH 	  := $(shell $(GO) env GOPATH)
OBJPREFIX := "github.com/milvus-io/milvus/cmd/milvus"
16 17 18

INSTALL_PATH := $(PWD)/bin
LIBRARY_PATH := $(PWD)/lib
J
jaime 已提交
19 20 21
OS := $(shell uname -s)
ARCH := $(shell arch)
mode = Release
22

C
cai.zhang 已提交
23
all: build-cpp build-go
24

J
jaime 已提交
25 26 27 28
pre-proc:
	@echo "Running pre-processing"
ifeq ($(OS),Darwin) # MacOS X
	@echo "MacOS system identified. Switching to customized gorocksdb fork..."
29
	@go mod edit -replace=github.com/tecbot/gorocksdb=github.com/soothing-rain/gorocksdb@v0.0.1
J
jaime 已提交
30
endif
J
Ji Bin 已提交
31 32 33 34
ifeq ($(MSYSTEM), MINGW64) # MSYS
	@echo "MSYS. Switching to customized gorocksdb fork..."
	@go mod edit -replace=github.com/tecbot/gorocksdb=github.com/soothing-rain/gorocksdb@v0.0.1
endif
35

36 37 38
get-build-deps:
	@(env bash $(PWD)/scripts/install_deps.sh)

39
# attention: upgrade golangci-lint should also change Dockerfiles in build/docker/builder/cpu/<os>
40 41
getdeps:
	@mkdir -p ${GOPATH}/bin
42
	@which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.43.0)
C
cai.zhang 已提交
43
	@which ruleguard 1>/dev/null || (echo "Installing ruleguard" && go get github.com/quasilyte/go-ruleguard/cmd/ruleguard@v0.2.1)
44

45 46 47 48
tools/bin/revive: tools/check/go.mod
	cd tools/check; \
	$(GO) build -o ../bin/revive github.com/mgechev/revive

49 50
cppcheck:
	@(env bash ${PWD}/scripts/core_build.sh -l)
51

52
generated-proto-go: export protoc:=${PWD}/cmake_build/thirdparty/protobuf/protobuf-build/protoc
53
generated-proto-go: build-cpp
54
	@mkdir -p ${GOPATH}/bin
55
	@which protoc-gen-go 1>/dev/null || (echo "Installing protoc-gen-go" && cd /tmp && go install github.com/golang/protobuf/protoc-gen-go@v1.3.2)
56 57 58 59 60
	@(env bash $(PWD)/scripts/proto_gen_go.sh)

check-proto-product: generated-proto-go
	@(env bash $(PWD)/scripts/check_proto_product.sh)

61
fmt:
62 63 64 65
ifdef GO_DIFF_FILES
	@echo "Running $@ check"
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh $(GO_DIFF_FILES)
else
66
	@echo "Running $@ check"
67 68
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh cmd/
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh internal/
G
godchen 已提交
69
	@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh tests/go/
70
endif
71

72
lint: tools/bin/revive
73 74 75
	@echo "Running $@ check"
	@tools/bin/revive -formatter friendly -config tools/check/revive.toml ./...

76
#TODO: Check code specifications by golangci-lint
X
XuanYang-cn 已提交
77
static-check:
78 79
	@echo "Running $@ check"
	@GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean
X
XuanYang-cn 已提交
80 81
	@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=30m --config ./.golangci.yml ./internal/...
	@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=30m --config ./.golangci.yml ./cmd/...
82
#	@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=30m --config ./.golangci.yml ./tests/go_client/...
83

C
cai.zhang 已提交
84
ruleguard:
85 86 87 88
ifdef GO_DIFF_FILES
	@echo "Running $@ check"
	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go $(GO_DIFF_FILES)
else
C
cai.zhang 已提交
89
	@echo "Running $@ check"
J
jaime 已提交
90 91 92 93 94
ifeq ($(OS),Darwin) # MacOS X
ifeq ($(ARCH),arm64)
	@${GOPATH}/bin/darwin_arm64/ruleguard -rules ruleguard.rules.go ./internal/...
	@${GOPATH}/bin/darwin_arm64/ruleguard -rules ruleguard.rules.go ./cmd/...
else
C
cai.zhang 已提交
95 96
	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./internal/...
	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./cmd/...
J
jaime 已提交
97 98 99 100 101 102
endif
else
	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./internal/...
	@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./cmd/...
endif
	#@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./tests/go/...
103
endif
C
cai.zhang 已提交
104

105
verifiers: build-cpp getdeps cppcheck fmt static-check ruleguard
106

107
# Build various components locally.
C
Cai Yudong 已提交
108 109
binlog:
	@echo "Building binlog ..."
110
	@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build -o $(INSTALL_PATH)/binlog $(PWD)/cmd/tools/binlog/main.go 1>/dev/null
Z
zhenshan.cao 已提交
111

112
BUILD_TAGS = $(shell git describe --tags --always --dirty="-dev")
J
jaime 已提交
113
BUILD_TIME = $(shell date -u)
114 115
GIT_COMMIT = $(shell git rev-parse --short HEAD)
GO_VERSION = $(shell go version)
116 117 118 119 120
ifeq ($(OS),Darwin)
ifeq ($(ARCH),arm64)
	APPLE_SILICON_FLAG = -tags dynamic
endif
endif
121

D
dragondriver 已提交
122 123 124 125 126 127 128
print-build-info:
	@echo "Build Tag: $(BUILD_TAGS)"
	@echo "Build Time: $(BUILD_TIME)"
	@echo "Git Commit: $(GIT_COMMIT)"
	@echo "Go Version: $(GO_VERSION)"

milvus: build-cpp print-build-info
129
	@echo "Building Milvus ..."
130
	@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build \
131
		-ldflags="-X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \
132
		${APPLE_SILICON_FLAG}  -o $(INSTALL_PATH)/milvus $(PWD)/cmd/main.go 1>/dev/null
133

134 135 136
embd-milvus: build-cpp-embd print-build-info
	@echo "Building **Embedded** Milvus ..."
	@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build \
137
		-ldflags="-r /tmp/milvus/lib/ -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \
138
		${APPLE_SILICON_FLAG} -buildmode=c-shared -o $(INSTALL_PATH)/embd-milvus.so $(PWD)/pkg/embedded/embedded.go 1>/dev/null
139

140
build-go: milvus
N
neza2017 已提交
141

J
jaime 已提交
142
build-cpp: pre-proc
143
	@echo "Building Milvus cpp library ..."
144
	@(env bash $(PWD)/scripts/core_build.sh -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)")
145 146 147 148 149 150
	@(env bash $(PWD)/scripts/cwrapper_build.sh -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)")
	@(env bash $(PWD)/scripts/cwrapper_rocksdb_build.sh -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)")

build-cpp-embd: pre-proc
	@echo "Building **Embedded** Milvus cpp library ..."
	@(env bash $(PWD)/scripts/core_build.sh -b -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)")
151 152
	@(env bash $(PWD)/scripts/cwrapper_build.sh -b -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)")
	@(env bash $(PWD)/scripts/cwrapper_rocksdb_build.sh -b -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)")
153

J
jaime 已提交
154
build-cpp-with-unittest: pre-proc
155
	@echo "Building Milvus cpp library with unittest ..."
156
	@(env bash $(PWD)/scripts/core_build.sh -t ${mode} -u -f "$(CUSTOM_THIRDPARTY_PATH)")
J
jaime 已提交
157 158
	@(env bash $(PWD)/scripts/cwrapper_build.sh -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)")
	@(env bash $(PWD)/scripts/cwrapper_rocksdb_build.sh -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)")
159

160 161 162 163 164 165 166
build-cpp-with-coverage: pre-proc
	@echo "Building Milvus cpp library with coverage and unittest ..."
	@(env bash $(PWD)/scripts/core_build.sh -t ${mode} -u -c -f "$(CUSTOM_THIRDPARTY_PATH)")
	@(env bash $(PWD)/scripts/cwrapper_build.sh -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)")
	@(env bash $(PWD)/scripts/cwrapper_rocksdb_build.sh -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)")


167
# Run the tests.
168
unittest: test-cpp test-go
169

170 171 172 173
test-indexnode:
	@echo "Running go unittests..."
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/indexnode -v

Z
zhenshan.cao 已提交
174 175 176 177
test-proxy:
	@echo "Running go unittests..."
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/proxy -v

178 179 180 181
test-datacoord:
	@echo "Running go unittests..."
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/datacoord -v

182 183 184
test-datanode:
	@echo "Running go unittests..."
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/datanode -v
Z
zhenshan.cao 已提交
185

186 187 188 189
test-querynode:
	@echo "Running go unittests..."
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/querynode -v

B
bigsheeper 已提交
190 191 192 193 194
test-querycoord:
	@echo "Running go unittests..."
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/querycoord	-v


195
test-go: build-cpp-with-unittest
196
	@echo "Running go unittests..."
197
	@(env bash $(PWD)/scripts/run_go_unittest.sh)
198 199

test-cpp: build-cpp-with-unittest
C
cai.zhang 已提交
200
	@echo "Running cpp unittests..."
201
	@(env bash $(PWD)/scripts/run_cpp_unittest.sh)
202

203
# Run code coverage.
G
groot 已提交
204
codecov: codecov-go codecov-cpp
G
groot 已提交
205

G
groot 已提交
206
# Run codecov-go
207
codecov-go: build-cpp-with-coverage
G
groot 已提交
208
	@echo "Running go coverage..."
209 210
	@(env bash $(PWD)/scripts/run_go_codecov.sh)

G
groot 已提交
211
# Run codecov-cpp
212
codecov-cpp: build-cpp-with-coverage
G
groot 已提交
213
	@echo "Running cpp coverage..."
214 215
	@(env bash $(PWD)/scripts/run_cpp_codecov.sh)

216 217 218 219
# Package docker image locally.
# TODO: fix error occur at starting up
docker: install
	./build/build_image.sh
220

221
# Build each component and install binary to $GOPATH/bin.
222 223
install: all
	@echo "Installing binary to './bin'"
224
	@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/bin/milvus $(GOPATH)/bin/milvus
225
	@mkdir -p $(LIBRARY_PATH) && cp -r -P $(PWD)/internal/core/output/lib/* $(LIBRARY_PATH)
226 227 228 229 230 231
	@echo "Installation successful."

clean:
	@echo "Cleaning up all the generated files"
	@find . -name '*.test' | xargs rm -fv
	@find . -name '*~' | xargs rm -fv
232 233
	@rm -rf bin/
	@rm -rf lib/
X
Xiaofan 已提交
234
	@rm -rf $(GOPATH)/bin/milvus
235 236 237
	@rm -rf cmake_build
	@rm -rf cwrapper_rocksdb_build
	@rm -rf cwrapper_build
238

D
dragondriver 已提交
239
milvus-tools: print-build-info
240 241 242 243
	@echo "Building tools ..."
	@mkdir -p $(INSTALL_PATH)/tools && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build \
		-ldflags="-X 'main.BuildTags=$(BUILD_TAGS)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.GitCommit=$(GIT_COMMIT)' -X 'main.GoVersion=$(GO_VERSION)'" \
		-o $(INSTALL_PATH)/tools $(PWD)/cmd/tools/* 1>/dev/null
S
shaoyue 已提交
244 245 246

rpm-setup: 
	@echo "Setuping rpm env ...;"
247
	@build/rpm/setup-env.sh
S
shaoyue 已提交
248 249 250 251 252 253 254 255 256 257 258 259 260 261

rpm: install
	@echo "Note: run 'make rpm-setup' to setup build env for rpm builder"
	@echo "Building rpm ...;"
	@yum -y install rpm-build rpmdevtools wget
	@rm -rf ~/rpmbuild/BUILD/*
	@rpmdev-setuptree
	@wget https://github.com/etcd-io/etcd/releases/download/v3.5.0/etcd-v3.5.0-linux-amd64.tar.gz && tar -xf etcd-v3.5.0-linux-amd64.tar.gz
	@cp etcd-v3.5.0-linux-amd64/etcd bin/etcd
	@wget https://dl.min.io/server/minio/release/linux-amd64/archive/minio.RELEASE.2021-02-14T04-01-33Z -O bin/minio
	@cp -r bin ~/rpmbuild/BUILD/
	@cp -r lib ~/rpmbuild/BUILD/
	@cp -r configs ~/rpmbuild/BUILD/
	@cp -r build/rpm/services ~/rpmbuild/BUILD/
262
	@QA_RPATHS="$$[ 0x001|0x0002|0x0020 ]" rpmbuild -ba ./build/rpm/milvus.spec