Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: add cmake install #63

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Test
run: |
./clean.sh
bazel coverage //trpc/... --test_output=all --coverage_report_generator="@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" --combined_report=lcov --nocache_test_results
bazel coverage //trpc/... --test_output=errors --coverage_report_generator="@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" --combined_report=lcov --nocache_test_results
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
Expand Down
70 changes: 70 additions & 0 deletions docs/en/setup_env.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,72 @@ Since the FetchContent feature of CMake is required for fetching third-party dep
./run_examples_cmake.sh
```

3. **How to use tRPC-Cpp**

a. (Recommend) Use as external source code

We recommend this as it can easily switch tRPC-Cpp version to the lastest and the libs framework depends on can also be imported via a simple SDK target named `trpc`.

For example, you can import in CMakeLists.txt in this way:

```shell
# Fetch tRPC-Cpp and add as library
include(FetchContent)
FetchContent_Declare(
trpc-cpp
GIT_REPOSITORY https://git.woa.com/trpc-cpp/open-source/trpc-cpp.git
GIT_TAG recommanded_always_use_latest_tag
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake_third_party/trpc-cpp
)
FetchContent_MakeAvailable(trpc-cpp)

# Set path of stub code genretated tool(PROTOBUF_PROTOC_EXECUTABLE/TRPC_TO_CPP_PLUGIN will be filled after you import tRPC-Cpp)
set(PB_PROTOC ${PROTOBUF_PROTOC_EXECUTABLE})
set(TRPC_CPP_PLUGIN ${TRPC_TO_CPP_PLUGIN})

# link lib trpc to your target
target_link_libraries(your_cmake_target trpc)
```

b. Use via make install

Execute below commands, install tRPC-Cpp to your machine first:

```shell
# You can install the lastest verion by: git checkout tags/vx.x.x
git clone https://github.com/trpc-group/trpc-cpp.git
cd trpc-cpp
mkdir build && cd build

# By default, tRPC-Cpp will build as static lib. If you need dynamic lib, add cmake option: -DTRPC_BUILD_SHARED=ON
cmake ..
make -j8
make install # install at /usr/local/trpc-cpp/trpc
```

Then, import trpc lib in your CMakeLists.txt as below:

```shell
# set install path of tRPC-Cpp
set(TRPC_INSTALL_PATH /usr/local/trpc-cpp/trpc)

# Load hearders and libs
include(${TRPC_INSTALL_PATH}/cmake/config/trpc_config.cmake)
include_directories(${INCLUDE_INSTALL_PATHS})
link_directories(${LIBRARY_INSTALL_PATHS})

# Set path of stub code genretated tool
include(${TRPC_INSTALL_PATH}/cmake/tools/trpc_utils.cmake)
set(PB_PROTOC ${TRPC_INSTALL_PATH}/bin/protoc)
set(TRPC_CPP_PLUGIN ${TRPC_INSTALL_PATH}/bin/trpc_cpp_plugin)

# add trpc and it's dependent libs
set(LIBRARY trpc ${LIBS_BASIC})

# link lib trpc to your target
target_link_libraries(your_cmake_target trpc)
```

## Ubuntu

It recommend using **Ubuntu version 20.04 LTS or above** for compiling and running tRPC-Cpp.
Expand Down Expand Up @@ -145,6 +211,10 @@ Since the FetchContent feature of CMake is required for fetching third-party dep
./run_examples_cmake.sh
```

3. **How to use tRPC-Cpp**

Same as CentOS section

# FAQ

## bazel --version" shows a "command not found" error?
Expand Down
71 changes: 71 additions & 0 deletions docs/zh/setup_env.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,72 @@ bazel 推荐使用 3.5.1及以后版本。
./run_examples_cmake.sh
```

3. **如何引入tRPC-Cpp**

a. (推荐)以外部库形式源码引入

推荐使用这种方式,因为能很方便切换框架的版本,同时,框架相关依赖可随构建的SDK目标引入。

参考如下示例,在您项目的 CMakeLists.txt 以外部库源码方式引入:

```shell
# 拉取并以库的形式添加tRPC-Cpp
include(FetchContent)
FetchContent_Declare(
trpc-cpp
GIT_REPOSITORY https://git.woa.com/trpc-cpp/open-source/trpc-cpp.git
GIT_TAG recommanded_always_use_latest_tag
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake_third_party/trpc-cpp
)
FetchContent_MakeAvailable(trpc-cpp)

# 设置proto文件桩代码生成工具的路径(PROTOBUF_PROTOC_EXECUTABLE/TRPC_TO_CPP_PLUGIN将会在tRPC-Cpp被引入后自动填充)
set(PB_PROTOC ${PROTOBUF_PROTOC_EXECUTABLE})
set(TRPC_CPP_PLUGIN ${TRPC_TO_CPP_PLUGIN})

# 在您的构建目标里link trpc库
target_link_libraries(your_cmake_target trpc)
```

b. 通过make install引入

参考如下命令,先安装trpc到系统里:

```shell
# 可checkout切换到最新的版本
git clone https://github.com/trpc-group/trpc-cpp.git
cd trpc-cpp
mkdir build && cd build

# 默认编译静态库,可以通过cmake选项编译动态库: -DTRPC_BUILD_SHARED=ON
cmake ..
make -j8
make install
```

然后,参考如下步骤,在您项目的 CMakeLists.txt 里,引入trpc库:

```shell
# 设置tRPC-Cpp的安装位置
set(TRPC_INSTALL_PATH /usr/local/trpc-cpp/trpc)

# 加载tRPC-Cpp头文件及库路径
include(${TRPC_INSTALL_PATH}/cmake/config/trpc_config.cmake)
include_directories(${INCLUDE_INSTALL_PATHS})
link_directories(${LIBRARY_INSTALL_PATHS})

# 设置proto文件桩代码生成工具的路径 - 具体使用方式见相关章节
include(${TRPC_INSTALL_PATH}/cmake/tools/trpc_utils.cmake)
set(PB_PROTOC ${TRPC_INSTALL_PATH}/bin/protoc)
set(TRPC_CPP_PLUGIN ${TRPC_INSTALL_PATH}/bin/trpc_cpp_plugin)

# 添加trpc库及其依赖的三方
set(LIBRARY trpc ${LIBS_BASIC})

# 在您的构建目标里link trpc库
target_link_libraries(your_cmake_target trpc)
```

## Ubuntu

推荐**Ubuntu 版本在 20.04 LTS 及以上版本**。
Expand Down Expand Up @@ -155,6 +221,11 @@ bazel 推荐使用3.5.1及以后版本。
./run_examples_cmake.sh
```

3. **安装及使用**

同CentOS 部分。


# FAQ

## bazel --version 出现找不到 bazel 命令?
Expand Down