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

feat(protobuf): Add an option to remove RTTI from binaries #4682

Merged
merged 4 commits into from Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions recipes/protobuf/all/conandata.yml
Expand Up @@ -11,6 +11,9 @@ sources:
3.13.0:
sha256: 9b4ee22c250fe31b16f1a24d61467e40780a3fbb9b91c3b65be2a376ed913a1a
url: https://github.com/protocolbuffers/protobuf/archive/v3.13.0.tar.gz
3.15.5:
sha256: bc3dbf1f09dba1b2eb3f2f70352ee97b9049066c9040ce0c9b67fb3294e91e4b
url: https://github.com/protocolbuffers/protobuf/archive/v3.15.5.tar.gz
patches:
3.12.4:
- patch_file: "patches/upstream-pr-7761-cmake-regex-fix.patch"
Expand Down
31 changes: 27 additions & 4 deletions recipes/protobuf/all/conanfile.py
@@ -1,5 +1,4 @@
import os
import glob
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conans.tools import Version
Expand All @@ -17,8 +16,20 @@ class ProtobufConan(ConanFile):
generators = "cmake"
short_paths = True
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "with_zlib": [True, False], "fPIC": [True, False], "lite": [True, False]}
default_options = {"with_zlib": False, "shared": False, "fPIC": True, "lite": False}
options = {
"fPIC": [True, False],
"lite": [True, False],
"shared": [True, False],
"with_rtti": [True, False],
"with_zlib": [True, False]
}
default_options = {
"fPIC": True,
"lite": False,
"shared": False,
"with_rtti": True,
"with_zlib": False
}

_cmake = None

Expand All @@ -34,15 +45,20 @@ def _build_subfolder(self):
def _is_clang_x86(self):
return self.settings.compiler == "clang" and self.settings.arch == "x86"

@property
def _can_disable_rtti(self):
return tools.Version(self.version) >= "3.15.4"

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_folder = self.name + "-" + self.version
os.rename(extracted_folder, self._source_subfolder)


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

def configure(self):
if self.options.shared:
Expand All @@ -58,6 +74,11 @@ def configure(self):
if Version(self.settings.compiler.version) < "14":
raise ConanInvalidConfiguration("On Windows Protobuf can only be built with "
"Visual Studio 2015 or higher.")

if self.settings.compiler == "clang":
if tools.Version(self.version) >= "3.15.4" and tools.Version(self.settings.compiler.version) < "4":
raise ConanInvalidConfiguration("protobuf {} doesn't support clang < 4".format(self.version))

def requirements(self):
if self.options.with_zlib:
self.requires("zlib/1.2.11")
Expand All @@ -74,6 +95,8 @@ def _configure_cmake(self):
self._cmake.definitions["protobuf_BUILD_TESTS"] = False
self._cmake.definitions["protobuf_BUILD_PROTOC_BINARIES"] = True
self._cmake.definitions["protobuf_BUILD_LIBPROTOC"] = True
if self._can_disable_rtti:
self._cmake.definitions["protobuf_DISABLE_RTTI"] = not self.options.with_rtti
if self.settings.compiler == "Visual Studio":
self._cmake.definitions["protobuf_MSVC_STATIC_RUNTIME"] = "MT" in str(self.settings.compiler.runtime)
self._cmake.configure(build_folder=self._build_subfolder)
Expand Down
2 changes: 2 additions & 0 deletions recipes/protobuf/config.yml
Expand Up @@ -7,3 +7,5 @@ versions:
folder: all
3.13.0:
folder: all
3.15.5:
folder: all