Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
252 lines (212 loc) · 9.14 KB
/
Copy pathMakefile
File metadata and controls
252 lines (212 loc) · 9.14 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
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
# Copyright (C) 2019-2023 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.
PWD := $(shell pwd)
# BUILD_DIR is where conan + cmake put build outputs. Overridable from the
# command line, e.g. `make BUILD_DIR=$(pwd)/build_asan WITH_ASAN=True`.
# Binaries end up at $(BUILD_DIR)/$(BUILD_TYPE)/... (e.g. build/Release/...).
BUILD_DIR ?= $(PWD)/build
SHELL := /bin/bash
# Conan install-only flags (not valid for conan build)
CONAN_INSTALL_FLAGS := --update --build=missing
# ---------- User-facing build flags ----------
# Usage: make WITH_GPU=True WITH_UT=True WITH_ASAN=True WITH_DEBUG=True
WITH_GPU ?= False
WITH_CUVS ?=
WITH_UT ?=
WITH_BENCHMARK ?=
WITH_ASAN ?=
WITH_DISKANN ?= True
WITH_SVS ?=
WITH_CARDINAL ?=
CARDINAL_VERSION_FORCE_CHECKOUT ?=
WITH_C_API ?=
WITH_JNI ?=
WITH_C_API_TESTS ?=
WITH_DEBUG ?=
CONAN_PROFILE ?=
# CMake 4.x removed compatibility with cmake_minimum_required versions below
# 3.5. Export this so Conan-built third-party packages inherit it too.
export CMAKE_POLICY_VERSION_MINIMUM ?= 3.5
# Prevent build-flag variables from leaking into the environment of child
# processes (conan / cmake). Without this, GNU Make exports command-line
# variables such as WITH_ASAN to every sub-process, which causes the custom
# folly recipe to pick up $ENV{WITH_ASAN} and compile folly itself with
# -fsanitize=address — breaking the build on GCC.
unexport WITH_GPU WITH_CUVS WITH_UT WITH_BENCHMARK WITH_ASAN WITH_DISKANN WITH_CARDINAL CARDINAL_VERSION_FORCE_CHECKOUT WITH_DEBUG \
WITH_C_API WITH_JNI WITH_C_API_TESTS
# ---------- Derived settings ----------
ifdef WITH_DEBUG
BUILD_TYPE := Debug
else
BUILD_TYPE := Release
endif
# Auto-detect OS for compiler.libcxx; override with LIBCXX=<value>.
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LIBCXX ?= libc++
else
LIBCXX ?= libstdc++11
endif
# ---------- Compose conan flags from user flags ----------
# Settings/options flags shared by conan install and conan build
# -s:b compiler.cppstd=20: build-context tools (e.g. grpc_cpp_plugin) must also
# use C++20, because abseil's installed headers hardcode ABSL_OPTION_USE_STD_ORDERING=1
# which requires std::partial_ordering from <compare> (a C++20 feature).
CONAN_SETTINGS := -s compiler.libcxx=$(LIBCXX) -s build_type=$(BUILD_TYPE) -s compiler.cppstd=20 -s:b compiler.cppstd=20
# DiskANN and liburing require libaio (Linux-only).
ifneq ($(UNAME_S),Darwin)
ifneq ($(filter True true ON on 1,$(WITH_DISKANN)),)
CONAN_SETTINGS += -o \&:with_diskann=True
ifeq ($(filter True true ON on 1,$(WITH_GPU)),)
CONAN_INSTALL_FLAGS += --build=liburing
endif
else ifneq ($(filter False false OFF off 0,$(WITH_DISKANN)),)
CONAN_SETTINGS += -o \&:with_diskann=False
else
$(error WITH_DISKANN must be True/False, ON/OFF, or 1/0)
endif
endif
# Pass the GPU selection to Conan.
ifneq ($(WITH_GPU),)
ifneq ($(filter True true ON on 1,$(WITH_GPU)),)
CONAN_SETTINGS += -o \&:with_gpu=True
else ifneq ($(filter False false OFF off 0,$(WITH_GPU)),)
CONAN_SETTINGS += -o \&:with_gpu=False
else
$(error WITH_GPU must be True/False, ON/OFF, or 1/0)
endif
endif
ifneq ($(WITH_CUVS),)
ifneq ($(filter True true ON on 1,$(WITH_CUVS)),)
CONAN_SETTINGS += -o \&:with_cuvs=True
else ifneq ($(filter False false OFF off 0,$(WITH_CUVS)),)
CONAN_SETTINGS += -o \&:with_cuvs=False
else
$(error WITH_CUVS must be True/False, ON/OFF, or 1/0)
endif
endif
ifdef WITH_UT
CONAN_SETTINGS += -o \&:with_ut=True
endif
ifdef WITH_BENCHMARK
CONAN_SETTINGS += -o \&:with_benchmark=True
endif
ifdef WITH_ASAN
CONAN_SETTINGS += -o \&:with_asan=True
endif
ifneq ($(WITH_SVS),)
ifneq ($(filter True true ON on 1,$(WITH_SVS)),)
CONAN_SETTINGS += -o \&:with_svs=True
else ifneq ($(filter False false OFF off 0,$(WITH_SVS)),)
CONAN_SETTINGS += -o \&:with_svs=False
else
$(error WITH_SVS must be True/False, ON/OFF, or 1/0)
endif
endif
ifneq ($(WITH_CARDINAL),)
ifneq ($(filter True true ON on 1,$(WITH_CARDINAL)),)
CONAN_SETTINGS += -o \&:with_cardinal=True
else ifneq ($(filter False false OFF off 0,$(WITH_CARDINAL)),)
CONAN_SETTINGS += -o \&:with_cardinal=False
else
$(error WITH_CARDINAL must be True/False, ON/OFF, or 1/0)
endif
endif
# C ABI and Java JNI bindings (WITH_JNI implies WITH_C_API). Tests need a C compiler only.
ifdef WITH_C_API
CONAN_SETTINGS += -o \&:with_c_api=True
endif
ifdef WITH_JNI
CONAN_SETTINGS += -o \&:with_jni=True
endif
ifdef WITH_C_API_TESTS
CONAN_SETTINGS += -o \&:with_c_api_tests=True
endif
ifneq ($(CARDINAL_VERSION_FORCE_CHECKOUT),)
ifneq ($(filter True true ON on 1,$(CARDINAL_VERSION_FORCE_CHECKOUT)),)
CONAN_SETTINGS += -o \&:cardinal_version_force_checkout=True
else ifneq ($(filter False false OFF off 0,$(CARDINAL_VERSION_FORCE_CHECKOUT)),)
CONAN_SETTINGS += -o \&:cardinal_version_force_checkout=False
else
$(error CARDINAL_VERSION_FORCE_CHECKOUT must be True/False, ON/OFF, or 1/0)
endif
endif
ifdef CONAN_PROFILE
CONAN_SETTINGS += -pr:h $(CONAN_PROFILE) -pr:b $(CONAN_PROFILE)
endif
.PHONY: build test test-c-api \
lint format pre-commit \
wheel codecov \
clean help
all: build ## Default: CPU release build
# ---------- Build ----------
build: ## Build knowhere (use WITH_GPU=True, WITH_UT=True, WITH_BENCHMARK=True, WITH_ASAN=True, WITH_JNI=True)
@mkdir -p $(BUILD_DIR) && \
conan install . -of $(BUILD_DIR) $(CONAN_INSTALL_FLAGS) $(CONAN_SETTINGS) && \
conan build . -of $(BUILD_DIR) $(CONAN_SETTINGS)
# ---------- Test ----------
test: ## Run unit tests (requires prior build with WITH_UT=True)
@$(BUILD_DIR)/$(BUILD_TYPE)/tests/ut/knowhere_tests
test-c-api: ## Run C ABI tests (requires prior build with WITH_C_API_TESTS=True)
@ctest --test-dir $(BUILD_DIR)/$(BUILD_TYPE) -R knowhere_c_api --output-on-failure
# ---------- Code quality ----------
lint: ## Run clang-tidy (requires a prior build)
@$(PWD)/scripts/prepare_clang_tidy.sh
@find src -type f -name '*.cc' | xargs run-clang-tidy -quiet -p=$(BUILD_DIR)/$(BUILD_TYPE)
format: ## Run clang-format via pre-commit
@pre-commit run clang-format --all-files
pre-commit: ## Run all pre-commit hooks
@pre-commit run --all-files
# ---------- Python ----------
wheel: ## Build portable Python wheel (requires a prior build)
@cd $(PWD)/python && ./build_portable_wheel.sh
# ---------- Coverage ----------
codecov: ## Generate code coverage report (requires a coverage build)
@$(PWD)/scripts/run_codecov.sh
# ---------- Housekeeping ----------
clean: ## Remove build directory
@rm -rf $(BUILD_DIR)
# ---------- Help ----------
help: ## Show available targets
@echo "Knowhere build targets:"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*## ' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Build flags:"
@echo " WITH_GPU=True/False Enable GPU support (default: False)"
@echo " WITH_CUVS=True/False Explicit cuVS selection (also enabled by WITH_GPU=True without Cardinal)"
@echo " WITH_UT=True Enable unit tests"
@echo " WITH_BENCHMARK=True Enable benchmarks build"
@echo " WITH_ASAN=True Enable AddressSanitizer"
@echo " WITH_DISKANN=False Disable DiskANN (enabled by default on Linux)"
@echo " WITH_SVS=True/False Enable or disable SVS (Intel Scalable Vector Search, x86-64 only)"
@echo " WITH_CARDINAL=True Enable Cardinal build"
@echo " CARDINAL_VERSION_FORCE_CHECKOUT=True Force Cardinal checkout to configured version"
@echo " WITH_C_API=True Build the C ABI library (libknowhere_c)"
@echo " WITH_JNI=True Build the Java JNI library (implies WITH_C_API; needs a JDK 11+)"
@echo " WITH_C_API_TESTS=True Build the C ABI tests (run with make test-c-api)"
@echo " WITH_DEBUG=True Debug build (default: Release)"
@echo " CONAN_PROFILE=<p> Use one custom Conan profile for host and build"
@echo " LIBCXX=<lib> Override compiler.libcxx (auto-detected from OS)"
@echo ""
@echo "Examples:"
@echo " make # CPU release"
@echo " make WITH_GPU=True # GPU release"
@echo " make WITH_CARDINAL=True WITH_GPU=True # Cardinal GPU release"
@echo " make WITH_CARDINAL=True WITH_GPU=True WITH_CUVS=True # Cardinal GPU + cuVS release"
@echo " make WITH_UT=True WITH_ASAN=True # CPU UT + ASAN"
@echo " make WITH_GPU=True WITH_UT=True # GPU UT"
@echo " make WITH_DEBUG=True WITH_UT=True # CPU debug + UT"
@echo " make WITH_JNI=True WITH_C_API_TESTS=True # C ABI + JNI bindings with C tests"
@echo " make LIBCXX=libc++ # override compiler.libcxx"
@echo " make CONAN_PROFILE=/path/to/profile # CPU with custom profile"
@echo ""