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

V3 cleanup #95

Merged
merged 7 commits into from
Feb 14, 2024
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
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
NamespaceMacros:
- AGRPC_NAMESPACE_BEGIN
- AGRPC_NAMESPACE_CPP20_BEGIN
- DOCTEST_TEST_SUITE
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ on:
- 'CMakePresets.json'

env:
VCPKG_VERSION: '0e47c1985273129e4d0ee52ff73bed9125555de8' # Jul 02, 2023
CMAKE_ARGS: '-DCMAKE_BUILD_TYPE=Release -DVCPKG_MANIFEST_INSTALL=off -DASIO_GRPC_ENABLE_PKGCONFIG_FALLBACK=off -DCMAKE_COMPILE_WARNING_AS_ERROR=on'
VCPKG_VERSION: '0e47c1985273129e4d0ee52ff73bed9125555de8'
CMAKE_ARGS: '-DCMAKE_BUILD_TYPE=Release -DVCPKG_MANIFEST_INSTALL=off -DASIO_GRPC_ENABLE_PKGCONFIG_FALLBACK=off -DCMAKE_COMPILE_WARNING_AS_ERROR=on -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=on'
CTEST_ARGS: '-T test --output-on-failure --timeout 180 --no-tests=error --parallel 25'

jobs:
Expand Down Expand Up @@ -274,7 +274,7 @@ jobs:
run: |
${{ env.VCPKG_ROOT }}/vcpkg install --recurse --clean-after-build --triplet ${{ env.TRIPLET }} --host-triplet ${{ env.TRIPLET }} \
--x-install-root=${{ runner.workspace }}/vcpkg_installed --overlay-ports=${{ github.workspace }}/deps --overlay-triplets=${{ github.workspace }}/.github/vcpkg \
libunifex boost-coroutine boost-asio boost-interprocess boost-thread boost-container boost-process asio[coroutine]
libunifex boost-coroutine boost-asio boost-interprocess boost-thread boost-process asio[coroutine]
working-directory: ${{ env.VCPKG_ROOT }}

- name: Configure CMake
Expand Down
12 changes: 1 addition & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ cmake_minimum_required(VERSION 3.14...3.27)

include("${CMAKE_CURRENT_LIST_DIR}/cmake/AsioGrpcOptionDefaults.cmake")

# user options
option(ASIO_GRPC_USE_BOOST_CONTAINER "(deprecated) Use Boost.Container instead of <memory_resource>"
${ASIO_GRPC_DEFAULT_USE_BOOST_CONTAINER})
option(ASIO_GRPC_USE_RECYCLING_ALLOCATOR "(deprecated) Use asio::recycling_allocator instead of <memory_resource>" off)

if(ASIO_GRPC_USE_BOOST_CONTAINER AND ASIO_GRPC_USE_RECYCLING_ALLOCATOR)
message(
FATAL_ERROR
"The options ASIO_GRPC_USE_BOOST_CONTAINER and ASIO_GRPC_USE_RECYCLING_ALLOCATOR are mutually exclusive.")
endif()

# Hunter package manager options
option(HUNTER_ENABLED "Enable Hunter package manager" off)
option(ASIO_GRPC_HUNTER_BACKEND_BOOST_ASIO "Build Boost.Asio using Hunter" on)
Expand Down Expand Up @@ -99,6 +88,7 @@ endif()
if(ASIO_GRPC_BUILD_TESTS)
include("${CMAKE_CURRENT_LIST_DIR}/cmake/AsioGrpcInstallGitHooks.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/AsioGrpcCoverage.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/AsioGrpcCheckStdPmr.cmake")
endif()

