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

asio-grpc: add version 3.2.0 #22910

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions recipes/asio-grpc/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"3.2.0":
url: "https://github.com/Tradias/asio-grpc/archive/refs/tags/v3.2.0.tar.gz"
sha256: "f281e84202cf75aae055d67c4200b794f240cd7bd9ff8ecc3f9670a8912edf4f"
"2.9.2":
url: "https://github.com/Tradias/asio-grpc/archive/refs/tags/v2.9.2.tar.gz"
sha256: "a025587278b3332f4c5dd0464b3d5313fbecb89fc58a6ec1d611f693d6b51ef2"
Expand Down
58 changes: 32 additions & 26 deletions recipes/asio-grpc/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class AsioGrpcConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
options = {
"backend": ["boost", "asio", "unifex"],
"local_allocator": ["auto", "memory_resource", "boost_container", "recycling_allocator"],
"local_allocator": ["memory_resource", "boost_container", "recycling_allocator"],
}
default_options = {
"backend": "boost",
"local_allocator": "auto",
# local_allocator default handled in config_options
}
no_copy_source = True

Expand All @@ -43,30 +43,37 @@ def _compilers_minimum_version(self):
"apple-clang": "11",
}

def configure(self):
self._local_allocator_option = self.options.local_allocator
if self._local_allocator_option == "auto":
def config_options(self):
if Version(self.version) >= "3.0.0":
del self.options.local_allocator
else:
libcxx = self.settings.compiler.get_safe("libcxx")
compiler_version = Version(self.settings.compiler.version)
prefer_boost_container = libcxx and str(libcxx) == "libc++" or \
(self.settings.compiler == "gcc" and compiler_version < "9") or \
(self.settings.compiler == "clang" and compiler_version < "12" and libcxx and str(libcxx) == "libstdc++")
self._local_allocator_option = "boost_container" if prefer_boost_container else "memory_resource"
if self._local_allocator_option == "recycling_allocator" and self.options.backend == "unifex":
raise ConanInvalidConfiguration(f"{self.name} 'recycling_allocator' cannot be used in combination with the 'unifex' backend.")
(self.settings.compiler == "gcc" and compiler_version < "9") or \
(self.settings.compiler == "clang" and compiler_version < "12" and libcxx and str(libcxx) == "libstdc++")
self.options.local_allocator = "boost_container" if prefer_boost_container else "memory_resource"

def requirements(self):
self.requires("grpc/1.54.3", transitive_libs=True)
if self._local_allocator_option == "boost_container" or self.options.backend == "boost":
self.requires("boost/1.83.0", transitive_headers=True)
use_latest = Version(self.version) > "2.8"
self.requires("grpc/1.54.3", transitive_headers=True, transitive_libs=True)
if (self.options.get_safe("local_allocator") == "boost_container" and Version(self.version) < "3.0.0") or self.options.backend == "boost":
version = "1.86.0" if use_latest else "1.83.0"
self.requires(f"boost/{version}", transitive_headers=True)
if self.options.backend == "asio":
self.requires("asio/1.29.0", transitive_headers=True)
version = "1.31.0" if use_latest else "1.29.0"
self.requires(f"asio/{version}", transitive_headers=True)
if self.options.backend == "unifex":
self.requires("libunifex/0.4.0")
self.requires("libunifex/0.4.0", transitive_headers=True, transitive_libs=True)

def package_id(self):
local_allocator = None
if "local_allocator" in self.info.options:
local_allocator = self.info.options.local_allocator
self.info.clear()
self.info.options.local_allocator = self._local_allocator_option
if local_allocator is not None:
# Keep the local_allocator option in the package_id
self.info.options.local_allocator = local_allocator

