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

grpc: more conan v2 stuff + bump zlib #13817

Merged
merged 4 commits into from
Oct 28, 2022
Merged
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
69 changes: 36 additions & 33 deletions recipes/grpc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.microsoft import visual, is_msvc
from conan.tools.build import cross_building, valid_min_cppstd, check_min_cppstd
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, rmdir, rename, replace_in_file
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rename, replace_in_file, rmdir
from conan.tools.microsoft import check_min_vs, is_msvc
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration
from conans import CMake
import os
import shutil
Expand Down Expand Up @@ -72,8 +72,8 @@ def _cxxstd_required(self):
return 14 if Version(self.version) >= "1.47" else 11

def export_sources(self):
self.copy("CMakeLists.txt")
self.copy(os.path.join("cmake", self._grpc_plugin_template))
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
copy(self, f"cmake/{self._grpc_plugin_template}", self.recipe_folder, self.export_sources_folder)
export_conandata_patches(self)

def config_options(self):
Expand All @@ -82,11 +82,17 @@ def config_options(self):

def configure(self):
if self.options.shared:
del self.options.fPIC
try:
del self.options.fPIC
except Exception:
pass
self.options["protobuf"].shared = True
self.options["googleapis"].shared = True
self.options["grpc-proto"].shared = True

def layout(self):
pass

def requirements(self):
if is_msvc(self) and Version(self.version) < "1.47":
self.requires("abseil/20211102.0")
Expand All @@ -95,35 +101,32 @@ def requirements(self):
self.requires("c-ares/1.18.1")
self.requires("openssl/1.1.1q")
self.requires("re2/20220601")
self.requires("zlib/1.2.12")
self.requires("zlib/1.2.13")
self.requires("protobuf/3.21.4")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When cross compiling, shoulnd't the protoc binaries only be built for the host platform and not the target platform?

self.options["protobuf"].with_protoc_binaries = False

However, this will only work if protobuf recipe is updated fjp@cc59b53

Copy link
Contributor Author

@SpaceIm SpaceIm Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't matter for grpc recipe, so there is no reason to force this option in grpc recipe itself.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your quick response.

Sure, it can also be set in a profile or from the command line. But my point is that there seems to be an issue when cross building grpc. Cross-build from 'Linux:x86_64' to 'Linux:armv7hf' using -b missing I get build errors for protobuf:

...
usr/include/c++/v1/cstdlib:123:9: error: target of using declaration conflicts with declaration already in scope
using ::abs _LIBCPP_USING_IF_EXISTS;
...
protobuf/3.20.0: ERROR: Package '4c113c49faf2c4384d5b6d4b12ce3565050d800e' build failed
protobuf/3.20.0: WARN: Build folder /root/.conan/data/protobuf/3.20.0/_/_/build/4c113c49faf2c4384d5b6d4b12ce3565050d800e
root@0ec9a559fe37:~# conan or in build() method, line 203

        ConanException: Error 2 while executing cmake --build '/root/.conan/data/protobuf/3.20.0/_/_/build/4c113c49faf2c4384d5b6d4b12ce3565050d800e/build_subfolder' '--' '-j8'

Are there any build jobs on conan-center-index that run cross compilation? I have just seen #13817 (comment) which doesn't seem to use different host and build profiles, but please correct me if I am wrong.

Copy link
Contributor Author

@SpaceIm SpaceIm Nov 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In c3i, there is one cross-build with 2 profiles: from macOS Intel to macOS M1.

From what I see from your log, it may be a protobuf recipe issue, when target is Linux armv7hf.

self.requires("googleapis/cci.20220711")
self.requires("grpc-proto/cci.20220627")

def package_id(self):
del self.info.options.secure
self.info.requires["protobuf"].full_package_mode()

def validate(self):
if is_msvc(self):
if self.settings.compiler == "Visual Studio":
vs_ide_version = self.settings.compiler.version
else:
vs_ide_version = visual.msvc_version_to_vs_ide_version(self.settings.compiler.version)
if Version(vs_ide_version) < "14":
raise ConanInvalidConfiguration("gRPC can only be built with Visual Studio 2015 or higher.")

if self.options.shared:
raise ConanInvalidConfiguration("gRPC shared not supported yet with Visual Studio")

if Version(self.version) >= "1.47" and self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "6":
check_min_vs(self, "190")
if is_msvc(self) and self.info.options.shared:
raise ConanInvalidConfiguration(f"{self.ref} shared not supported by Visual Studio")

if Version(self.version) >= "1.47" and self.info.settings.compiler == "gcc" and Version(self.info.settings.compiler.version) < "6":
raise ConanInvalidConfiguration("GCC older than 6 is not supported")

if self.settings.compiler.get_safe("cppstd"):
if self.info.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._cxxstd_required)

if self.options.shared and (not self.options["protobuf"].shared or not self.options["googleapis"].shared or not self.options["grpc-proto"].shared):
raise ConanInvalidConfiguration("If built as shared, protobuf, googleapis and grpc-proto must be shared as well. Please, use `protobuf:shared=True` and `googleapis:shared=True` and `grpc-proto:shared=True`")

def package_id(self):
del self.info.options.secure
self.info.requires["protobuf"].full_package_mode()
if self.info.options.shared and \
(not self.dependencies["protobuf"].options.shared or not self.dependencies["googleapis"].options.shared or not self.dependencies["grpc-proto"].options.shared):
raise ConanInvalidConfiguration(
"If built as shared, protobuf, googleapis and grpc-proto must be shared as well. "
"Please, use `protobuf:shared=True` and `googleapis:shared=True` and `grpc-proto:shared=True`",
)

def build_requirements(self):
if hasattr(self, "settings_build"):
Expand Down Expand Up @@ -217,7 +220,7 @@ def build(self):
cmake.build()

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

Expand Down Expand Up @@ -266,15 +269,14 @@ def _grpc_plugins(self):
}

def _create_executable_module_file(self, target, executable):
module_abs_path = os.path.join(self.package_folder, self._module_path)

# Copy our CMake module template file to package folder
self.copy(self._grpc_plugin_template, dst=self._module_path,
src=os.path.join(self.source_folder, "cmake"))
copy(self, self._grpc_plugin_template, src=os.path.join(self.source_folder, "cmake"), dst=module_abs_path)

# Rename it
dst_file = os.path.join(self.package_folder, self._module_path,
"{}.cmake".format(executable))
rename(self, os.path.join(self.package_folder, self._module_path, self._grpc_plugin_template),
dst_file)
dst_file = os.path.join(module_abs_path, f"{executable}.cmake")
rename(self, os.path.join(module_abs_path, self._grpc_plugin_template), dst_file)

# Replace placeholders
replace_in_file(self, dst_file, "@target_name@", target)
Expand Down Expand Up @@ -402,6 +404,7 @@ def corefoundation():

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "gRPC")
self.cpp_info.resdirs = ["res"]
ssl_roots_file_path = os.path.join(self.package_folder, "res", "grpc", "roots.pem")
self.runenv_info.define_path("GRPC_DEFAULT_SSL_ROOTS_FILE_PATH", ssl_roots_file_path)
self.env_info.GRPC_DEFAULT_SSL_ROOTS_FILE_PATH = ssl_roots_file_path # remove in conan v2?
Expand Down