if(NOT ASIO_GRPC_PROJECT_IS_TOP_LEVEL OR ASIO_GRPC_BUILD_EXAMPLES)
Expand Down
170 changes: 88 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ An [Executor, Networking TS](https://www.boost.org/doc/libs/1_84_0/doc/html/boos
* Asio [ExecutionContext](https://www.boost.org/doc/libs/1_84_0/doc/html/boost_asio/reference/ExecutionContext.html) compatible wrapper around [grpc::CompletionQueue](https://grpc.github.io/grpc/cpp/classgrpc_1_1_completion_queue.html)
* Support for all RPC types: unary, client-streaming, server-streaming and bidirectional-streaming with any mix of Asio [CompletionToken](https://www.boost.org/doc/libs/1_84_0/doc/html/boost_asio/reference/asynchronous_operations.html#boost_asio.reference.asynchronous_operations.completion_tokens_and_handlers) as well as [Sender](https://github.com/facebookexperimental/libunifex/blob/main/doc/concepts.md#sender-concept), including allocator customization
* Support for asynchronously waiting for [grpc::Alarms](https://grpc.github.io/grpc/cpp/classgrpc_1_1_alarm.html) including cancellation through [cancellation_slots](https://www.boost.org/doc/libs/1_84_0/doc/html/boost_asio/reference/cancellation_slot.html) and [StopTokens](https://github.com/facebookexperimental/libunifex/blob/main/doc/concepts.md#stoptoken-concept)
* Support for `std::execution` through either [libunifex](https://github.com/facebookexperimental/libunifex) or [stdexec](https://github.com/NVIDIA/stdexec)
* Support for sender/receiver through either [libunifex](https://github.com/facebookexperimental/libunifex) or [stdexec](https://github.com/NVIDIA/stdexec)
* Support for generic gRPC clients and servers
* No extra codegen required, works with the vanilla gRPC C++ plugin (`grpc_cpp_plugin`)
* No-Boost version with [standalone Asio](https://github.com/chriskohlhoff/asio)
Expand All @@ -26,51 +26,73 @@ Officially supported compilers are GCC 8+, Clang 10+, AppleClang 14+ and latest

# Usage

The library can be added to a CMake project using either `add_subdirectory` or `find_package`. Once set up, include the individual headers from the agrpc/ directory or the convenience header:
The library can be added to a CMake project using either `add_subdirectory` or `find_package`. Once set up, include the individual headers from the `agrpc` directory or the convenience header:

```cpp
#include <agrpc/asio_grpc.hpp>
```

<details><summary><b>As a CMake subdirectory</b></summary>
<details><summary><b>Using vcpkg</b></summary>
<p>

Clone the repository into a subdirectory of your CMake project. Then add it and link it to your target.

Using [Boost.Asio](https://www.boost.org/doc/libs/1_84_0/doc/html/boost_asio.html):

```cmake
add_subdirectory(/path/to/asio-grpc)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc)
Add [asio-grpc](https://github.com/microsoft/vcpkg/blob/master/ports/asio-grpc/vcpkg.json) to the dependencies inside your `vcpkg.json`:

# Also link with the equivalents of gRPC::grpc++ and Boost::headers
```
{
"name": "your_app",
"version": "0.1.0",
"dependencies": [
"asio-grpc",
// To use the Boost.Asio backend add
// "boost-asio",
// To use the standalone Asio backend add
// "asio",
// To use the libunifex backend add
// "libunifex",
// To use the stdexec backend add
// "stdexec"
]
}
```

Or using [standalone Asio](https://github.com/chriskohlhoff/asio):
Locate asio-grpc and link it to your target in your `CMakeLists.txt`:

```cmake
add_subdirectory(/path/to/asio-grpc)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-standalone-asio)

# Also link with the equivalents of gRPC::grpc++ and asio::asio
find_package(asio-grpc)
# Using the Boost.Asio backend
find_package(Boost)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc Boost::headers)
# Or use the standalone Asio backend
find_package(asio)
#target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-standalone-asio asio::asio)
# Or use the libunifex backend
find_package(unifex)
#target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-unifex unifex::unifex)
# Or use the stdexec backend
find_package(stdexec)
#target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-stdexec STDEXEC::stdexec)
```

Or using [libunifex](https://github.com/facebookexperimental/libunifex):
</p>
</details>

```cmake
add_subdirectory(/path/to/asio-grpc)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-unifex)
<details><summary><b>Using Hunter</b></summary>
<p>

# Also link with the equivalents of gRPC::grpc++ and unifex::unifex
```
See asio-grpc's documentation on the Hunter website: [https://hunter.readthedocs.io/en/latest/packages/pkg/asio-grpc.html](https://hunter.readthedocs.io/en/latest/packages/pkg/asio-grpc.html).

Or using [stdexec](https://github.com/NVIDIA/stdexec):
</p>
</details>

```cmake
add_subdirectory(/path/to/asio-grpc)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-stdexec)
<details><summary><b>Using conan</b></summary>
<p>

The recipe in conan-center is called [asio-grpc](https://conan.io/center/recipes/asio-grpc).
If you are using conan's CMake generator then link with `asio-grpc::asio-grpc` independent of the backend that you choose:

# Also link with the equivalents of gRPC::grpc++ and STDEXEC::stdexec
```cmake
find_package(asio-grpc)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc)
```

</p>
Expand All @@ -93,98 +115,83 @@ Using [Boost.Asio](https://www.boost.org/doc/libs/1_84_0/doc/html/boost_asio.htm
```cmake
# Make sure CMAKE_PREFIX_PATH contains /desired/installation/directory
find_package(asio-grpc)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc)
find_package(Boost)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc Boost::headers)
```

Or using [standalone Asio](https://github.com/chriskohlhoff/asio):

```cmake
# Make sure CMAKE_PREFIX_PATH contains /desired/installation/directory
find_package(asio-grpc)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-standalone-asio)
find_package(asio)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-standalone-asio asio::asio)
```

Or using [libunifex](https://github.com/facebookexperimental/libunifex):

```cmake
# Make sure CMAKE_PREFIX_PATH contains /desired/installation/directory
find_package(asio-grpc)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-unifex)
find_package(unifex)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-unifex unifex::unifex)
```

Or using [stdexec](https://github.com/NVIDIA/stdexec):

```cmake
# Make sure CMAKE_PREFIX_PATH contains /desired/installation/directory
find_package(asio-grpc)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-stdexec)
find_package(stdexec)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-stdexec STDEXEC::stdexec)
```

</p>
</details>

<details><summary><b>Using vcpkg</b></summary>
<details><summary><b>As a CMake subdirectory</b></summary>
<p>

Add [asio-grpc](https://github.com/microsoft/vcpkg/blob/master/ports/asio-grpc/vcpkg.json) to the dependencies inside your `vcpkg.json`:

```
{
"name": "your_app",
"version": "0.1.0",
"dependencies": [
"asio-grpc",
// To use the Boost.Asio backend add
// "boost-asio",
// To use the standalone Asio backend add
// "asio",
// To use the libunifex backend add
// "libunifex",
// To use the stdexec backend add
// "stdexec"
]
}
```
Clone the repository into a subdirectory of your CMake project. Then add it and link it to your target.

Locate asio-grpc and link it to your target in your `CMakeLists.txt`:
Independent of the backend you chose, find and link with gRPC:

```cmake
find_package(asio-grpc)
# Using the Boost.Asio backend
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc)
# Or use the standalone Asio backend
#target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-standalone-asio)
# Or use the libunifex backend
#target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-unifex)
# Or use the stdexec backend
#target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-stdexec)
find_package(gRPC)
target_link_libraries(your_app PUBLIC gRPC::grpc++)
```

</p>
</details>

<details><summary><b>Using Hunter</b></summary>
<p>
Using [Boost.Asio](https://www.boost.org/doc/libs/1_84_0/doc/html/boost_asio.html):

See asio-grpc's documentation on the Hunter website: [https://hunter.readthedocs.io/en/latest/packages/pkg/asio-grpc.html](https://hunter.readthedocs.io/en/latest/packages/pkg/asio-grpc.html).
```cmake
add_subdirectory(/path/to/asio-grpc)
find_package(Boost)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc Boost::headers)
```

</p>
</details>
Or using [standalone Asio](https://github.com/chriskohlhoff/asio):

<details><summary><b>Using conan</b></summary>
<p>
```cmake
add_subdirectory(/path/to/asio-grpc)
find_package(asio)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-standalone-asio asio::asio)
```

The recipe in conan-center is called [asio-grpc](https://conan.io/center/recipes/asio-grpc).
If you are using conan's CMake generator then link with `asio-grpc::asio-grpc` independent of the backend that you choose:
Or using [libunifex](https://github.com/facebookexperimental/libunifex):

```cmake
find_package(asio-grpc)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc)
add_subdirectory(/path/to/asio-grpc)
find_package(unifex)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-unifex unifex::unifex)
```

### Available options
Or using [stdexec](https://github.com/NVIDIA/stdexec):

`backend` - One of "boost" for Boost.Asio, "asio" for standalone Asio or "unifex" for libunifex.
```cmake
add_subdirectory(/path/to/asio-grpc)
find_package(stdexec)
target_link_libraries(your_app PUBLIC asio-grpc::asio-grpc-stdexec STDEXEC::stdexec)
```

</p>
</details>
Expand All @@ -209,14 +216,14 @@ the backend's header files and libraries can be found correctly.

asio-grpc is part of [grpc_bench](https://github.com/Tradias/grpc_bench). Head over there to compare its performance against other libraries and languages.

<details><summary><b>Results</b></summary>
<p>

Below are the results from the helloworld unary RPC for:
Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Linux, GCC 12.2.0, Boost 1.80.0, gRPC 1.52.1, asio-grpc v2.5.0, jemalloc 5.2.1
Request scenario: string_100B

<details><summary><b>Results</b></summary>
<p>

### 1 CPU server

| name | req/s | avg. latency | 90 % in | 95 % in | 99 % in | avg. cpu | avg. memory |
Expand Down Expand Up @@ -252,8 +259,7 @@ Request scenario: string_100B

# Documentation

[**Documentation**](https://tradias.github.io/asio-grpc/)
[**Examples**](/example)
[**Documentation**](https://tradias.github.io/asio-grpc/) | [**Examples**](/example)

The main workhorses of this library are the [agrpc::GrpcContext](https://tradias.github.io/asio-grpc/classagrpc_1_1_grpc_context.html) and its `executor_type` - [agrpc::GrpcExecutor](https://tradias.github.io/asio-grpc/classagrpc_1_1_basic_grpc_executor.html).

Expand Down
19 changes: 19 additions & 0 deletions cmake/AsioGrpcCheckStdPmr.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 Dennis Hezel
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

try_compile(
ASIO_GRPC_HAS_STD_PMR "${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_LIST_DIR}/check_std_pmr.cpp"
CMAKE_FLAGS "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
LINK_LIBRARIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED on)
4 changes: 0 additions & 4 deletions cmake/AsioGrpcCompileOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ target_compile_features(asio-grpc-compile-options INTERFACE cxx_std_17)
target_sources(asio-grpc-compile-options
INTERFACE "$<$<CXX_COMPILER_ID:MSVC>:${ASIO_GRPC_PROJECT_ROOT}/asio-grpc.natvis>")

if(ASIO_GRPC_USE_BOOST_CONTAINER)
target_link_libraries(asio-grpc-compile-options INTERFACE Boost::container)
endif()

# C++20 compile options
add_library(asio-grpc-compile-options-cpp20 INTERFACE)

Expand Down
5 changes: 1 addition & 4 deletions cmake/AsioGrpcFindPackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ unset(FPHSA_NAME_MISMATCHED)
find_package(gRPC)

set(ASIO_GRPC_FIND_BOOST_COMPONENTS coroutine)
if(ASIO_GRPC_USE_BOOST_CONTAINER)
list(APPEND ASIO_GRPC_FIND_BOOST_COMPONENTS container)
endif()
if(ASIO_GRPC_BUILD_TESTS)
list(APPEND ASIO_GRPC_FIND_BOOST_COMPONENTS thread filesystem)
endif()
Expand All @@ -41,7 +38,7 @@ if(ASIO_GRPC_ENABLE_CPP20_TESTS_AND_EXAMPLES)
endif()

if(ASIO_GRPC_ENABLE_STDEXEC_TESTS)
find_package(stdexec CONFIG)
find_package(stdexec)
endif()

# Fallback to pkg-config
Expand Down
4 changes: 0 additions & 4 deletions cmake/AsioGrpcHunter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ if(ASIO_GRPC_HUNTER_BACKEND_STANDALONE_ASIO OR ASIO_GRPC_BUILD_TESTS)
list(APPEND HUNTER_PACKAGES asio)
endif()

if(ASIO_GRPC_USE_BOOST_CONTAINER)
set(HUNTER_Boost_COMPONENTS container)
endif()

if(ASIO_GRPC_BUILD_TESTS)
list(APPEND HUNTER_PACKAGES doctest)
list(APPEND HUNTER_Boost_COMPONENTS coroutine thread filesystem)
Expand Down
9 changes: 1 addition & 8 deletions cmake/AsioGrpcInstallation.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,4 @@ install(
TYPE INCLUDE
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.ipp"
PATTERN "*memory_resource.hpp" EXCLUDE
PATTERN "*memory_resource_boost_pmr.hpp" EXCLUDE
PATTERN "*memory_resource_recycling_allocator.hpp" EXCLUDE
PATTERN "*memory_resource_std_pmr.hpp" EXCLUDE)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/src/generated/agrpc/detail/memory_resource.hpp"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/agrpc/detail")
PATTERN "*.ipp")
Loading
Loading