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

[anyrpc] Add new recipe #13717

Merged
merged 21 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 14 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
17 changes: 17 additions & 0 deletions recipes/anyrpc/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sources:
"1.0.2":
url: "https://github.com/sgieseking/anyrpc/archive/refs/tags/v1.0.2.tar.gz"
sha256: "236c9fa0ba417af945d950866c9671a1efa06506af8c86efa2e89ab67607969f"
patches:
"1.0.2":
- patch_file: "patches/0001-fix-asan-1.0.2.patch"
patch_description: "Handle ASAN flag properly in CMakeLists.txt"
patch_type: backport
patch_source: "https://github.com/sgieseking/anyrpc/pull/42"
- patch_file: "patches/0002-fix-shared-library-1.0.2.patch"
patch_description: "Fixed 'undefined reference' error when compile for windows platform"
patch_type: backport
patch_source: "https://github.com/sgieseking/anyrpc/pull/43"
- patch_file: "patches/0003-use-conan-libs-1.0.2.patch"
patch_description: "Link to conan libs"
patch_type: "conan"
124 changes: 124 additions & 0 deletions recipes/anyrpc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
import os


required_conan_version = ">=1.52.0"


class AnyRPCConan(ConanFile):
name = "anyrpc"
description = "A multiprotocol remote procedure call system for C++"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/sgieseking/anyrpc"
topics = ("rpc")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_log4cplus": [True, False],
"with_threading": [True, False],
"with_regex": [True, False],
"with_wchar": [True, False],
"with_protocol_json": [True, False],
"with_protocol_xml": [True, False],
"with_protocol_messagepack": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_log4cplus": False,
"with_threading": True,
"with_wchar": True,
"with_regex": True,
"with_protocol_json": True,
"with_protocol_xml": True,
"with_protocol_messagepack": True,
}

@property
def _minimum_cpp_standard(self):
return 11

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
fdgStilla marked this conversation as resolved.
Show resolved Hide resolved

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if self.options.with_log4cplus:
self.requires("log4cplus/2.0.7")

def validate(self):
if self.info.settings.compiler.cppstd:
check_min_cppstd(self, self._minimum_cpp_standard)

if self.options.with_log4cplus and self.options.with_wchar:
fdgStilla marked this conversation as resolved.
Show resolved Hide resolved
raise ConanInvalidConfiguration(f"{self.ref} can not be built with both log4cplus and wchar, see https://github.com/sgieseking/anyrpc/issues/25")

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["ANYRPC_LIB_BUILD_SHARED"] = self.options.shared
tc.variables["BUILD_EXAMPLES"] = False
tc.variables["BUILD_TEST"] = False
tc.variables["BUILD_WITH_ADDRESS_SANITIZE"] = False

tc.variables["BUILD_WITH_LOG4CPLUS"] = self.options.with_log4cplus
tc.variables["BUILD_WITH_THREADING"] = self.options.with_threading
tc.variables["BUILD_WITH_REGEX"] = self.options.with_regex
tc.variables["BUILD_WITH_WCHAR"] = self.options.with_wchar

tc.variables["BUILD_PROTOCOL_JSON"] = self.options.with_protocol_json
tc.variables["BUILD_PROTOCOL_XML"] = self.options.with_protocol_xml
tc.variables["BUILD_PROTOCOL_MESSAGEPACK"] = self.options.with_protocol_messagepack
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)

def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, pattern="license", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.libs = ["anyrpc"]

if not self.options.shared:
if self.settings.os == "Windows":
self.cpp_info.system_libs.append("ws2_32")
fdgStilla marked this conversation as resolved.
Show resolved Hide resolved

if self.settings.os == "Linux":
self.cpp_info.system_libs = ["pthread"]
fdgStilla marked this conversation as resolved.
Show resolved Hide resolved
28 changes: 28 additions & 0 deletions recipes/anyrpc/all/patches/0001-fix-asan-1.0.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 74b4fbb92b654a9483ef3ff64b708fda46bd7b2b Mon Sep 17 00:00:00 2001
From: Falko Axmann <code@falkoaxmann.de>
Date: Sun, 12 Jan 2020 12:43:00 +0100
Subject: [PATCH] Handle ASAN flag properly in CMakeLists.txt

Because of a typo ("else" instead of "elseif"), the
BUILD_WITH_ADDRESS_SANITIZE option was ignored and on
Linux, anyrpc would always be built with ASAN enabled.
---
CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cfeb604..87991bb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -63,7 +63,7 @@ if (MSVC)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc" )
elseif (MINGW)
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -U__STRICT_ANSI__" )
-else (BUILD_WITH_ADDRESS_SANITIZE)
+elseif (BUILD_WITH_ADDRESS_SANITIZE)
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer" )
SET( ASAN_LIBRARY asan )
endif ()
--
2.36.1.windows.1

54 changes: 54 additions & 0 deletions recipes/anyrpc/all/patches/0002-fix-shared-library-1.0.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
From c8ece5d572bf68a7d0f63405089a7a8d7d6206ee Mon Sep 17 00:00:00 2001
From: "email@email.com" <email@email.com>
Date: Fri, 31 Jul 2020 15:37:29 +0300
Subject: [PATCH] fixed 'undefined reference' error when compile for windows
platform

