forked from ruslo/hunter
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `asio-grpc` a header only wrapper to enable asynchronous gRPC with Asio/unified executors Co-authored-by: NeroBurner <[email protected]>
- Loading branch information
1 parent
afbeade
commit 0b11f79
Showing
5 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (c) 2022, Tradias | ||
# All rights reserved. | ||
|
||
# !!! DO NOT PLACE HEADER GUARDS HERE !!! | ||
|
||
include(hunter_add_version) | ||
include(hunter_cacheable) | ||
include(hunter_download) | ||
include(hunter_pick_scheme) | ||
|
||
hunter_add_version( | ||
PACKAGE_NAME | ||
asio-grpc | ||
VERSION | ||
1.6.0 | ||
URL | ||
"https://github.com/Tradias/asio-grpc/archive/refs/tags/v1.6.0.tar.gz" | ||
SHA1 | ||
a5ab9797a34b390236fdd52986ee792a6894221f | ||
) | ||
|
||
hunter_pick_scheme(DEFAULT url_sha1_cmake) | ||
hunter_cacheable(asio-grpc) | ||
hunter_download(PACKAGE_NAME asio-grpc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
.. spelling:: | ||
|
||
asio-grpc | ||
|
||
.. index:: | ||
single: concurrency ; asio-grpc | ||
single: networking ; asio-grpc | ||
|
||
.. _pkg.asio-grpc: | ||
|
||
asio-grpc | ||
========= | ||
|
||
- `Official <https://github.com/Tradias/asio-grpc>`__ | ||
- `Example <https://github.com/cpp-pm/hunter/blob/master/examples/asio-grpc/CMakeLists.txt>`__ | ||
- Added by `Tradias <https://github.com/Tradias>`__ (`pr-554 <https://github.com/cpp-pm/hunter/pull/554>`__) | ||
|
||
.. literalinclude:: /../examples/asio-grpc/CMakeLists.txt | ||
:language: cmake | ||
:start-after: # DOCUMENTATION_START { | ||
:end-before: # DOCUMENTATION_END } | ||
|
||
CMake options | ||
------------- | ||
|
||
The ``CMAKE_ARGS`` feature (see | ||
`customization <https://hunter.readthedocs.io/en/latest/reference/user-modules/hunter_config.html>`__) | ||
can be used to customize asio-grpc: | ||
|
||
- To use standalone Asio instead of Boost.Asio: | ||
|
||
.. code-block:: cmake | ||
hunter_config( | ||
asio-grpc | ||
VERSION ${HUNTER_asio-grpc_VERSION} | ||
CMAKE_ARGS | ||
ASIO_GRPC_HUNTER_BACKEND_BOOST_ASIO=OFF | ||
ASIO_GRPC_HUNTER_BACKEND_STANDALONE_ASIO=ON | ||
) | ||
- To use Boost.Container instead of ``<memory_resource>``: | ||
|
||
.. code-block:: cmake | ||
hunter_config( | ||
asio-grpc | ||
VERSION ${HUNTER_asio-grpc_VERSION} | ||
CMAKE_ARGS | ||
ASIO_GRPC_USE_BOOST_CONTAINER=ON | ||
) | ||
For more options see `asio-grpc repository <https://github.com/Tradias/asio-grpc#cmake-options>`__. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (c) 2016-2020, Rahul Sheth, Ruslan Baratov | ||
# All rights reserved. | ||
|
||
cmake_minimum_required(VERSION 3.2) | ||
|
||
# Emulate HunterGate: | ||
# * https://github.com/hunter-packages/gate | ||
include("../common.cmake") | ||
|
||
project(download-asio-grpc) | ||
|
||
# DOCUMENTATION_START { | ||
hunter_add_package(asio-grpc) | ||
find_package(asio-grpc CONFIG REQUIRED) | ||
|
||
add_executable(boo boo.cpp) | ||
target_link_libraries(boo PUBLIC asio-grpc::asio-grpc) | ||
# DOCUMENTATION_END } | ||
|
||
# Test double library creation | ||
find_package(asio-grpc CONFIG REQUIRED) | ||
|
||
# Check license | ||
string(COMPARE EQUAL "${asio-grpc_LICENSES}" "" is_empty) | ||
if(is_empty) | ||
message(FATAL_ERROR "Licenses not found") | ||
endif() | ||
|
||
message("asio-grpc licenses:") | ||
foreach(x ${asio-grpc_LICENSES}) | ||
message("* ${x}") | ||
if(NOT EXISTS "${x}") | ||
message(FATAL_ERROR "File not found") | ||
endif() | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <agrpc/asioGrpc.hpp> | ||
|
||
#include <iostream> | ||
|
||
int main() { | ||
agrpc::GrpcContext grpc_context{std::make_unique<grpc::CompletionQueue>()}; | ||
grpc::Alarm alarm; | ||
agrpc::wait(alarm, | ||
std::chrono::system_clock::now() + std::chrono::milliseconds(10), | ||
boost::asio::bind_executor(grpc_context, [](bool ok) { | ||
std::cout << "Waited for grpc::Alarm: " << ok << std::endl; | ||
})); | ||
grpc_context.run(); | ||
} |