From 88bc6a7b854f7b24dff6463bb27922e8f8a05e72 Mon Sep 17 00:00:00 2001 From: Bingyi Sun Date: Tue, 30 Jan 2024 11:54:55 +0800 Subject: [PATCH] [Cpp]: add opendal optional compile (#116) Signed-off-by: sunby --- cpp/CMakeLists.txt | 20 +++++++++++++------ .../milvus-storage/common/opendal_fs.h | 4 ++++ cpp/src/common/fs_util.cpp | 4 ++++ cpp/src/common/opendal_fs.cpp | 3 +++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 2b0983f..8111a2a 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -4,12 +4,16 @@ project(milvus-storage VERSION 0.1.0) option(WITH_UT "Build the testing tree." ON) option(WITH_ASAN "Build with address sanitizer." OFF) +option(WITH_OPENDAL "Build with opendal." OFF) set(CMAKE_CXX_STANDARD 17) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -include(libopendal) +if (WITH_OPENDAL) + add_compile_definitions(MILVUS_OPENDAL) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + include(libopendal) +endif() find_package(Boost REQUIRED) find_package(Arrow REQUIRED) @@ -19,14 +23,18 @@ find_package(glog REQUIRED) file(GLOB_RECURSE SRC_FILES src/*.cpp src/*.cc) add_library(milvus-storage ${SRC_FILES}) target_include_directories(milvus-storage PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/milvus-storage ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/test/include) -target_link_libraries(milvus-storage PUBLIC +set(LINK_LIBS arrow::libarrow arrow::libparquet Boost::boost protobuf::protobuf - glog::glog - opendal -) + glog::glog) + +if (WITH_OPENDAL) + list(APPEND LINK_LIBS opendal) +endif() + +target_link_libraries(milvus-storage PUBLIC ${LINK_LIBS}) if (WITH_UT) enable_testing() diff --git a/cpp/include/milvus-storage/common/opendal_fs.h b/cpp/include/milvus-storage/common/opendal_fs.h index 85a4262..5fcf61a 100644 --- a/cpp/include/milvus-storage/common/opendal_fs.h +++ b/cpp/include/milvus-storage/common/opendal_fs.h @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#pragma once +#ifdef MILVUS_OPENDAL #include #include #include @@ -77,3 +79,5 @@ class OpendalFileSystem : public arrow::fs::FileSystem { }; } // namespace milvus_storage + +#endif \ No newline at end of file diff --git a/cpp/src/common/fs_util.cpp b/cpp/src/common/fs_util.cpp index 537cf68..5faa03a 100644 --- a/cpp/src/common/fs_util.cpp +++ b/cpp/src/common/fs_util.cpp @@ -20,7 +20,9 @@ #include #include "common/log.h" #include "common/macro.h" +#ifdef MILVUS_OPENDAL #include "common/opendal_fs.h" +#endif namespace milvus_storage { @@ -42,11 +44,13 @@ Result> BuildFileSystem(const std::string // return std::shared_ptr(fs); // } +#ifdef MILVUS_OPENDAL if (scheme == "opendal") { ASSIGN_OR_RETURN_ARROW_NOT_OK(auto option, OpendalOptions::FromUri(uri_parser, out_path)); ASSIGN_OR_RETURN_ARROW_NOT_OK(auto fs, OpendalFileSystem::Make(option)); return std::unique_ptr(std::move(fs)); } +#endif // if (schema == "s3") { // if (!arrow::fs::IsS3Initialized()) { diff --git a/cpp/src/common/opendal_fs.cpp b/cpp/src/common/opendal_fs.cpp index 7a1ee41..52f159c 100644 --- a/cpp/src/common/opendal_fs.cpp +++ b/cpp/src/common/opendal_fs.cpp @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#ifdef MILVUS_OPENDAL #include "common/opendal_fs.h" #include #include @@ -313,3 +314,5 @@ arrow::Result> OpendalFileSystem::OpenA } } // namespace milvus_storage + +#endif \ No newline at end of file