Skip to content
This repository has been archived by the owner on May 2, 2021. It is now read-only.

Enable cross building for Android and iOS #51

Closed
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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ project(cmake_wrapper)
include(conanbuildinfo.cmake)
conan_basic_setup()

if(NOT Protobuf_PROTOC_EXECUTABLE)
message(FATAL_ERROR "Expected Conan to provide: 'Protobuf_PROTOC_EXECUTABLE'")
endif()
# GRPC will find the wrong protoc when cross building.
# Override it here.
set(_gRPC_PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})

add_subdirectory("source_subfolder")
4 changes: 4 additions & 0 deletions conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ sources:
"1.34.1":
url: https://github.com/grpc/grpc/archive/v1.34.1.zip
sha256: 0884778ef7866c2aaa9c06abd820f2ba2b514edcc5ec21bda74f3b7253036f9d
patches:
"1.34.1":
- patch_file: "patches/upstream-pr-24959-only-openssl-engine-when-supported.patch"
base_path: "source_subfolder"
26 changes: 18 additions & 8 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class grpcConan(ConanFile):
url = "https://github.com/inexorgame/conan-grpc"
homepage = "https://github.com/grpc/grpc"
license = "Apache-2.0"
exports_sources = ["CMakeLists.txt"]
exports_sources = ["CMakeLists.txt", "patches/*"]
generators = "cmake", "cmake_find_package_multi"
short_paths = True

Expand Down Expand Up @@ -54,6 +54,13 @@ class grpcConan(ConanFile):
"re2/20201101"
)

def build_requirements(self):
self.build_requires("protobuf/3.13.0")

# When cross building the recipe depends on itself to provide the plugins
if tools.cross_building(self.settings):
self.build_requires("{}/{}@{}/{}".format(self.name, self.version, self.user, self.channel))

def configure(self):
if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio":
del self.options.fPIC
Expand Down Expand Up @@ -98,13 +105,13 @@ def _configure_cmake(self):
cmake.definitions["gRPC_PROTOBUF_PROVIDER"] = "package"
cmake.definitions["gRPC_RE2_PROVIDER"] = "package"

cmake.definitions["gRPC_BUILD_GRPC_CPP_PLUGIN"] = self.options.build_cpp_plugin
cmake.definitions["gRPC_BUILD_GRPC_CSHARP_PLUGIN"] = self.options.build_csharp_plugin
cmake.definitions["gRPC_BUILD_GRPC_NODE_PLUGIN"] = self.options.build_node_plugin
cmake.definitions["gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN"] = self.options.build_objective_c_plugin
cmake.definitions["gRPC_BUILD_GRPC_PHP_PLUGIN"] = self.options.build_php_plugin
cmake.definitions["gRPC_BUILD_GRPC_PYTHON_PLUGIN"] = self.options.build_python_plugin
cmake.definitions["gRPC_BUILD_GRPC_RUBY_PLUGIN"] = self.options.build_ruby_plugin
cmake.definitions["gRPC_BUILD_GRPC_CPP_PLUGIN"] = self.options.build_cpp_plugin and not tools.cross_building(self.settings)
cmake.definitions["gRPC_BUILD_GRPC_CSHARP_PLUGIN"] = self.options.build_csharp_plugin and not tools.cross_building(self.settings)
cmake.definitions["gRPC_BUILD_GRPC_NODE_PLUGIN"] = self.options.build_node_plugin and not tools.cross_building(self.settings)
cmake.definitions["gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN"] = self.options.build_objective_c_plugin and not tools.cross_building(self.settings)
cmake.definitions["gRPC_BUILD_GRPC_PHP_PLUGIN"] = self.options.build_php_plugin and not tools.cross_building(self.settings)
cmake.definitions["gRPC_BUILD_GRPC_PYTHON_PLUGIN"] = self.options.build_python_plugin and not tools.cross_building(self.settings)
cmake.definitions["gRPC_BUILD_GRPC_RUBY_PLUGIN"] = self.options.build_ruby_plugin and not tools.cross_building(self.settings)