---
include/anyrpc/json/jsonserver.h | 2 +-
include/anyrpc/messagepack/messagepackserver.h | 2 +-
include/anyrpc/xml/xmlserver.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/anyrpc/json/jsonserver.h b/include/anyrpc/json/jsonserver.h
index d883b16..000bbd4 100644
--- a/include/anyrpc/json/jsonserver.h
+++ b/include/anyrpc/json/jsonserver.h
@@ -24,7 +24,7 @@
namespace anyrpc
{

-bool JsonRpcHandler(MethodManager* manager, char* request, std::size_t length, Stream &response);
+ANYRPC_API bool JsonRpcHandler(MethodManager* manager, char* request, std::size_t length, Stream &response);

////////////////////////////////////////////////////////////////////////////////

diff --git a/include/anyrpc/messagepack/messagepackserver.h b/include/anyrpc/messagepack/messagepackserver.h
index cc708f8..708bd72 100644
--- a/include/anyrpc/messagepack/messagepackserver.h
+++ b/include/anyrpc/messagepack/messagepackserver.h
@@ -24,7 +24,7 @@
namespace anyrpc
{

-bool MessagePackRpcHandler(MethodManager* manager, char* request, std::size_t length, Stream &response);
+ANYRPC_API bool MessagePackRpcHandler(MethodManager* manager, char* request, std::size_t length, Stream &response);

////////////////////////////////////////////////////////////////////////////////

diff --git a/include/anyrpc/xml/xmlserver.h b/include/anyrpc/xml/xmlserver.h
index 5350ca5..fe0ed23 100644
--- a/include/anyrpc/xml/xmlserver.h
+++ b/include/anyrpc/xml/xmlserver.h
@@ -24,7 +24,7 @@
namespace anyrpc
{

-bool XmlRpcHandler(MethodManager* manager, char* request, std::size_t length, Stream &response);
+ANYRPC_API bool XmlRpcHandler(MethodManager* manager, char* request, std::size_t length, Stream &response);

////////////////////////////////////////////////////////////////////////////////

--
2.36.1.windows.1

44 changes: 44 additions & 0 deletions recipes/anyrpc/all/patches/0003-use-conan-libs-1.0.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 2.8)

Project(AnyRPC CXX)

-# Some of the cmake find_package files are part of this distribution
-set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
-
# Read out version from "version" file
file(STRINGS "version" ANYRPC_VERSION_FILE)

@@ -91,7 +88,7 @@ CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/version.h.in"
"${PROJECT_SOURCE_DIR}/include/anyrpc/version.h" )

if (BUILD_WITH_LOG4CPLUS)
- find_package( Log4cplus )
- if (NOT LOG4CPLUS_FOUND)
+ find_package( log4cplus )
+ if (NOT log4cplus_FOUND)
# the find_package call for Log4cplus doesn't generate an error even if marked as required
message( FATAL_ERROR "LOG4CPLUS library required if BUILD_WITH_LOG4CPLUS on" )

--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -44,15 +44,15 @@ set(ANYRPC_HEADERS ${ANYRPC_HEADERS} ${ANYRPC_INTERNAL_HEADERS}

# Add the necessary external library references
if (BUILD_WITH_LOG4CPLUS)
- include_directories(${LOG4CPLUS_INCLUDE_DIRS})
+ set( LOG4CPLUS_TARGET "log4cplus::log4cplus" )
add_definitions( -DBUILD_WITH_LOG4CPLUS )
else ()
- set( LOG4CPLUS_LIBRARIES "" )
+ set( LOG4CPLUS_TARGET "" )
endif ()

# Create the libraries with these header and source files
add_library( anyrpc ${ANYRPC_LIB_TYPE} ${ANYRPC_SOURCES} ${ANYRPC_HEADERS} )
-target_link_libraries( anyrpc ${ASAN_LIBRARY} ${LOG4CPLUS_LIBRARIES})
+target_link_libraries( anyrpc ${ASAN_LIBRARY} ${LOG4CPLUS_TARGET})

# Need the winsock library for Windows
if (WIN32)
12 changes: 12 additions & 0 deletions recipes/anyrpc/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.8)

project(test_anyrpc CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
fdgStilla marked this conversation as resolved.
Show resolved Hide resolved

find_package(anyrpc REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_anyrpc.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE anyrpc::anyrpc)
fdgStilla marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 26 additions & 0 deletions recipes/anyrpc/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestAnyRpcConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_anyrpc")
self.run(bin_path, env="conanrun")
12 changes: 12 additions & 0 deletions recipes/anyrpc/all/test_package/test_anyrpc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <cstdlib>
#include <iostream>

#include "anyrpc/anyrpc.h"

int main(void)
{
anyrpc::JsonHttpServer server;
std::cout << "Success!" << std::endl;
fdgStilla marked this conversation as resolved.
Show resolved Hide resolved

return EXIT_SUCCESS;
}
15 changes: 15 additions & 0 deletions recipes/anyrpc/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.8)

project(test_anyrpc CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(anyrpc REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_anyrpc.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE anyrpc::anyrpc)
18 changes: 18 additions & 0 deletions recipes/anyrpc/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


class TestAnyRpcV1Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "test_anyrpc")
self.run(bin_path, run_environment=True)
3 changes: 3 additions & 0 deletions recipes/anyrpc/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.2":
folder: all