Repository navigation
Expand file tree
/
Copy pathconanfile.py
More file actions
402 lines (371 loc) · 18 KB
/
Copy pathconanfile.py
File metadata and controls
402 lines (371 loc) · 18 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
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
required_conan_version = ">=2.0"
from conan.tools.microsoft import is_msvc, msvc_runtime_flag
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools import files
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.gnu import PkgConfigDeps
from conan.errors import ConanInvalidConfiguration
from conan.errors import ConanException
import os
import hashlib
import json
import shutil
from pathlib import Path
class KnowhereConan(ConanFile):
name = "knowhere"
description = "Knowhere is written in C++. It is an independent project that act as Milvus's internal core"
topics = ("vector", "simd", "ann")
url = "https://github.com/milvus-io/knowhere"
homepage = "https://github.com/milvus-io/knowhere"
license = "Apache-2.0"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_cuvs": [True, False],
"with_asan": [True, False],
"with_diskann": [True, False],
"with_svs": [True, False],
"with_cardinal": [True, False],
"with_gpu": [True, False],
"cardinal_version_force_checkout": [True, False],
"with_profiler": [True, False],
"with_ut": [True, False],
"with_c_api": [True, False],
"with_jni": [True, False],
"with_c_api_tests": [True, False],
"with_benchmark": [True, False],
"with_coverage": [True, False],
"with_faiss_tests": [True, False],
"with_light": [True, False],
"with_compile_prune": [True, False],
}
default_options = {
"shared": True,
"fPIC": False,
"with_cuvs": False,
"with_asan": False,
"with_diskann": False,
"with_svs": False,
"with_cardinal": False,
"with_gpu": False,
"metis/*:with_64bit_types": True,
"cardinal_version_force_checkout": False,
"with_profiler": False,
"with_ut": False,
"with_c_api": False,
"with_jni": False,
"with_c_api_tests": False,
"glog/*:shared": True,
"glog/*:with_gflags": True,
"gtest/*:build_gmock": True,
"prometheus-cpp/*:with_pull": False,
"with_benchmark": False,
"with_coverage": False,
"boost/*:without_locale": False,
"boost/*:without_test": True,
"boost/*:without_stacktrace": True,
"openssl/*:shared": True,
"openssl/*:no_apps": True,
"gflags/*:shared": True,
"fmt/*:header_only": False,
"openblas/*:dynamic_arch": True,
"with_faiss_tests": False,
"opentelemetry-cpp/*:with_stl": True,
"libcurl/*:with_ssl": False,
"with_light": False,
"with_compile_prune": True,
"folly/*:shared": True,
}
exports_sources = (
"src/*",
"thirdparty/*",
"tests/ut/*",
"tests/c_api/*",
"java/src/*",
"java/scripts/*",
"java/tests/*",
"java/CMakeLists.txt",
"java/pom.xml",
"java/README.md",
"cmake/*",
"scripts/install_cuda.sh",
"include/*",
"CMakeLists.txt",
"LICENSE",
"*.cmake",
"conanfile.py",
)
@property
def _minimum_cpp_standard(self):
return 20
@property
def _minimum_compilers_version(self):
return {
"gcc": "10",
"Visual Studio": "17",
"clang": "10",
"apple-clang": "13",
}
@property
def _openblas_dynamic_arches(self):
# Keep OpenBLAS portable across supported CPU families without pinning a
# concrete TARGET such as SANDYBRIDGE.
return ["x86", "x86_64", "armv8", "ppc64", "ppc64le"]
def config_options(self):
if self.settings.os == "Windows":
self.options.rm_safe("fPIC")
if self.options.with_light:
self.options["boost"].without_locale = True
if self.settings.os == "Macos":
self.options["libcurl"].with_ssl = "openssl"
@property
def _with_c_api(self):
# The JNI library is built on the C ABI; CMake applies the same implication.
return bool(self.options.with_c_api) or bool(self.options.with_jni)
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
if self.settings.os == "Linux" and str(self.settings.arch) in self._openblas_dynamic_arches:
self.options["openblas"].dynamic_arch = True
def requirements(self):
if self.options.with_cardinal:
self.requires("metis/5.2.1#85cfe7ee0dfc0cba7c0334e92efcbbc6")
self.requires("abseil/20250127.0#481edcc75deb0efb16500f511f0f0a1c")
self.requires("boost/1.83.0#4e8a94ac1b88312af95eded83cd81ca8")
self.requires("gflags/2.2.2#7671803f1dc19354cc90bd32874dcfda")
self.requires("glog/0.7.1#a306e61d7b8311db8cb148ad62c48030")
self.requires("nlohmann_json/3.11.3#ffb9e9236619f1c883e36662f944345d", force=True)
self.requires("openssl/3.3.2#9f9f130d58e7c13e76bb8a559f0a6a8b", force=True, override=True)
self.requires("prometheus-cpp/1.2.4#0918d66c13f97acb7809759f9de49b3f")
self.requires("zlib/1.3.1#8045430172a5f8d56ba001b14561b4ea")
self.requires("double-conversion/3.3.0#640e35791a4bac95b0545e2f54b7aceb")
self.requires("xz_utils/5.4.5#fc4e36861e0a47ecd4a40a00e6d29ac8")
self.requires("protobuf/5.27.0@milvus/dev#42f031a96d21c230a6e05bcac4bdd633", force=True, override=True)
self.requires("lz4/1.10.0#982d9b673900f665a1da109e09c17cab", force=True, override=True)
if self.settings.os == "Linux":
self.requires("liburing/2.8", force=True, override=True)
self.requires("fmt/12.1.0", force=True, override=True)
self.requires("libevent/2.1.12#95065aaefcd58d3956d6dfbfc5631d97")
self.requires("grpc/1.67.1@milvus/dev#efeaa484b59bffaa579004d5e82ec4fd")
self.requires("folly/2026.04.20.00@milvus/dev#06852bea5b6449f0c4eb0df002b5779c")
self.requires("fast_float/8.0.0@milvus/dev#c7802833c74c5a86ffed70e4af1a795e")
self.requires("libcurl/8.10.1#a3113369c86086b0e84231844e7ed0a9", force=True, override=True)
self.requires("simde/0.8.2#5e1edfd5cba92f25d79bf6ef4616b972")
self.requires("xxhash/0.8.3#caa6d0af1b951c247922e38fbcebdbe6")
if self.settings.os == "Linux":
self.requires("openblas/0.3.30#aca4131c143d4c109923372e052c643c")
# milvus-common is built from source (cmake/libs/libmilvus-common.cmake)
# and its CMake requires opentelemetry-cpp unconditionally, so it must
# stay in the graph even for light builds.
self.requires("opentelemetry-cpp/1.23.0@milvus/dev#11bc565ec6e82910ae8f7471da756720")
if self.settings.os != "Macos":
self.requires("libunwind/1.8.1#748a981ace010b80163a08867b732e71")
if self.options.with_ut:
self.requires("catch2/3.7.1")
if self.options.with_benchmark:
self.requires("gtest/1.15.0")
self.requires("hdf5/1.14.5")
if self.options.with_faiss_tests:
self.requires("gtest/1.15.0")
@property
def _required_boost_components(self):
return ["program_options"]
def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._minimum_cpp_standard)
min_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if not min_version:
self.output.warn(
"{} recipe lacks information about the {} compiler support.".format(
self.name, self.settings.compiler
)
)
else:
if Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration(
"{} requires C++{} support. The current compiler {} {} does not support it.".format(
self.name,
self._minimum_cpp_standard,
self.settings.compiler,
self.settings.compiler.version,
)
)
def layout(self):
# build_folder="" places the cmake build dir directly at
# <output_folder>/<build_type> instead of cmake_layout's default
# <output_folder>/build/<build_type>. The Makefile always passes
# -of <BUILD_DIR>, so final paths are $(BUILD_DIR)/Release/\u2026
# which matches the historical build/Release/ layout exactly.
cmake_layout(self, build_folder="")
def generate(self):
if self._with_c_api:
self._collect_host_licenses()
tc = CMakeToolchain(self)
tc.variables["CMAKE_POSITION_INDEPENDENT_CODE"] = self.options.get_safe(
"fPIC", True
)
# Relocatable shared lib on Macos
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
# Honor BUILD_SHARED_LIBS from conan_toolchain (see https://github.com/conan-io/conan/issues/11840)
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
cppstd = self.settings.compiler.get_safe("cppstd")
if cppstd:
if cppstd.startswith("gnu"):
cxx_std_value = "gnu++{}".format(cppstd[3:])
else:
cxx_std_value = "c++{}".format(cppstd)
else:
cxx_std_value = "c++{}".format(self._minimum_cpp_standard)
tc.variables["CXX_STD"] = cxx_std_value
if is_msvc(self):
tc.variables["MSVC_LANGUAGE_VERSION"] = cxx_std_value
tc.variables["MSVC_ENABLE_ALL_WARNINGS"] = False
tc.variables["MSVC_USE_STATIC_RUNTIME"] = "MT" in msvc_runtime_flag(self)
tc.variables["WITH_ASAN"] = self.options.with_asan
tc.variables["WITH_DISKANN"] = self.options.with_diskann
tc.variables["WITH_SVS"] = self.options.with_svs
tc.cache_variables["WITH_CARDINAL"] = bool(self.options.with_cardinal)
tc.cache_variables["WITH_GPU"] = bool(self.options.with_gpu)
tc.variables["CARDINAL_VERSION_FORCE_CHECKOUT"] = self.options.cardinal_version_force_checkout
tc.cache_variables["WITH_CUVS"] = bool(self.options.with_cuvs)
tc.variables["WITH_PROFILER"] = self.options.with_profiler
tc.variables["WITH_UT"] = self.options.with_ut
tc.variables["WITH_C_API"] = self._with_c_api
tc.variables["WITH_JNI"] = self.options.with_jni
tc.variables["WITH_C_API_TESTS"] = self.options.with_c_api_tests
tc.variables["WITH_BENCHMARK"] = self.options.with_benchmark
tc.variables["WITH_COVERAGE"] = self.options.with_coverage
tc.variables["WITH_FAISS_TESTS"] = self.options.with_faiss_tests
tc.variables["WITH_LIGHT"] = self.options.with_light
tc.variables["WITH_COMPILE_PRUNE"] = self.options.with_compile_prune
# CMake 4.x removed compatibility with cmake_minimum_required < 3.5
tc.cache_variables["CMAKE_POLICY_VERSION_MINIMUM"] = "3.5"
# macOS: Apple Clang lacks OpenMP; point CMake to Homebrew's libomp
if self.settings.os == "Macos":
import subprocess
result = subprocess.run(
["brew", "--prefix", "libomp"],
capture_output=True, text=True
)
if result.returncode == 0:
libomp_prefix = result.stdout.strip()
elif os.path.isdir("/opt/homebrew/opt/libomp"):
libomp_prefix = "/opt/homebrew/opt/libomp"
else:
libomp_prefix = "/usr/local/opt/libomp"
omp_inc = f"-I{libomp_prefix}/include"
tc.variables["OpenMP_C_FLAGS"] = f"-Xpreprocessor -fopenmp {omp_inc}"
tc.variables["OpenMP_CXX_FLAGS"] = f"-Xpreprocessor -fopenmp {omp_inc}"
tc.variables["OpenMP_C_LIB_NAMES"] = "omp"
tc.variables["OpenMP_CXX_LIB_NAMES"] = "omp"
tc.variables["OpenMP_omp_LIBRARY"] = f"{libomp_prefix}/lib/libomp.dylib"
tc.variables["CMAKE_C_FLAGS"] = omp_inc
tc.variables["CMAKE_CXX_FLAGS"] = omp_inc
# Configure ccache
tc.variables["CMAKE_CXX_COMPILER_LAUNCHER"] = "ccache"
tc.variables["CMAKE_C_COMPILER_LAUNCHER"] = "ccache"
tc.generate()
deps = CMakeDeps(self)
deps.generate()
pc = PkgConfigDeps(self)
pc.generate()
def _collect_host_licenses(self):
# DT_NEEDED cannot describe static or header-only dependencies. Preserve
# every host package's license documents beside the binding build output.
destination = Path(self.build_folder) / "licenses" / "conan"
if destination.exists():
shutil.rmtree(destination)
destination.mkdir(parents=True)
inventory = []
missing = []
# Follow the original compile/runtime edges of each package, including
# headers already embedded in a cached static dependency. The root's
# .host view omits those, while indiscriminately including skipped nodes
# would also report unused dependencies.
pending = list(self.dependencies.host.values())
host_dependencies = {}
while pending:
dependency = pending.pop()
reference = dependency.ref.repr_notime()
if reference in host_dependencies:
continue
host_dependencies[reference] = dependency
for requirement, child in dependency.dependencies.filter(
{"build": False, "test": False, "direct": True}).items():
if requirement.headers or requirement.libs or requirement.run:
pending.append(child)
for reference, dependency in sorted(host_dependencies.items()):
directory = str(dependency.ref.name) + "-" + hashlib.sha256(reference.encode("utf-8")).hexdigest()[:16]
package_folder = dependency.package_folder
if not package_folder and dependency.pref:
# Skipped packages can still exist locally. Use the public,
# read-only cache API; never infer a package path from a name.
from conan.api.conan_api import ConanAPI
try:
package_folder = ConanAPI().cache.package_path(dependency.pref)
except ConanException:
package_folder = None
license_root = Path(package_folder) / "licenses" if package_folder else None
documents = sorted(path for path in license_root.rglob("*") if path.is_file()) if license_root else []
inventory.append({"reference": reference, "directory": directory,
"files": [path.relative_to(license_root).as_posix() for path in documents]})
if not documents:
missing.append(reference)
self.output.warning("License documents require follow-up for host dependency: " + reference)
for source in documents:
target = destination / directory / source.relative_to(license_root)
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(source, target)
(destination / "dependencies.json").write_text(
json.dumps(inventory, indent=2, sort_keys=True) + "\n", encoding="utf-8")
(destination / "missing-licenses.txt").write_text(
"".join(reference + "\n" for reference in missing), encoding="utf-8")
def build(self):
# files.apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
# milvus-common is embedded via FetchContent (cmake/libs/libmilvus-common.cmake),
# so its install rules (install(TARGETS milvus-common) + install(DIRECTORY include/))
# are honored here alongside the knowhere install rules. The published knowhere
# package therefore ships libmilvus-common.so and milvus-common's headers in
# addition to libknowhere.so, and package_info does not re-export a
# milvus-common::milvus-common component. This is an explicit, intended packaging
# change: consumers that already provide their own milvus-common (e.g. the Milvus
# server after the FetchContent migration) must not ALSO install this one, or two
# copies of libmilvus-common.so can end up on the runtime path and silently load
# the wrong one once the pins diverge. If this embedding becomes undesirable,
# guard milvus-common's install rules instead of relying on the subproject's.
cmake = CMake(self)
cmake.install()
files.rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
files.rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "knowhere")
self.cpp_info.set_property("cmake_target_name", "Knowhere::knowhere")
self.cpp_info.set_property("pkg_config_name", "libknowhere")
self.cpp_info.components["libknowhere"].libs = ["knowhere"]
self.cpp_info.components["libknowhere"].requires = [
"boost::program_options",
"glog::glog",
"prometheus-cpp::core",
"prometheus-cpp::push",
]
self.cpp_info.components["libknowhere"].set_property(
"cmake_target_name", "Knowhere::knowhere"
)
self.cpp_info.components["libknowhere"].set_property(
"pkg_config_name", "libknowhere"
)
if self._with_c_api:
self.cpp_info.components["libknowhere_c"].libs = ["knowhere_c"]
self.cpp_info.components["libknowhere_c"].requires = ["libknowhere"]
self.cpp_info.components["libknowhere_c"].set_property("cmake_target_name", "Knowhere::c_api")
if self.options.with_jni:
self.cpp_info.components["libknowhere_jni"].libs = ["knowhere_jni"]
self.cpp_info.components["libknowhere_jni"].requires = ["libknowhere_c"]
self.cpp_info.components["libknowhere_jni"].set_property("cmake_target_name", "Knowhere::jni")