Compare commits

...

35 Commits

Author SHA1 Message Date
Bronek Kozicki
e3d5be39ed Merge branch 'develop' into Bronek/upgrades_rolled_up 2025-08-04 11:33:20 +01:00
Bronek Kozicki
482315fc42 Merge branch 'develop' into Bronek/upgrades_rolled_up 2025-07-29 18:04:25 +01:00
Bronek Kozicki
4e3810e0b2 Revert "Set 24 jobs for windows"
This reverts commit ad184d9ef8.
2025-07-26 21:34:51 +01:00
Bronek Kozicki
ed2fa19997 Disable CONAN_URL 2025-07-26 21:33:28 +01:00
Bronek Kozicki
ad184d9ef8 Set 24 jobs for windows 2025-07-26 17:14:38 +01:00
Bronek Kozicki
597de4dbb0 Reduce number of jobs for windows build again 2025-07-26 14:46:14 +01:00
Bronek Kozicki
804614e2a0 Suppress warning "operands are different enum types" in grpc 2025-07-26 14:45:05 +01:00
Bronek Kozicki
f8a9886ece Disable verbosity, reduce number of jobs for windows build 2025-07-26 09:56:35 +01:00
Bronek Kozicki
de54c7ead3 Change dependencies conan options to explicitly apply to xrpl only 2025-07-25 17:08:31 +01:00
Bronek Kozicki
3a94f22da7 Merge branch 'develop' into Bronek/upgrades_rolled_up 2025-07-25 17:02:04 +01:00
Bronek Kozicki
9169b58c08 Switch Windows build to dynamic, for grpc_cpp_plugin 2025-07-25 15:03:57 +01:00
Bronek Kozicki
3c3bc8fa21 Remove BOOST_ASIO_DISABLE_CONCEPTS from default profile 2025-07-25 12:54:20 +01:00
Bronek Kozicki
ab857068ed Merge branch 'develop' into Bronek/upgrades_rolled_up 2025-07-25 09:16:49 +01:00
Bronek Kozicki
7f60624ccd Switch to clang-16 2025-07-24 16:49:52 +01:00
Bronek Kozicki
759d6a3f2b Switch instrumentation build to clang-17 2025-07-24 15:34:53 +01:00
Bronek Kozicki
6cb1ae6666 Fix grpc error: No target 'grpc_cpp_plugin' 2025-07-24 15:29:32 +01:00
Bronek Kozicki
47875cee52 Disable grpc plugins 2025-07-24 15:22:40 +01:00
Bronek Kozicki
8b50263c2b Merge branch 'Bronek/external_protobuf' into Bronek/upgrades_rolled_up 2025-07-24 15:11:32 +01:00
Bronek Kozicki
64233c9f47 Merge branch 'develop' into Bronek/upgrades_rolled_up 2025-07-24 14:43:11 +01:00
Bronek Kozicki
2ea247bb9c Add workarounds for instrumentation step 2025-07-24 12:44:39 +01:00
Bronek Kozicki
bd8242d805 Add conan export to workflows 2025-07-24 12:22:08 +01:00
Bronek Kozicki
1043388407 Document new external/protobuf 2025-07-24 12:21:11 +01:00
Bronek Kozicki
6ba0ec479b Add external/protobuf
Only needed until this PR is merged
https://github.com/conan-io/conan-center-index/pull/27982
2025-07-24 12:21:05 +01:00
Bronek Kozicki
b527194743 Fix link error due to duplicate __cxxabiv1::__cxa_allocate_exception 2025-07-24 12:06:59 +01:00
Bronek Kozicki
615e380fab Updates Conan dependencies: Boost #5264 2025-07-24 09:40:55 +01:00
Bronek Kozicki
901654a966 refactor: Update rocksdb #5568 2025-07-24 09:39:42 +01:00
Bronek Kozicki
8ad9f4b768 Updates protobuf and grpc #5589 2025-07-24 09:37:35 +01:00
Bronek Kozicki
dd68fe0e2c Add external/protobuf
Only needed until this PR is merged
https://github.com/conan-io/conan-center-index/pull/27982
2025-07-24 09:33:35 +01:00
Bart Thomee
95a8d84f1f Temporarily compile using Clang 17 2025-07-22 10:44:19 -04:00
Bart Thomee
5a2004332b Temporarily compile using Clang 17 2025-07-22 10:32:26 -04:00
Bart Thomee
9a56a5b788 Temporarily disable ripple remote 2025-07-21 17:45:16 -04:00
Bart Thomee
605c8bd377 Temporarily disable ripple remote 2025-07-21 17:10:19 -04:00
Bart Thomee
900131d09f Temporarily disable ripple remote 2025-07-21 16:36:24 -04:00
Bart Thomee
01bdb87b39 Explicitly specify version of abseil to use 2025-07-21 16:13:24 -04:00
Bart Thomee
274a7303ff Updates protobuf and grpc 2025-07-21 15:14:56 -04:00
17 changed files with 689 additions and 13 deletions

