Makefile 11.2 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)
43

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

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

51
generated-proto-go: export protoc:=${PWD}/cmake_build/thirdparty/protobuf/protobuf-build/protoc
52
generated-proto-go: build-cpp
53
	@mkdir -p ${GOPATH}/bin
54
	@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)
55 56 57 58 59
	@(env bash $(PWD)/scripts/proto_gen_go.sh)

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

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

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

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

83
verifiers: build-cpp getdeps cppcheck fmt static-check
84

85
# Build various components locally.
C
Cai Yudong 已提交
86 87
binlog:
	@echo "Building binlog ..."
88
	@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 已提交
89

90
BUILD_TAGS = $(shell git describe --tags --always --dirty="-dev")
J
jaime 已提交
91
BUILD_TIME = $(shell date -u)
92 93
GIT_COMMIT = $(shell git rev-parse --short HEAD)
GO_VERSION = $(shell go version)
94 95 96 97 98
ifeq ($(OS),Darwin)
ifeq ($(ARCH),arm64)
	APPLE_SILICON_FLAG = -tags dynamic
endif
endif
99

D
dragondriver 已提交
100 101 102 103 104 105 106
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
107
	@echo "Building Milvus ..."
108
	@echo "if build fails on Mac M1 machines, you probably need to rerun scripts/install_deps.sh and then run: \`export PKG_CONFIG_PATH=\"/opt/homebrew/opt/openssl@3/lib/pkgconfig\"\`"
109
	@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build \
110
		-ldflags="-X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \
111
		${APPLE_SILICON_FLAG}  -o $(INSTALL_PATH)/milvus $(PWD)/cmd/main.go 1>/dev/null
112

113 114
embd-milvus: build-cpp-embd print-build-info
	@echo "Building **Embedded** Milvus ..."
115
	@echo "if build fails on Mac M1 machines, rerun scripts/install_deps.sh and then run: \`export PKG_CONFIG_PATH=\"/opt/homebrew/opt/openssl@3/lib/pkgconfig\"\`"
116
	@mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build \
117
		-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)'" \
118
		${APPLE_SILICON_FLAG} -buildmode=c-shared -o $(INSTALL_PATH)/embd-milvus.so $(PWD)/pkg/embedded/embedded.go 1>/dev/null
119

120
build-go: milvus
N
neza2017 已提交
121

J
jaime 已提交
122
build-cpp: pre-proc
123
	@echo "Building Milvus cpp library ..."
124
	@(env bash $(PWD)/scripts/core_build.sh -t ${mode} -f "$(CUSTOM_THIRDPARTY_PATH)")
125 126 127 128 129 130
	@(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)")
131 132
	@(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)")
133

J
jaime 已提交
134
build-cpp-with-unittest: pre-proc
135
	@echo "Building Milvus cpp library with unittest ..."
136
	@(env bash $(PWD)/scripts/core_build.sh -t ${mode} -u -f "$(CUSTOM_THIRDPARTY_PATH)")
J
jaime 已提交
137 138
	@(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)")
139

140 141 142 143 144 145 146
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)")


147
# Run the tests.
148
unittest: test-cpp test-go
149
	@echo "if test fails on Mac M1 machines, you probably need to rerun scripts/install_deps.sh and then run: \`export PKG_CONFIG_PATH=\"/opt/homebrew/opt/openssl@3/lib/pkgconfig\"\`"
150

151 152
test-indexnode:
	@echo "Running go unittests..."
153
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/indexnode -v -failfast
154

Z
zhenshan.cao 已提交
155 156
test-proxy:
	@echo "Running go unittests..."
157
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/proxy -v -failfast
Z
zhenshan.cao 已提交
158

159 160
test-datacoord:
	@echo "Running go unittests..."
161
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/datacoord -v -failfast
162

163 164
test-datanode:
	@echo "Running go unittests..."
165
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/datanode -v -failfast
Z
zhenshan.cao 已提交
166

167 168
test-querynode:
	@echo "Running go unittests..."
169
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/querynode -v -failfast
170

B
bigsheeper 已提交
171 172
test-querycoord:
	@echo "Running go unittests..."
