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 <[email protected]> AuthorDate: Thu Aug 31 12:20:14 2023 +0800 docs(bindings/cpp): add CONTRIBUTING.md Signed-off-by: silver-ymz <[email protected]> --- .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>