# see https://github.com/inexorgame/conan-grpc/issues/39
if self.settings.os == "Windows":
Expand All @@ -117,6 +124,9 @@ def _configure_cmake(self):
return cmake

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

cmake = self._configure_cmake()
cmake.build()

Expand Down
51 changes: 51 additions & 0 deletions patches/upstream-pr-24959-only-openssl-engine-when-supported.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
commit e3918f40fb45dc569d8c068c179dd086b89bc938
Author: jiangtaoli2016 <jiangtao@google.com>
Date: Thu Dec 10 08:51:25 2020 -0800

Only enable OpenSSL Engine when compiler supports it

diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc
index ad9f5704bf..c6a8580021 100644
--- a/src/core/tsi/ssl_transport_security.cc
+++ b/src/core/tsi/ssl_transport_security.cc
@@ -141,7 +141,7 @@ struct tsi_ssl_frame_protector {
static gpr_once g_init_openssl_once = GPR_ONCE_INIT;
static int g_ssl_ctx_ex_factory_index = -1;
static const unsigned char kSslSessionIdContext[] = {'g', 'r', 'p', 'c'};
-#ifndef OPENSSL_IS_BORINGSSL
+#if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE)
static const char kSslEnginePrefix[] = "engine:";
#endif

@@ -592,7 +592,7 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX* context,
return result;
}

-#ifndef OPENSSL_IS_BORINGSSL
+#if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE)
static tsi_result ssl_ctx_use_engine_private_key(SSL_CTX* context,
const char* pem_key,
size_t pem_key_size) {
@@ -665,7 +665,7 @@ static tsi_result ssl_ctx_use_engine_private_key(SSL_CTX* context,
if (engine_name != nullptr) gpr_free(engine_name);
return result;
}
-#endif /* OPENSSL_IS_BORINGSSL */
+#endif /* !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE) */

static tsi_result ssl_ctx_use_pem_private_key(SSL_CTX* context,
const char* pem_key,
@@ -696,11 +696,11 @@ static tsi_result ssl_ctx_use_pem_private_key(SSL_CTX* context,
static tsi_result ssl_ctx_use_private_key(SSL_CTX* context, const char* pem_key,
size_t pem_key_size) {
// BoringSSL does not have ENGINE support
-#ifndef OPENSSL_IS_BORINGSSL
+#if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE)
if (strncmp(pem_key, kSslEnginePrefix, strlen(kSslEnginePrefix)) == 0) {
return ssl_ctx_use_engine_private_key(context, pem_key, pem_key_size);
} else
-#endif /* OPENSSL_IS_BORINGSSL */
+#endif /* !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE) */
{
return ssl_ctx_use_pem_private_key(context, pem_key, pem_key_size);
}
15 changes: 9 additions & 6 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ endif()
set(CMAKE_CXX_STANDARD 11)

# Find Protobuf installation

set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${protobuf_VERSION}")
if(NOT Protobuf_PROTOC_EXECUTABLE)
message(FATAL_ERROR "Expected Conan to provide: 'Protobuf_PROTOC_EXECUTABLE'")
endif()

set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
# set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
find_program(_PROTOBUF_PROTOC protoc ${CONAN_BIN_DIRS_PROTOBUF} NO_DEFAULT_PATH)

# Find gRPC installation
find_package(gRPC CONFIG REQUIRED)
# find_package(protoc CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")

set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
# Find GRPC_CPP_PLUGIN_EXECUTABLE
find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin REQUIRED)
if(NOT _GRPC_CPP_PLUGIN_EXECUTABLE)
message(FATAL_ERROR "${_GRPC_CPP_PLUGIN_EXECUTABLE} but required!")
endif()

# Proto file
get_filename_component(hw_proto "helloworld.proto" ABSOLUTE)
Expand All @@ -37,7 +40,7 @@ set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.cc")
set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.h")
add_custom_command(
OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${hw_proto_path}"
Expand Down
5 changes: 5 additions & 0 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build_requirements(self):
self.build_requires("protobuf/3.13.0")
if tools.cross_building(self.settings):
self.build_requires(str(self.requires['grpc']))

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