Skip to content

Commit

Permalink
[Cpp]: add opendal optional compile (#116)
Browse files Browse the repository at this point in the history
Signed-off-by: sunby <[email protected]>
  • Loading branch information
sunby committed Jan 30, 2024
1 parent fb501d0 commit 88bc6a7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
20 changes: 14 additions & 6 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions cpp/include/milvus-storage/common/opendal_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once
#ifdef MILVUS_OPENDAL
#include <arrow/filesystem/filesystem.h>
#include <arrow/util/macros.h>
#include <arrow/util/uri.h>
Expand Down Expand Up @@ -77,3 +79,5 @@ class OpendalFileSystem : public arrow::fs::FileSystem {
};

} // namespace milvus_storage

#endif
4 changes: 4 additions & 0 deletions cpp/src/common/fs_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include <cstdlib>
#include "common/log.h"
#include "common/macro.h"
#ifdef MILVUS_OPENDAL
#include "common/opendal_fs.h"
#endif

namespace milvus_storage {

Expand All @@ -42,11 +44,13 @@ Result<std::unique_ptr<arrow::fs::FileSystem>> BuildFileSystem(const std::string
// return std::shared_ptr<arrow::fs::FileSystem>(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<arrow::fs::FileSystem>(std::move(fs));
}
#endif

// if (schema == "s3") {
// if (!arrow::fs::IsS3Initialized()) {
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/common/opendal_fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <arrow/filesystem/filesystem.h>
#include <arrow/filesystem/path_util.h>
Expand Down Expand Up @@ -313,3 +314,5 @@ arrow::Result<std::shared_ptr<arrow::io::OutputStream>> OpendalFileSystem::OpenA
}

} // namespace milvus_storage

#endif

0 comments on commit 88bc6a7

Please sign in to comment.