173
	go test -race -coverpkg=./... -coverprofile=profile.out -covermode=atomic -timeout 5m github.com/milvus-io/milvus/internal/querycoord	-v -failfast
B
bigsheeper 已提交
174 175


176
test-go: build-cpp-with-unittest
177
	@echo "Running go unittests..."
178
	@echo "if test fails on Mac M1 machines, you probably need to rerun scripts/install_deps.sh and then run: \`export PKG_CONFIG_PATH=\"/opt/homebrew/opt/openssl@3/lib/pkgconfig\"\`"
179
	@(env bash $(PWD)/scripts/run_go_unittest.sh)
180 181

test-cpp: build-cpp-with-unittest
C
cai.zhang 已提交
182
	@echo "Running cpp unittests..."
183
	@echo "if test fails on Mac M1 machines, you probably need to rerun scripts/install_deps.sh and then run: \`export PKG_CONFIG_PATH=\"/opt/homebrew/opt/openssl@3/lib/pkgconfig\"\`"
184
	@(env bash $(PWD)/scripts/run_cpp_unittest.sh)
185

186
# Run code coverage.
G
groot 已提交
187
codecov: codecov-go codecov-cpp
188
	@echo "if test fails on Mac M1 machines, you probably need to rerun scripts/install_deps.sh and then run: \`export PKG_CONFIG_PATH=\"/opt/homebrew/opt/openssl@3/lib/pkgconfig\"\`"
G
groot 已提交
189

G
groot 已提交
190
# Run codecov-go
191
codecov-go: build-cpp-with-coverage
G
groot 已提交
192
	@echo "Running go coverage..."
193
	@echo "if test fails on Mac M1 machines, you probably need to rerun scripts/install_deps.sh and then run: \`export PKG_CONFIG_PATH=\"/opt/homebrew/opt/openssl@3/lib/pkgconfig\"\`"
194 195
	@(env bash $(PWD)/scripts/run_go_codecov.sh)

G
groot 已提交
196
# Run codecov-cpp
197
codecov-cpp: build-cpp-with-coverage
G
groot 已提交
198
	@echo "Running cpp coverage..."
199
	@echo "if test fails on Mac M1 machines, you probably need to rerun scripts/install_deps.sh and then run: \`export PKG_CONFIG_PATH=\"/opt/homebrew/opt/openssl@3/lib/pkgconfig\"\`"
200 201
	@(env bash $(PWD)/scripts/run_cpp_codecov.sh)

202 203 204 205
# Package docker image locally.
# TODO: fix error occur at starting up
docker: install
	./build/build_image.sh
206

207
# Build each component and install binary to $GOPATH/bin.
208 209
install: all
	@echo "Installing binary to './bin'"
210
	@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/bin/milvus $(GOPATH)/bin/milvus
211
	@mkdir -p $(LIBRARY_PATH) && cp -r -P $(PWD)/internal/core/output/lib/* $(LIBRARY_PATH)
212 213 214 215 216 217
	@echo "Installation successful."

clean:
	@echo "Cleaning up all the generated files"
	@find . -name '*.test' | xargs rm -fv
	@find . -name '*~' | xargs rm -fv
218 219
	@rm -rf bin/
	@rm -rf lib/
X
Xiaofan 已提交
220
	@rm -rf $(GOPATH)/bin/milvus
221 222 223
	@rm -rf cmake_build
	@rm -rf cwrapper_rocksdb_build
	@rm -rf cwrapper_build
J
jaime 已提交
224 225 226
	@rm -rf internal/storage/cwrapper/output
	@rm -rf internal/core/output
	@rm -rf internal/kv/rocksdb/cwrapper/output
227

D
dragondriver 已提交
228
milvus-tools: print-build-info
229 230 231 232
	@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 已提交
233 234 235

rpm-setup: 
	@echo "Setuping rpm env ...;"
236
	@build/rpm/setup-env.sh
S
shaoyue 已提交
237 238 239 240 241 242 243 244 245 246 247 248 249 250

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/
251
	@QA_RPATHS="$$[ 0x001|0x0002|0x0020 ]" rpmbuild -ba ./build/rpm/milvus.spec