Skip to content

Commit

Permalink
Add asio-grpc v1.6.0 (#554)
Browse files Browse the repository at this point in the history
Add `asio-grpc` a header only wrapper to enable asynchronous gRPC with Asio/unified executors

Co-authored-by: NeroBurner <[email protected]>
  • Loading branch information
Tradias and NeroBurner committed Apr 27, 2022
1 parent afbeade commit 0b11f79
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/configs/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ hunter_default_version(angles VERSION 1.9.11-p0)
hunter_default_version(apg VERSION 0.0.0-b322f7a-p0)
hunter_default_version(arabica VERSION 0.0.0-a202766-p0)
hunter_default_version(asio VERSION 1.17.0-p0)
hunter_default_version(asio-grpc VERSION 1.6.0)
hunter_default_version(astc-encoder VERSION 3.0-7257cbd-p0)
hunter_default_version(autobahn-cpp VERSION 0.2.0)
hunter_default_version(autoutils VERSION 0.3.0)
Expand Down
24 changes: 24 additions & 0 deletions cmake/projects/asio-grpc/hunter.cmake
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)
54 changes: 54 additions & 0 deletions docs/packages/pkg/asio-grpc.rst
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>`__.

35 changes: 35 additions & 0 deletions examples/asio-grpc/CMakeLists.txt
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()
14 changes: 14 additions & 0 deletions examples/asio-grpc/boo.cpp
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();
}

0 comments on commit 0b11f79

Please sign in to comment.