|
| 1 | +import os |
| 2 | + |
| 3 | +from conan import ConanFile |
| 4 | +from conan.tools.build import check_min_cppstd, cppstd_flag |
| 5 | +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout |
| 6 | +from conan.tools.files import copy, get, replace_in_file |
| 7 | +from conan.tools.gnu import PkgConfigDeps |
| 8 | +from conan.tools.microsoft import is_msvc, msvc_runtime_flag |
| 9 | + |
| 10 | + |
| 11 | +required_conan_version = ">=2.0" |
| 12 | + |
| 13 | + |
| 14 | +class MilvusCommonConan(ConanFile): |
| 15 | + name = "milvus-common" |
| 16 | + license = "Apache-2.0" |
| 17 | + url = "https://github.com/zilliztech/milvus-common" |
| 18 | + homepage = "https://github.com/zilliztech/milvus-common" |
| 19 | + description = "Common C++ libraries for Milvus" |
| 20 | + package_type = "shared-library" |
| 21 | + |
| 22 | + settings = "os", "arch", "compiler", "build_type" |
| 23 | + options = { |
| 24 | + "with_ut": [True, False], |
| 25 | + "with_asan": [True, False], |
| 26 | + } |
| 27 | + default_options = { |
| 28 | + "folly/*:shared": True, |
| 29 | + "fmt/*:header_only": False, |
| 30 | + "gflags/*:shared": True, |
| 31 | + "glog/*:shared": True, |
| 32 | + "glog/*:with_gflags": True, |
| 33 | + "gtest/*:build_gmock": True, |
| 34 | + "openblas/*:use_openmp": True, |
| 35 | + "opentelemetry-cpp/*:with_stl": True, |
| 36 | + "openssl/*:shared": True, |
| 37 | + "prometheus-cpp/*:with_pull": False, |
| 38 | + "with_ut": False, |
| 39 | + "with_asan": False, |
| 40 | + } |
| 41 | + |
| 42 | + @property |
| 43 | + def _minimum_cpp_standard(self): |
| 44 | + return 17 |
| 45 | + |
| 46 | + def validate(self): |
| 47 | + check_min_cppstd(self, self._minimum_cpp_standard) |
| 48 | + |
| 49 | + def requirements(self): |
| 50 | + if self.options.with_ut: |
| 51 | + self.requires("gtest/1.15.0", visible=False) |
| 52 | + self.requires("glog/0.7.1", transitive_headers=True, transitive_libs=True) |
| 53 | + self.requires("fmt/11.0.2", transitive_headers=True, transitive_libs=True) |
| 54 | + self.requires("prometheus-cpp/1.2.4", transitive_headers=True, transitive_libs=True) |
| 55 | + self.requires("gflags/2.2.2", transitive_headers=True, transitive_libs=True) |
| 56 | + self.requires("opentelemetry-cpp/1.23.0@milvus/dev", transitive_headers=True, transitive_libs=True) |
| 57 | + self.requires("folly/2024.08.12.00@milvus/dev", transitive_headers=True, transitive_libs=True) |
| 58 | + self.requires("protobuf/5.27.0@milvus/dev", override=True) |
| 59 | + self.requires("lz4/1.9.4", override=True) |
| 60 | + self.requires("openssl/3.3.2", override=True) |
| 61 | + self.requires("libcurl/8.10.1", override=True) |
| 62 | + self.requires("nlohmann_json/3.11.3", force=True) |
| 63 | + if self.settings.os != "Macos": |
| 64 | + self.requires("openblas/0.3.27", transitive_headers=True, transitive_libs=True) |
| 65 | + |
| 66 | + def layout(self): |
| 67 | + cmake_layout(self, src_folder="src") |
| 68 | + |
| 69 | + def source(self): |
| 70 | + get(self, **self.conan_data["sources"][self.version], strip_root=True) |
| 71 | + |
| 72 | + def generate(self): |
| 73 | + tc = CMakeToolchain(self) |
| 74 | + tc.generator = "Unix Makefiles" |
| 75 | + tc.variables["CMAKE_POSITION_INDEPENDENT_CODE"] = True |
| 76 | + tc.cache_variables["CMAKE_INSTALL_LIBDIR"] = "lib" |
| 77 | + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW" |
| 78 | + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW" |
| 79 | + tc.cache_variables["CMAKE_POLICY_VERSION_MINIMUM"] = "3.5" |
| 80 | + |
| 81 | + cxx_std_flag = cppstd_flag(self) |
| 82 | + cxx_std_value = cxx_std_flag.split("=")[1] if cxx_std_flag else f"c++{self._minimum_cpp_standard}" |
| 83 | + tc.variables["CXX_STD"] = cxx_std_value |
| 84 | + if is_msvc(self): |
| 85 | + tc.variables["MSVC_LANGUAGE_VERSION"] = cxx_std_value |
| 86 | + tc.variables["MSVC_ENABLE_ALL_WARNINGS"] = False |
| 87 | + tc.variables["MSVC_USE_STATIC_RUNTIME"] = "MT" in msvc_runtime_flag(self) |
| 88 | + |
| 89 | + tc.variables["WITH_COMMON_UT"] = self.options.with_ut |
| 90 | + tc.variables["WITH_ASAN"] = self.options.with_asan |
| 91 | + tc.generate() |
| 92 | + |
| 93 | + deps = CMakeDeps(self) |
| 94 | + deps.set_property("folly", "cmake_file_name", "folly") |
| 95 | + deps.set_property("gflags", "cmake_file_name", "gflags") |
| 96 | + deps.set_property("glog", "cmake_file_name", "glog") |
| 97 | + deps.set_property("fmt", "cmake_file_name", "fmt") |
| 98 | + deps.set_property("prometheus-cpp", "cmake_file_name", "prometheus-cpp") |
| 99 | + deps.set_property("nlohmann_json", "cmake_file_name", "nlohmann_json") |
| 100 | + deps.set_property("openblas", "cmake_file_name", "OpenBLAS") |
| 101 | + deps.generate() |
| 102 | + |
| 103 | + pc = PkgConfigDeps(self) |
| 104 | + pc.generate() |
| 105 | + |
| 106 | + def _patch_sources(self): |
| 107 | + cmakelists = os.path.join(self.source_folder, "CMakeLists.txt") |
| 108 | + replace_in_file(self, cmakelists, "find_package(prometheus-cpp REQUIRED)\n", "find_package(prometheus-cpp REQUIRED)\nfind_package(nlohmann_json REQUIRED CONFIG)\n") |
| 109 | + replace_in_file(self, cmakelists, "list(APPEND COMMON_LINKER_LIBS prometheus-cpp::core prometheus-cpp::push)\n", "list(APPEND COMMON_LINKER_LIBS prometheus-cpp::core prometheus-cpp::push)\nlist(APPEND COMMON_LINKER_LIBS nlohmann_json::nlohmann_json)\n") |
| 110 | + |
| 111 | + def build(self): |
| 112 | + self._patch_sources() |
| 113 | + cmake = CMake(self) |
| 114 | + cmake.generator = "Unix Makefiles" |
| 115 | + cmake.configure() |
| 116 | + cmake.build() |
| 117 | + |
| 118 | + def package(self): |
| 119 | + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) |
| 120 | + cmake = CMake(self) |
| 121 | + cmake.generator = "Unix Makefiles" |
| 122 | + cmake.install() |
| 123 | + |
| 124 | + def package_info(self): |
| 125 | + self.cpp_info.set_property("cmake_file_name", "milvus-common") |
| 126 | + self.cpp_info.set_property("cmake_target_name", "milvus-common::milvus-common") |
| 127 | + self.cpp_info.libs = ["milvus-common"] |
| 128 | + self.cpp_info.defines = ["OPENTELEMETRY_STL_VERSION=2017"] |
| 129 | + self.cpp_info.requires = [ |
| 130 | + "opentelemetry-cpp::opentelemetry_trace", |
| 131 | + "opentelemetry-cpp::opentelemetry_exporter_ostream_span", |
| 132 | + "opentelemetry-cpp::opentelemetry_exporter_otlp_http", |
| 133 | + "folly::folly", |
| 134 | + "gflags::gflags", |
| 135 | + "glog::glog", |
| 136 | + "fmt::fmt", |
| 137 | + "nlohmann_json::nlohmann_json", |
| 138 | + "prometheus-cpp::prometheus-cpp-core", |
| 139 | + "prometheus-cpp::prometheus-cpp-push", |
| 140 | + ] |
| 141 | + if self.dependencies["opentelemetry-cpp"].options.with_otlp_grpc: |
| 142 | + self.cpp_info.requires.append("opentelemetry-cpp::opentelemetry_exporter_otlp_grpc") |
| 143 | + self.cpp_info.defines.append("HAVE_OTLP_GRPC_EXPORTER") |
| 144 | + if self.settings.os == "Linux": |
| 145 | + self.cpp_info.requires.append("openblas::openblas") |
| 146 | + self.cpp_info.system_libs.extend(["pthread", "dl"]) |
| 147 | + if self.settings.compiler == "gcc": |
| 148 | + self.cpp_info.system_libs.extend(["gomp", "atomic"]) |
| 149 | + elif self.settings.compiler == "clang": |
| 150 | + self.cpp_info.system_libs.append("omp") |
| 151 | + elif self.settings.os == "Macos": |
| 152 | + self.cpp_info.defines.append("BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED") |
0 commit comments