View File

@@ -11,6 +11,7 @@ runs:
run: |
conan export --version 1.1.10 external/snappy
conan export --version 4.0.3 external/soci
conan export --version 6.30.1 external/protobuf
- name: add Ripple Conan remote
if: env.CONAN_URL != ''
shell: bash
@@ -22,7 +23,7 @@ runs:
conan remote add --index 0 ripple "${CONAN_URL}"
echo "Added conan remote ripple at ${CONAN_URL}"
- name: try to authenticate to Ripple Conan remote
if: env.CONAN_LOGIN_USERNAME_RIPPLE != '' && env.CONAN_PASSWORD_RIPPLE != ''
if: env.CONAN_URL != '' && env.CONAN_LOGIN_USERNAME_RIPPLE != '' && env.CONAN_PASSWORD_RIPPLE != ''
id: remote
shell: bash
run: |

View File

@@ -18,7 +18,7 @@ concurrency:
# This part of Conan configuration is specific to this workflow only; we do not want
# to pollute conan/profiles directory with settings which might not work for others
env:
CONAN_URL: http://18.143.149.228:8081/artifactory/api/conan/dev
# CONAN_URL: http://18.143.149.228:8081/artifactory/api/conan/dev
CONAN_LOGIN_USERNAME_RIPPLE: ${{ secrets.CONAN_USERNAME }}
CONAN_PASSWORD_RIPPLE: ${{ secrets.CONAN_TOKEN }}
CONAN_GLOBAL_CONF: |
@@ -95,6 +95,7 @@ jobs:
run: |
conan export --version 1.1.10 external/snappy
conan export --version 4.0.3 external/soci
conan export --version 6.30.1 external/protobuf
- name: add Ripple Conan remote
if: env.CONAN_URL != ''
shell: bash

View File

@@ -19,7 +19,7 @@ concurrency:
# This part of Conan configuration is specific to this workflow only; we do not want
# to pollute conan/profiles directory with settings which might not work for others
env:
CONAN_URL: http://18.143.149.228:8081/artifactory/api/conan/dev
# CONAN_URL: http://18.143.149.228:8081/artifactory/api/conan/dev
CONAN_LOGIN_USERNAME_RIPPLE: ${{ secrets.CONAN_USERNAME }}
CONAN_PASSWORD_RIPPLE: ${{ secrets.CONAN_TOKEN }}
CONAN_GLOBAL_CONF: |

View File

@@ -21,15 +21,13 @@ concurrency:
# This part of Conan configuration is specific to this workflow only; we do not want
# to pollute conan/profiles directory with settings which might not work for others
env:
CONAN_URL: http://18.143.149.228:8081/artifactory/api/conan/dev
# CONAN_URL: http://18.143.149.228:8081/artifactory/api/conan/dev
CONAN_LOGIN_USERNAME_RIPPLE: ${{ secrets.CONAN_USERNAME }}
CONAN_PASSWORD_RIPPLE: ${{ secrets.CONAN_TOKEN }}
CONAN_GLOBAL_CONF: |
core.download:parallel={{os.cpu_count()}}
core.upload:parallel={{os.cpu_count()}}
tools.build:jobs=24
tools.build:verbosity=verbose
tools.compilation:verbosity=verbose
tools.build:jobs=6
jobs:
@@ -90,6 +88,7 @@ jobs:
run: |
conan export --version 1.1.10 external/snappy
conan export --version 4.0.3 external/soci
conan export --version 6.30.1 external/protobuf
- name: add Ripple Conan remote
if: env.CONAN_URL != ''
shell: bash

View File