def layout(self):
cmake_layout(self, src_folder="src")
Expand All @@ -81,22 +88,21 @@ def validate(self):
raise ConanInvalidConfiguration(
f"{self.name} requires C++{self._min_cppstd}, which your compiler does not support."
)
else:
self.output.warning(
f"{self.name} requires C++{self._min_cppstd}. Your compiler is unknown. Assuming it supports"
f" C++{self._min_cppstd}."
)
if Version(self.version) == "2.7.0" and self.settings.compiler == "gcc" and compiler_version.major == "11" and \
compiler_version < "11.3":
compiler_version < "11.3":
raise ConanInvalidConfiguration(f"{self.ref} does not support gcc 11.0-11.2")

if self.options.get_safe("local_allocator") == "recycling_allocator" and self.options.backend == "unifex":
raise ConanInvalidConfiguration(f'{self.name} -o="&:local_allocator=recycling_allocator" cannot be used in combination with the -o="&:backend=unifex" backend.')

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["ASIO_GRPC_USE_BOOST_CONTAINER"] = self._local_allocator_option == "boost_container"
tc.variables["ASIO_GRPC_USE_RECYCLING_ALLOCATOR"] = self._local_allocator_option == "recycling_allocator"
if Version(self.version) < "3.0.0":
tc.variables["ASIO_GRPC_USE_BOOST_CONTAINER"] = self.options.get_safe("local_allocator") == "boost_container"
tc.variables["ASIO_GRPC_USE_RECYCLING_ALLOCATOR"] = self.options.get_safe("local_allocator") == "recycling_allocator"
tc.generate()

def build(self):
Expand All @@ -115,7 +121,7 @@ def package_info(self):

build_modules = [os.path.join("lib", "cmake", "asio-grpc", "AsioGrpcProtobufGenerator.cmake")]

self.cpp_info.requires = ["grpc::grpc++_unsecure"]
self.cpp_info.requires = ["grpc::grpc++"]
if self.options.backend == "boost":
self.cpp_info.defines = ["AGRPC_BOOST_ASIO"]
self.cpp_info.requires.append("boost::headers")
Expand All @@ -126,7 +132,7 @@ def package_info(self):
self.cpp_info.defines = ["AGRPC_UNIFEX"]
self.cpp_info.requires.append("libunifex::unifex")

if self._local_allocator_option == "boost_container":
if self.options.get_safe("local_allocator") == "boost_container" and Version(self.version) < "3.0.0":
self.cpp_info.requires.append("boost::container")

self.cpp_info.set_property("cmake_file_name", "asio-grpc")
Expand Down
4 changes: 0 additions & 4 deletions recipes/asio-grpc/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE asio-grpc::asio-grpc)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)

# See https://github.com/chriskohlhoff/asio/issues/955
target_compile_definitions(${PROJECT_NAME}
PRIVATE BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC)

if(${asio-grpc_VERSION} VERSION_GREATER_EQUAL 2)
target_compile_definitions(${PROJECT_NAME} PRIVATE ASIO_GRPC_V2)
endif()
Expand Down
17 changes: 3 additions & 14 deletions recipes/asio-grpc/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,10 @@ int main() {
boost::asio::post(grpc_context, [] {});

#ifndef CROSSCOMPILING
std::unique_ptr<test::Test::Stub> stub;
grpc::ClientContext client_context;
std::unique_ptr<grpc::ClientAsyncResponseReader<test::TestReply>> reader;
test::TestRequest request;
test::TestReply response;
grpc::Status status;

boost::asio::post(grpc_context, [&]() {
stub = test::Test::NewStub(grpc::CreateChannel(
boost::asio::post(grpc_context, []() {
[[maybe_unused]] auto stub = test::Test::NewStub(grpc::CreateChannel(
"localhost:50051", grpc::InsecureChannelCredentials()));
request.set_message("hello");
reader = agrpc::request(&test::Test::Stub::AsyncUnary, *stub,
client_context, request, grpc_context);
agrpc::finish(reader, response, status,
boost::asio::bind_executor(grpc_context, [](bool) {}));
[[maybe_unused]] test::TestRequest request;
});
#endif
}
2 changes: 2 additions & 0 deletions recipes/asio-grpc/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"3.2.0":
folder: all
"2.9.2":
folder: all
"2.7.0":
Expand Down
Loading