You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by si...@apache.org on 2023/08/31 05:52:05 UTC
[incubator-opendal] branch cpp-contribute-docs created (now 6728d0f19)
This is an automated email from the ASF dual-hosted git repository.
silver pushed a change to branch cpp-contribute-docs
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
at 6728d0f19 add address sanitizer to check memory error
This branch includes the following new commits:
new b882b30d1 docs(bindings/cpp): add CONTRIBUTING.md
new 6728d0f19 add address sanitizer to check memory error
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[incubator-opendal] 01/02: docs(bindings/cpp): add CONTRIBUTING.md
Posted by si...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
silver pushed a commit to branch cpp-contribute-docs
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit b882b30d1653cf9868264a619c0e828a61ea3c2a
Author: silver-ymz <yi...@gmail.com>
AuthorDate: Thu Aug 31 12:20:14 2023 +0800
docs(bindings/cpp): add CONTRIBUTING.md
Signed-off-by: silver-ymz <yi...@gmail.com>
---
.devcontainer/post_create.sh | 3 ++
bindings/cpp/.gitignore | 2 +-
bindings/cpp/CONTRIBUTING.md | 103 +++++++++++++++++++++++++++++++++++++++
bindings/cpp/include/opendal.hpp | 1 +
4 files changed, 108 insertions(+), 1 deletion(-)
diff --git a/.devcontainer/post_create.sh b/.devcontainer/post_create.sh
index 1f9b84a1d..8faedbf5f 100644
--- a/.devcontainer/post_create.sh
+++ b/.devcontainer/post_create.sh
@@ -65,3 +65,6 @@ sudo apt install -y php8.2 php8.2-dev
sudo apt install -y opam
opam init --auto-setup --yes
opam install -y dune ounit2 ocamlformat
+
+# Setup for Cpp binding
+sudo apt install -y ninja-build
\ No newline at end of file
diff --git a/bindings/cpp/.gitignore b/bindings/cpp/.gitignore
index c1d315b0e..20ded089e 100644
--- a/bindings/cpp/.gitignore
+++ b/bindings/cpp/.gitignore
@@ -1,3 +1,3 @@
compile_commands.json
.cache
-build
\ No newline at end of file
+build*
\ No newline at end of file
diff --git a/bindings/cpp/CONTRIBUTING.md b/bindings/cpp/CONTRIBUTING.md
new file mode 100644
index 000000000..f6a934c94
--- /dev/null
+++ b/bindings/cpp/CONTRIBUTING.md
@@ -0,0 +1,103 @@
+# Contributing
+
+- [Contributing](#contributing)
+ - [Setup](#setup)
+ - [Using a dev container environment](#using-a-dev-container-environment)
+ - [Bring your own toolbox](#bring-your-own-toolbox)
+ - [Build](#build)
+ - [Test](#test)
+
+## Setup
+
+### Using a dev container environment
+
+OpenDAL provides a pre-configured [dev container](https://containers.dev/) that could be used in [Github Codespaces](https://github.com/features/codespaces), [VSCode](https://code.visualstudio.com/), [JetBrains](https://www.jetbrains.com/remote-development/gateway/), [JuptyerLab](https://jupyterlab.readthedocs.io/en/stable/). Please pick up your favourite runtime environment.
+
+The fastest way is:
+
+[](https://codespaces.new/apache/incubator-opendal?quickstart=1&machine=standardLinux32gb)
+
+### Bring your own toolbox
+
+To build OpenDAL C++ binding, the following is all you need:
+
+- **C++ toolchain** that supports **c++17**, _e.g._ clang++ and g++
+
+- **CMake**. It is used to generate the build system.
+
+- **Ninja**. It is used to build the project. You can also use other build systems supported by CMake, _e.g._ make, bazel, etc. You just need to make corresponding changes to following commands.
+
+- To format the code, you need to install **clang-format**
+
+- **GTest(Google Test)**. It is used to run the tests. To see how to build, check [here](https://github.com/google/googletest).
+
+For Ubuntu and Debian:
+
+```shell
+# install C/C++ toolchain (can be replaced by other toolchains)
+sudo apt install build-essential
+
+# install CMake and Ninja
+sudo apt install cmake ninja-build
+
+# install clang-format
+sudo apt install clang-format
+
+# install and build GTest library under /usr/lib and softlink to /usr/local/lib
+sudo apt-get install libgtest-dev
+cd /usr/src/gtest
+sudo cmake CMakeLists.txt
+sudo make
+sudo cp lib/*.a /usr/lib
+sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a
+sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a
+```
+
+For MacOS:
+
+```shell
+# install C/C++ toolchain (can be replaced by other toolchains)
+xcode-select --install
+
+# install CMake and Ninja
+brew install cmake ninja
+
+# install clang-format
+brew install clang-format
+
+# install GTest library
+brew install googletest
+```
+
+## Build
+
+To build the library and header file.
+
+```shell
+mkdir build
+cd build
+
+# Add -DCMAKE_EXPORT_COMPILE_COMMANDS=1 to generate compile_commands.json for clangd
+cmake -DCMAKE_BUILD_TYPE=Debug -GNinja ..
+
+ninja
+```
+
+- The header file `opendal.hpp` is under `./include`.
+- The library is under `build` after building.
+
+To clean the build results.
+
+```shell
+ninja clean
+```
+
+## Test
+
+To build and run the tests. (Note that you need to install GTest)
+
+You should build the project first. Then run:
+
+```shell
+ninja test
+```
diff --git a/bindings/cpp/include/opendal.hpp b/bindings/cpp/include/opendal.hpp
index 2d42b8390..6fd4c2379 100644
--- a/bindings/cpp/include/opendal.hpp
+++ b/bindings/cpp/include/opendal.hpp
@@ -20,6 +20,7 @@
#pragma once
#include "lib.rs.h"
+#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
[incubator-opendal] 02/02: add address sanitizer to check memory error
Posted by si...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
silver pushed a commit to branch cpp-contribute-docs
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit 6728d0f19c63fbeb7ea1f874deb2b3ee78544b25
Author: silver-ymz <yi...@gmail.com>
AuthorDate: Thu Aug 31 13:51:17 2023 +0800
add address sanitizer to check memory error
Signed-off-by: silver-ymz <yi...@gmail.com>
---
bindings/cpp/CMakeLists.txt | 6 ++++++
bindings/cpp/src/opendal.cpp | 12 ++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/bindings/cpp/CMakeLists.txt b/bindings/cpp/CMakeLists.txt
index b8b5abc1d..226b99749 100644
--- a/bindings/cpp/CMakeLists.txt
+++ b/bindings/cpp/CMakeLists.txt
@@ -65,6 +65,12 @@ target_include_directories(opendal_cpp_test PUBLIC ${CPP_INCLUDE_DIR} ${GTEST_IN
target_link_libraries(opendal_cpp_test ${GTEST_LDFLAGS} GTest::gtest_main opendal_cpp)
target_compile_options(opendal_cpp_test PRIVATE ${GTEST_CFLAGS})
+# enable address sanitizers
+if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+ target_compile_options(opendal_cpp_test PRIVATE -fsanitize=leak,address,undefined -fno-omit-frame-pointer -fno-common -O1)
+ target_link_options(opendal_cpp_test PRIVATE -fsanitize=leak,address,undefined)
+endif()
+
# Platform-specific test configuration
if(WIN32)
target_link_libraries(opendal_cpp_test userenv ws2_32 bcrypt)
diff --git a/bindings/cpp/src/opendal.cpp b/bindings/cpp/src/opendal.cpp
index 92c240c3e..49a1fa227 100644
--- a/bindings/cpp/src/opendal.cpp
+++ b/bindings/cpp/src/opendal.cpp
@@ -38,8 +38,16 @@ Operator::Operator(std::string_view scheme,
bool Operator::available() const { return operator_.has_value(); }
std::vector<uint8_t> Operator::read(std::string_view path) {
- auto res = operator_.value()->read(rust::Str(path.data()));
- return std::vector<uint8_t>(res.data(), res.data() + res.size());
+ auto rust_vec = operator_.value()->read(rust::Str(path.data()));
+
+ // Convert rust::Vec<uint8_t> to std::vector<uint8_t>
+ // This cannot use rust vector pointer to init std::vector because
+ // rust::Vec owns the memory and will free it when it goes out of scope.
+ std::vector<uint8_t> res;
+ res.reserve(rust_vec.size());
+ std::copy(rust_vec.cbegin(), rust_vec.cend(), std::back_inserter(res));
+
+ return res;
}
void Operator::write(std::string_view path, const std::vector<uint8_t> &data) {