@@ -179,6 +179,14 @@ It patches their CMake to correctly import its dependencies.
conan export --version 4.0.3 external/soci
```
Export our [Conan recipe for Protobuf](./external/rocksdb).
It fixes compilation errors with clang-16 and Visual Studio.
```
# Conan 2.x
conan export --version 6.30.1 external/protobuf
```
### Build and Test
1. Create a build directory and move into it.

View File

@@ -70,8 +70,8 @@ if (MSVC)
-Zc:forScope
>
# static runtime
$<$<CONFIG:Debug>:-MTd>
$<$<NOT:$<CONFIG:Debug>>:-MT>
$<$<CONFIG:Debug>:-MDd>
$<$<NOT:$<CONFIG:Debug>>:-MD>
$<$<BOOL:${werr}>:-WX>
)
target_compile_definitions (common

View File

@@ -14,7 +14,7 @@ compiler={{compiler}}
compiler.version={{ compiler_version }}
compiler.cppstd=20
{% if os == "Windows" %}
compiler.runtime=static
compiler.runtime=dynamic
{% else %}
compiler.libcxx={{detect_api.detect_libcxx(compiler, version, compiler_exe)}}
{% endif %}
@@ -29,6 +29,10 @@ tools.build:cxxflags=['-Wno-missing-template-arg-list-after-template-kw']
{% if compiler == "gcc" and compiler_version < 13 %}
tools.build:cxxflags=['-Wno-restrict']
{% endif %}
{% if compiler == "msvc" %}
tools.build:cxxflags=['-wd5287']
tools.build:cflags=['-wd5287']
{% endif %}
[tool_requires]
!cmake/*: cmake/[>=3 <4]

View File

@@ -24,7 +24,7 @@ class Xrpl(ConanFile):
}
requires = [
'grpc/1.50.1',
'grpc/1.72.0',
'libarchive/3.8.1',
'nudb/2.0.9',
'openssl/1.1.1w',
@@ -37,7 +37,7 @@ class Xrpl(ConanFile):
]
tool_requires = [
'protobuf/3.21.12',
'protobuf/6.30.1',
]
default_options = {
@@ -98,6 +98,14 @@ class Xrpl(ConanFile):
self.version = match.group(1)
def configure(self):
# Disable grpc plugins, we do not use any
self.options["grpc"].csharp_plugin = False
self.options["grpc"].node_plugin = False
self.options["grpc"].objective_c_plugin = False
self.options["grpc"].php_plugin = False
self.options["grpc"].python_plugin = False
self.options["grpc"].ruby_plugin = False
self.options["grpc"].otel_plugin = False
if self.settings.compiler == 'apple-clang':
self.options['boost'].visibility = 'global'
@@ -107,7 +115,7 @@ class Xrpl(ConanFile):
self.requires('boost/1.86.0', force=True, **transitive_headers_opt)
self.requires('date/3.0.4', **transitive_headers_opt)
self.requires('lz4/1.10.0', force=True)
self.requires('protobuf/3.21.12', force=True)
self.requires('protobuf/6.30.1', force=True)
self.requires('sqlite3/3.49.1', force=True)
if self.options.jemalloc:
self.requires('jemalloc/5.3.0')

54
external/protobuf/conandata.yml vendored Normal file
View File

@@ -0,0 +1,54 @@
sources:
"6.30.1":
url: "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v6.30.1.tar.gz"
sha256: "c97cc064278ef2b8c4da66c1f85613642ecbd5a0c4217c0defdf7ad1b3de9fa5"
patches:
"6.30.1":
- patch_file: "patches/protobuf-6.30.1-change-empty-string.patch"
patch_description: "Change how we decide which empty string implementation to use"
patch_type: "backport"
patch_source: "https://github.com/protocolbuffers/protobuf/issues/20645"
- patch_file: "patches/protobuf-6.30.1-disable-fixed-string-MSVC.patch"
patch_description: "Disable the optimization for fixed_address_empty_string for MSVC"
patch_type: "backport"
patch_source: "https://github.com/protocolbuffers/protobuf/issues/21957"
absl_deps:
# reference: https://github.com/protocolbuffers/protobuf/blob/main/cmake/abseil-cpp.cmake
"6.30.1":
- absl_absl_check
- absl_absl_log
- absl_algorithm
- absl_base
- absl_bind_front
- absl_bits
- absl_btree
- absl_cleanup
- absl_cord
- absl_core_headers
- absl_debugging
- absl_die_if_null
- absl_dynamic_annotations
- absl_flags
- absl_flat_hash_map
- absl_flat_hash_set
- absl_function_ref
- absl_hash
- absl_layout
- absl_log_initialize
- absl_log_globals
- absl_log_severity
- absl_memory
- absl_node_hash_map
- absl_node_hash_set
- absl_optional
- absl_random_distributions
- absl_random_random
- absl_span
- absl_status
- absl_statusor
- absl_strings
- absl_synchronization
- absl_time
- absl_type_traits
- absl_utility
- absl_variant

330
external/protobuf/conanfile.py vendored Normal file
View File

@@ -0,0 +1,330 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, rename, get, apply_conandata_patches, export_conandata_patches, replace_in_file, rmdir, rm, save
from conan.tools.microsoft import check_min_vs, msvc_runtime_flag, is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version
import os
required_conan_version = ">=1.53"
class ProtobufConan(ConanFile):
name = "protobuf"
description = "Protocol Buffers - Google's data interchange format"
topics = ("protocol-buffers", "protocol-compiler", "serialization", "rpc", "protocol-compiler")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/protocolbuffers/protobuf"
license = "BSD-3-Clause"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_zlib": [True, False],
"with_rtti": [True, False],
"lite": [True, False],
"upb": [True, False],
"debug_suffix": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_zlib": True,
"with_rtti": True,
"lite": False,
"upb": False,
"debug_suffix": True,
}
short_paths = True
@property
def _is_clang_cl(self):
return self.settings.compiler == "clang" and self.settings.os == "Windows"
@property
def _is_clang_x86(self):
return self.settings.compiler == "clang" and self.settings.arch == "x86"
@property
def _protobuf_release(self):
current_ver = Version(self.version)
return Version(f"{current_ver.minor}.{current_ver.patch}")
def export_sources(self):
export_conandata_patches(self)
copy(self, "protobuf-conan-protoc-target.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
if self._protobuf_release < "27.0":
self.options.rm_safe("upb")
def layout(self):
cmake_layout(self, src_folder="src")
def requirements(self):
if self.options.with_zlib:
self.requires("zlib/[>=1.2.11 <2]")
if self._protobuf_release >= "22.0":
self.requires("abseil/[>=20230802.1 <=20250127.0]", transitive_headers=True)
@property
def _compilers_minimum_version(self):
return {
"gcc": "6",
"clang": "5",
"apple-clang": "10",
"Visual Studio": "15",
"msvc": "191",
}
def validate(self):
if self.options.shared and is_msvc_static_runtime(self):
raise ConanInvalidConfiguration("Protobuf can't be built with shared + MT(d) runtimes")
if is_msvc(self) and self._protobuf_release >= "22" and self.options.shared and \
not self.dependencies["abseil"].options.shared:
raise ConanInvalidConfiguration("When building protobuf as a shared library on Windows, "
"abseil needs to be a shared library too")
if self._protobuf_release >= "30.1":
check_min_cppstd(self, 17)
elif self._protobuf_release >= "22.0":
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 14)
else:
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), None)
compiler_version = Version(self.settings.compiler.version)
if minimum_version and compiler_version < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++14, which your compiler does not support.",
)
check_min_vs(self, "190")
if self.settings.compiler == "clang":
if Version(self.settings.compiler.version) < "4":
raise ConanInvalidConfiguration(f"{self.ref} doesn't support clang < 4")
if "abseil" in self.dependencies.host:
abseil_cppstd = self.dependencies.host['abseil'].info.settings.compiler.cppstd
if abseil_cppstd != self.settings.compiler.cppstd:
raise ConanInvalidConfiguration(f"Protobuf and abseil must be built with the same compiler.cppstd setting")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def build_requirements(self):
if self._protobuf_release >= "30.1":
self.tool_requires("cmake/[>=3.16 <4]")
@property
def _cmake_install_base_path(self):
return os.path.join("lib", "cmake", "protobuf")
def generate(self):
tc = CMakeToolchain(self)
if self._protobuf_release >= "30.1":
tc.cache_variables["protobuf_LOCAL_DEPENDENCIES_ONLY"] = True
tc.cache_variables["CMAKE_INSTALL_CMAKEDIR"] = self._cmake_install_base_path.replace("\\", "/")
tc.cache_variables["protobuf_WITH_ZLIB"] = self.options.with_zlib
tc.cache_variables["protobuf_BUILD_TESTS"] = False
tc.cache_variables["protobuf_BUILD_PROTOC_BINARIES"] = self.settings.os != "tvOS"
if not self.options.debug_suffix:
tc.cache_variables["protobuf_DEBUG_POSTFIX"] = ""
tc.cache_variables["protobuf_BUILD_LIBPROTOC"] = self.settings.os != "tvOS"
tc.cache_variables["protobuf_DISABLE_RTTI"] = not self.options.with_rtti
tc.cache_variables["protobuf_BUILD_LIBUPB"] = self.options.get_safe("upb")
if self._protobuf_release >= "22.0":
tc.cache_variables["protobuf_ABSL_PROVIDER"] = "package"
if not self.settings.compiler.get_safe("cppstd") and self._protobuf_release >= "22.0":
tc.variables["CMAKE_CXX_STANDARD"] = 14
if is_msvc(self) or self._is_clang_cl:
runtime = self.settings.get_safe("compiler.runtime")
if runtime:
tc.cache_variables["protobuf_MSVC_STATIC_RUNTIME"] = runtime == "static"
if is_apple_os(self) and self.options.shared:
# Workaround against SIP on macOS for consumers while invoking protoc when protobuf lib is shared
tc.variables["CMAKE_INSTALL_RPATH"] = "@loader_path/../lib"
if self.settings.os == "Linux":
# Use RPATH instead of RUNPATH to help with specific case
# in the grpc recipe when grpc_cpp_plugin is run with protoc
# in the same build. RPATH ensures that the rpath in the binary
# is respected for transitive dependencies too
project_include = os.path.join(self.generators_folder, "protobuf_project_include.cmake")
save(self, project_include, "add_link_options(-Wl,--disable-new-dtags)")
tc.variables["CMAKE_PROJECT_INCLUDE"] = project_include
# Note: conan2 only could be:
# tc.extra_exelinkflags.append("-Wl,--disable-new-dtags")
# tc.extra_sharedlinkflags.append("-Wl,--disable-new-dtags")
tc.generate()
deps = CMakeDeps(self)
deps.generate()
def _patch_sources(self):
apply_conandata_patches(self)
if self._protobuf_release < "22.0":
# In older versions of protobuf, this file defines the `protobuf_generate` function
protobuf_config_cmake = os.path.join(self.source_folder, "cmake", "protobuf-config.cmake.in")
replace_in_file(self, protobuf_config_cmake, "@_protobuf_FIND_ZLIB@", "")
replace_in_file(self, protobuf_config_cmake,
"include(\"${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake\")",
""
)
# Disable a potential warning in protobuf-module.cmake.in
# TODO: remove this patch? Is it really useful?
protobuf_module_cmake = os.path.join(self.source_folder, "cmake", "protobuf-module.cmake.in")
replace_in_file(self,
protobuf_module_cmake,
"if(DEFINED Protobuf_SRC_ROOT_FOLDER)",
"if(0)\nif(DEFINED Protobuf_SRC_ROOT_FOLDER)",
)
replace_in_file(self,
protobuf_module_cmake,
"# Define upper case versions of output variables",
"endif()",
)
def build(self):
self._patch_sources()
cmake = CMake(self)
cmake_root = "cmake" if Version(self.version) < "3.21" else None
cmake.configure(build_script_folder=cmake_root)
cmake.build()
def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
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", "utf8_range"))
if self._protobuf_release < "22.0":
rename(self, os.path.join(self.package_folder, self._cmake_install_base_path, "protobuf-config.cmake"),
os.path.join(self.package_folder, self._cmake_install_base_path, "protobuf-generate.cmake"))
cmake_config_folder = os.path.join(self.package_folder, self._cmake_install_base_path)
rm(self, "protobuf-config*.cmake", folder=cmake_config_folder)
rm(self, "protobuf-targets*.cmake", folder=cmake_config_folder)
copy(self, "protobuf-conan-protoc-target.cmake", src=self.source_folder, dst=cmake_config_folder)
if not self.options.lite:
rm(self, "libprotobuf-lite*", os.path.join(self.package_folder, "lib"))
rm(self, "libprotobuf-lite*", os.path.join(self.package_folder, "bin"))
def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_module_file_name", "Protobuf")
self.cpp_info.set_property("cmake_file_name", "protobuf")
self.cpp_info.set_property("pkg_config_name", "protobuf_full_package") # unofficial, but required to avoid side effects (libprotobuf component "steals" the default global pkg_config name)
build_modules = [
os.path.join(self._cmake_install_base_path, "protobuf-generate.cmake"),
os.path.join(self._cmake_install_base_path, "protobuf-module.cmake"),
os.path.join(self._cmake_install_base_path, "protobuf-options.cmake"),
os.path.join(self._cmake_install_base_path, "protobuf-conan-protoc-target.cmake"),
]
self.cpp_info.set_property("cmake_build_modules", build_modules)
lib_prefix = "lib" if (is_msvc(self) or self._is_clang_cl) else ""
lib_suffix = "d" if self.settings.build_type == "Debug" and self.options.debug_suffix else ""
if self._protobuf_release >= "22.0":
absl_deps = [f"abseil::{c}" for c in self.conan_data["absl_deps"][self.version]]
if self._protobuf_release >= "22.0" and (not self.options.shared or self.options.get_safe("upb")):
# utf8 libraries
# it's a private dependency and unconditionally built as a static library, should only
# be exposed when protobuf itself is static (or if upb is being built)
self.cpp_info.components["utf8_range"].set_property("cmake_target_name", "utf8_range::utf8_range")
self.cpp_info.components["utf8_validity"].set_property("cmake_target_name", "utf8_range::utf8_validity")
# https://github.com/protocolbuffers/protobuf/blob/0d815c5b74281f081c1ee4b431a4d5bbb1615c97/third_party/utf8_range/CMakeLists.txt#L24
if self._protobuf_release >= "30.1" and self.settings.os == "Windows":
self.cpp_info.components["utf8_range"].libs = ["libutf8_range"]
self.cpp_info.components["utf8_validity"].libs = ["libutf8_validity"]
else:
self.cpp_info.components["utf8_range"].libs = ["utf8_range"]
self.cpp_info.components["utf8_validity"].libs = ["utf8_validity"]
self.cpp_info.components["utf8_validity"].requires = ["abseil::absl_strings"]
if self.options.get_safe("upb"):
# upb libraries: note that these are unconditionally static
self.cpp_info.components["upb"].set_property("cmake_target_name", "protobuf::libupb")
self.cpp_info.components["upb"].libs = [lib_prefix + "upb" + lib_suffix]
self.cpp_info.components["upb"].requires = ["utf8_range"]
# libprotobuf
self.cpp_info.components["libprotobuf"].set_property("cmake_target_name", "protobuf::libprotobuf")
self.cpp_info.components["libprotobuf"].set_property("pkg_config_name", "protobuf")
self.cpp_info.components["libprotobuf"].builddirs.append(self._cmake_install_base_path)
self.cpp_info.components["libprotobuf"].libs = [lib_prefix + "protobuf" + lib_suffix]
if self.options.with_zlib:
self.cpp_info.components["libprotobuf"].requires = ["zlib::zlib"]
if self._protobuf_release >= "22.0":
self.cpp_info.components["libprotobuf"].requires.extend(absl_deps)
if not self.options.shared:
self.cpp_info.components["libprotobuf"].requires.extend(["utf8_validity"])
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["libprotobuf"].system_libs.extend(["m", "pthread"])
if self._is_clang_x86 or "arm" in str(self.settings.arch):
self.cpp_info.components["libprotobuf"].system_libs.append("atomic")
if self.settings.os == "Android":
self.cpp_info.components["libprotobuf"].system_libs.append("log")
if self.settings.os == "Windows":
if self.options.shared:
self.cpp_info.components["libprotobuf"].defines = ["PROTOBUF_USE_DLLS"]
# libprotoc
if self.settings.os != "tvOS":
self.cpp_info.components["libprotoc"].set_property("cmake_target_name", "protobuf::libprotoc")
self.cpp_info.components["libprotoc"].libs = [lib_prefix + "protoc" + lib_suffix]
self.cpp_info.components["libprotoc"].requires = ["libprotobuf"]
if self._protobuf_release >= "22.0":
self.cpp_info.components["libprotoc"].requires.extend(absl_deps)
# libprotobuf-lite
if self.options.lite:
self.cpp_info.components["libprotobuf-lite"].set_property("cmake_target_name", "protobuf::libprotobuf-lite")
self.cpp_info.components["libprotobuf-lite"].set_property("pkg_config_name", "protobuf-lite")
self.cpp_info.components["libprotobuf-lite"].builddirs.append(self._cmake_install_base_path)
self.cpp_info.components["libprotobuf-lite"].libs = [lib_prefix + "protobuf-lite" + lib_suffix]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["libprotobuf-lite"].system_libs.extend(["m", "pthread"])
if self._is_clang_x86 or "arm" in str(self.settings.arch):
self.cpp_info.components["libprotobuf-lite"].system_libs.append("atomic")
if self.settings.os == "Windows":
if self.options.shared:
self.cpp_info.components["libprotobuf-lite"].defines = ["PROTOBUF_USE_DLLS"]
if self.settings.os == "Android":
self.cpp_info.components["libprotobuf-lite"].system_libs.append("log")
if self._protobuf_release >= "22.0":
self.cpp_info.components["libprotobuf-lite"].requires.extend(absl_deps)
if not self.options.shared:
self.cpp_info.components["libprotobuf-lite"].requires.extend(["utf8_validity"])
# TODO: to remove in conan v2 once cmake_find_package* & pkg_config generators removed
self.cpp_info.filenames["cmake_find_package"] = "Protobuf"
self.cpp_info.filenames["cmake_find_package_multi"] = "protobuf"
self.cpp_info.names["pkg_config"] ="protobuf_full_package"
for generator in ["cmake_find_package", "cmake_find_package_multi"]:
self.cpp_info.components["libprotobuf"].build_modules[generator] = build_modules
if self.options.lite:
for generator in ["cmake_find_package", "cmake_find_package_multi"]:
self.cpp_info.components["libprotobuf-lite"].build_modules[generator] = build_modules
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))

View File

@@ -0,0 +1,70 @@
diff --git a/src/google/protobuf/port.cc b/src/google/protobuf/port.cc
index af668e9e2..d60c2b89f 100644
--- a/src/google/protobuf/port.cc
+++ b/src/google/protobuf/port.cc
@@ -97,14 +97,9 @@ void RealDebugCounter::Register(absl::string_view name) {
}
}
-#if defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
-PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT const GlobalEmptyString
- fixed_address_empty_string{};
-#else
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT
PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 GlobalEmptyString
fixed_address_empty_string{};
-#endif
} // namespace internal
} // namespace protobuf
diff --git a/src/google/protobuf/port.h b/src/google/protobuf/port.h
index 5f9e909a0..386ecc02a 100644
--- a/src/google/protobuf/port.h
+++ b/src/google/protobuf/port.h
@@ -494,20 +494,27 @@ class NoopDebugCounter {
// Default empty string object. Don't use this directly. Instead, call
// GetEmptyString() to get the reference. This empty string is aligned with a
// minimum alignment of 8 bytes to match the requirement of ArenaStringPtr.
-#if defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
+
// Take advantage of C++20 constexpr support in std::string.
-class alignas(8) GlobalEmptyString {
+class alignas(8) GlobalEmptyStringConstexpr {
public:
const std::string& get() const { return value_; }
// Nothing to init, or destroy.
std::string* Init() const { return nullptr; }
+ template <typename T = std::string, bool = (T(), true)>
+ static constexpr std::true_type HasConstexprDefaultConstructor(int) {
+ return {};
+ }
+ static constexpr std::false_type HasConstexprDefaultConstructor(char) {
+ return {};
+ }
+
private:
std::string value_;
};
-PROTOBUF_EXPORT extern const GlobalEmptyString fixed_address_empty_string;
-#else
-class alignas(8) GlobalEmptyString {
+
+class alignas(8) GlobalEmptyStringDynamicInit {
public:
const std::string& get() const {
return *reinterpret_cast<const std::string*>(internal::Launder(buffer_));
@@ -519,8 +526,12 @@ class alignas(8) GlobalEmptyString {
private:
alignas(std::string) char buffer_[sizeof(std::string)];
};
+
+using GlobalEmptyString = std::conditional_t<
+ GlobalEmptyStringConstexpr::HasConstexprDefaultConstructor(0),
+ const GlobalEmptyStringConstexpr, GlobalEmptyStringDynamicInit>;
+
PROTOBUF_EXPORT extern GlobalEmptyString fixed_address_empty_string;
-#endif
} // namespace internal
} // namespace protobuf

View File

@@ -0,0 +1,21 @@
diff --git a/src/google/protobuf/port.h b/src/google/protobuf/port.h
index 386ecc02a..32d260c42 100644
--- a/src/google/protobuf/port.h
+++ b/src/google/protobuf/port.h
@@ -502,10 +502,16 @@ class alignas(8) GlobalEmptyStringConstexpr {
// Nothing to init, or destroy.
std::string* Init() const { return nullptr; }
+ // Disable the optimization for MSVC.
+ // There are some builds where the default constructed string can't be used as
+ // `constinit` even though the constructor is `constexpr` and can be used
+ // during constant evaluation.
+#if !defined(_MSC_VER)
template <typename T = std::string, bool = (T(), true)>
static constexpr std::true_type HasConstexprDefaultConstructor(int) {
return {};
}
+#endif
static constexpr std::false_type HasConstexprDefaultConstructor(char) {
return {};
}

View File

@@ -0,0 +1,25 @@
if(NOT TARGET protobuf::protoc)
# Locate protoc executable
## Workaround for legacy "cmake" generator in case of cross-build
if(CMAKE_CROSSCOMPILING)
find_program(PROTOC_PROGRAM NAMES protoc PATHS ENV PATH NO_DEFAULT_PATH)
endif()
## And here this will work fine with "CMakeToolchain" (for native & cross-build)
## and legacy "cmake" generator in case of native build
if(NOT PROTOC_PROGRAM)
find_program(PROTOC_PROGRAM NAMES protoc)
endif()
## Last resort: we search in package folder directly
if(NOT PROTOC_PROGRAM)
set(PROTOC_PROGRAM "${CMAKE_CURRENT_LIST_DIR}/../../../bin/protoc${CMAKE_EXECUTABLE_SUFFIX}")
endif()
get_filename_component(PROTOC_PROGRAM "${PROTOC_PROGRAM}" ABSOLUTE)
# Give opportunity to users to provide an external protoc executable
# (this is a feature of official FindProtobuf.cmake)
set(Protobuf_PROTOC_EXECUTABLE ${PROTOC_PROGRAM} CACHE FILEPATH "The protoc compiler")
# Create executable imported target protobuf::protoc
add_executable(protobuf::protoc IMPORTED)
set_property(TARGET protobuf::protoc PROPERTY IMPORTED_LOCATION ${Protobuf_PROTOC_EXECUTABLE})
endif()

View File

@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)
find_package(protobuf CONFIG REQUIRED)
add_executable(${PROJECT_NAME} test_package.cpp)
if(CONAN_TEST_USE_CXXSTD_14)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
else()
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
endif()
if (protobuf_LITE)
target_link_libraries(${PROJECT_NAME} PRIVATE protobuf::libprotobuf-lite)
target_compile_definitions(${PROJECT_NAME} PRIVATE CONANTEST_PROTOBUF_LITE=1)
else()
target_link_libraries(${PROJECT_NAME} PRIVATE protobuf::libprotobuf)
endif()
if(NOT TARGET protobuf::protoc)
message(FATAL_ERROR "protoc executable should have been defined as part of find_package(protobuf)")
endif()
if(NOT COMMAND protobuf_generate)
message(FATAL_ERROR "protobuf_generate should have been defined as part of find_package(protobuf)")
endif()

View File

@@ -0,0 +1,64 @@
// See README.txt for information and build instructions.
//
// Note: START and END tags are used in comments to define sections used in
// tutorials. They are not part of the syntax for Protocol Buffers.
//
// To get an in-depth walkthrough of this file and the related examples, see:
// https://developers.google.com/protocol-buffers/docs/tutorials
// [START declaration]
syntax = "proto3";
package tutorial;
import "google/protobuf/timestamp.proto";
// [END declaration]
// [START java_declaration]
option java_package = "com.example.tutorial";
option java_outer_classname = "AddressBookProtos";
// [END java_declaration]
// [START csharp_declaration]
option csharp_namespace = "Google.Protobuf.Examples.AddressBook";
// [END csharp_declaration]
// [START messages]
message Person {
string name = 1;
int32 id = 2; // Unique ID number for this person.
string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
string number = 1;
PhoneType type = 2;
}
repeated PhoneNumber phones = 4;
google.protobuf.Timestamp last_updated = 5;
}
// Our address book file is just one of these.
message AddressBook {
repeated Person people = 1;
}
// [END messages]
// Artibrary message with a GID type, to cause
// the .pb.h file to define `GID_MAX`, which
// may conflict with a macro defined by system
// headers on macOS.
message FooBar {
enum GID {
FOO = 0;
}
enum UID {
BAR = 0;
}
}

View File

@@ -0,0 +1,40 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain
from conan.tools.scm import Version
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "VirtualBuildEnv", "VirtualRunEnv"
test_type = "explicit"
def layout(self):
cmake_layout(self)
def requirements(self):
# note `run=True` so that the runenv can find protoc
self.requires(self.tested_reference_str, run=True)
def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["protobuf_LITE"] = self.dependencies[self.tested_reference_str].options.lite
protobuf_version = Version(self.dependencies[self.tested_reference_str].ref.version)
tc.cache_variables["CONAN_TEST_USE_CXXSTD_14"] = protobuf_version >= "3.22"
tc.generate()
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_package")
self.run(bin_path, env="conanrun")
# Invoke protoc in the same way CMake would
self.run(f"protoc --proto_path={self.source_folder} --cpp_out={self.build_folder} {self.source_folder}/addressbook.proto", env="conanrun")
assert os.path.exists(os.path.join(self.build_folder,"addressbook.pb.cc"))
assert os.path.exists(os.path.join(self.build_folder,"addressbook.pb.h"))

View File

@@ -0,0 +1,23 @@
#include <cstdlib>
#include <iostream>
#if !defined(CONANTEST_PROTOBUF_LITE)
#include <google/protobuf/timestamp.pb.h>
#include <google/protobuf/util/time_util.h>
#else
#include <google/protobuf/message_lite.h>
#endif
int main()
{
#if !defined(CONANTEST_PROTOBUF_LITE)
google::protobuf::Timestamp ts;
google::protobuf::util::TimeUtil::FromString("1972-01-01T10:00:20.021Z", &ts);
const auto nanoseconds = ts.nanos();
std::cout << "1972-01-01T10:00:20.021Z in nanoseconds: " << nanoseconds << "\n";
#else
google::protobuf::ShutdownProtobufLibrary();
#endif
return EXIT_SUCCESS;
}