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

protobuf: add v4.25.3, v5.26.0 #21622

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
356b87e
protobuf: add version 4.23.1
toge Feb 17, 2023
fa4981b
cast string
toge May 23, 2023
4df762c
enable C++14 on protobuf>=4.20.0
toge May 23, 2023
06af570
make abseil shared when protobuf is shared
toge May 24, 2023
3a259e0
build abseil shared only on msvc
toge May 24, 2023
04e73d7
add utf8_lib_prefix
toge May 24, 2023
430c798
apply miklelappo's comment
toge May 25, 2023
471d84e
revert protobuf-protoc.cmake (xxx-config.cmake is not permitted)
toge May 25, 2023
944fd2c
fix validation
toge May 26, 2023
7bb3e3f
protobuf: bump version to v3.25.1
valgur Dec 5, 2023
a0ba6ea
protobuf: add check for shared abseil
valgur Dec 5, 2023
1a253a3
protobuf: bump version to v3.25.2
valgur Jan 17, 2024
b0e6e09
protobuf: use is_msvc_static_runtime()
valgur Jan 17, 2024
d8dbd1b
Bump patch version and correctly bump major version
Ahajha Mar 9, 2024
aadc616
Merge branch 'master' into update/protobuf-v4.25
Ahajha Mar 11, 2024
6e4fa05
Test
AbrilRBS Mar 14, 2024
5c038f9
Merge branch 'master' into update/protobuf-v4.25
Ahajha Mar 15, 2024
eaafddb
Add 5.26.0
Ahajha Mar 15, 2024
0b6b1ad
Add note about protobuf versions
Ahajha Mar 15, 2024
b9d4fbd
Merge branch 'master' into update/protobuf-v4.25
Ahajha Mar 21, 2024
97a1bf6
protobuf: drop versions older than 3.20.3
valgur Mar 23, 2024
4b11ccb
Update to protobuf 5.26.1
Ahajha Apr 5, 2024
59e1e47
Merge branch 'master' into update/protobuf-v4.25
valgur Apr 12, 2024
02fbd30
protobuf: avoid tool_requires() in test_package
valgur Apr 16, 2024
4529c72
protobuf: format imports
valgur Apr 16, 2024
f1ed8fa
protobuf: skip protobuf_generate() test when cross-compiling
valgur Apr 16, 2024
ac7941e
protobuf: try a macOS workaround from grpc recipe
valgur Apr 17, 2024
652a7ca
Merge branch 'master' into update/protobuf-v4.25
Ahajha Apr 17, 2024
a78b07a
Merge branch 'master' into update/protobuf-v4.25
Ahajha Apr 17, 2024
04ed7f6
Merge branch 'master' into update/protobuf-v4.25
Ahajha Apr 17, 2024
ef0ac4e
Merge branch 'master' into update/protobuf-v4.25
Ahajha Apr 18, 2024
4696eeb
Remove CMake calls for now
Ahajha Apr 18, 2024
3958f9b
Fix running test package with whitespace in path
Ahajha Apr 18, 2024
7f03206
protobuf: try building without setting CMAKE_CXX_STANDARD
valgur May 14, 2024
d454a59
protobuf: revert left-over workarounds in test_package
valgur May 14, 2024
b39a294
Revert "protobuf: try building without setting CMAKE_CXX_STANDARD"
valgur May 14, 2024
48d3263
protobuf: apply review suggestions
valgur May 14, 2024
c83f1cd
protobuf: restore "linkage" test for CMake functions in test_package
valgur May 16, 2024
9bc1f12
protobuf: simplify CMake module packaging
valgur May 16, 2024
6da91e5
protobuf: restore macOS CMake test_package workaround
valgur May 17, 2024
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
46 changes: 10 additions & 36 deletions recipes/protobuf/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
sources:
# Protobuf maintains multiple different "versions" with the same code for different
# languages, so it is possible to bump these versions incorrectly.
# Follow https://protobuf.dev/support/version-support/#cpp to see what the correct
# version is for C++.
"5.26.1":
url: "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v5.26.1.tar.gz"
sha256: "3754236f50b12d6b7acbc8a8b233a4324b576fa1f49c7098fb743b788ffade41"
"4.25.3":
url: "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v4.25.3.tar.gz"
sha256: "1d6b8d9114cb5b33ce8711729893097a107d4fefff5423528eb1decb5451856c"
"3.21.12":
url: "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.21.12.tar.gz"
sha256: "930c2c3b5ecc6c9c12615cf5ad93f1cd6e12d0aba862b572e076259970ac3a53"
Expand All @@ -8,18 +18,6 @@ sources:
"3.20.3":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.20.3.tar.gz"
sha256: "9c0fd39c7a08dff543c643f0f4baf081988129a411b977a07c46221793605638"
"3.20.0":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.20.0.tar.gz"
sha256: "b07772d38ab07e55eca4d50f4b53da2d998bb221575c60a4f81100242d4b4889"
"3.19.6":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.19.6.tar.gz"
sha256: "9a301cf94a8ddcb380b901e7aac852780b826595075577bb967004050c835056"
"3.18.3":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.18.3.tar.gz"
sha256: "663b3a6d56605e6ab7888d32a1525c34f34639b25b8996337821591e60c37041"
"3.17.1":
url: "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.17.1.tar.gz"
sha256: "036d66d6eec216160dd898cfb162e9d82c1904627642667cc32b104d407bb411"
patches:
"3.21.12":
- patch_file: "patches/protobuf-3.21.12-upstream-macos-macros.patch"
Expand All @@ -36,27 +34,3 @@ patches:
patch_description: "Handle case where macOS SDK macros may conflict with protobuf message types"
patch_type: "bugfix"
patch_source: "https://github.com/protocolbuffers/protobuf/pull/10103"
"3.20.0":
- patch_file: "patches/protobuf-3.20.0-upstream-macos-macros.patch"
patch_description: "Handle case where macOS SDK macros may conflict with protobuf message types"
patch_type: "bugfix"
patch_source: "https://github.com/protocolbuffers/protobuf/pull/10103"
"3.19.6":
- patch_file: "patches/upstream-pr-9437-msvc-runtime.patch"
patch_description: "Properly handle CMAKE_MSVC_RUNTIME_LIBRARY when using CMake >= 3.15"
patch_type: "portability"
patch_source: "https://github.com/protocolbuffers/protobuf/pull/9437"
- patch_file: "patches/protobuf-3.19.6-upstream-macos-macros.patch"
patch_description: "Handle case where macOS SDK macros may conflict with protobuf message types"
patch_type: "bugfix"
patch_source: "https://github.com/protocolbuffers/protobuf/pull/10103"
"3.18.3":
- patch_file: "patches/protobuf-3.18.1-upstream-macos-macros.patch"
patch_description: "Handle case where macOS SDK macros may conflict with protobuf message types"
patch_type: "bugfix"
patch_source: "https://github.com/protocolbuffers/protobuf/pull/10103"
"3.17.1":
- patch_file: "patches/protobuf-3.17.1-upstream-macos-macros.patch"
patch_description: "Handle case where macOS SDK macros may conflict with protobuf message types"
patch_type: "bugfix"
patch_source: "https://github.com/protocolbuffers/protobuf/pull/10103"
101 changes: 75 additions & 26 deletions recipes/protobuf/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.build import check_min_cppstd, valid_min_cppstd
from conan.tools.files import copy, rename, get, apply_conandata_patches, export_conandata_patches, replace_in_file, rmdir, rm
from conan.tools.microsoft import check_min_vs, msvc_runtime_flag, is_msvc, is_msvc_static_runtime
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version

import os
import textwrap

required_conan_version = ">=1.53"
required_conan_version = ">=1.53.0"


class ProtobufConan(ConanFile):
Expand Down Expand Up @@ -48,6 +49,26 @@
def _is_clang_x86(self):
return self.settings.compiler == "clang" and self.settings.arch == "x86"

@property
def _min_cppstd(self):
return 11 if Version(self.version) < "3.22.0" else 14

@property
def _compilers_minimum_version(self):
if self._min_cppstd == 14:
return {
"gcc": "7.3",
"clang": "5",
"apple-clang": "10",
"Visual Studio": "15",
"msvc": "191",
}
return {
"clang": "4",
"Visual Studio": "14",
"msvc": "190",
uilianries marked this conversation as resolved.
Show resolved Hide resolved
}
valgur marked this conversation as resolved.
Show resolved Hide resolved

def export_sources(self):
export_conandata_patches(self)

Expand All @@ -58,23 +79,32 @@
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
if Version(self.version) >= "3.22.0" and is_msvc(self):
uilianries marked this conversation as resolved.
Show resolved Hide resolved
self.options["abseil"].shared = True
valgur 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_zlib:
self.requires("zlib/[>=1.2.11 <2]")
if Version(self.version) >= "3.22.0":
valgur marked this conversation as resolved.
Show resolved Hide resolved
self.requires("abseil/20230802.1", transitive_headers=True)

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")

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 self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.",
)

if self.options.shared and is_msvc(self):
if is_msvc_static_runtime(self):
raise ConanInvalidConfiguration(f"{self.ref} can't be built with shared + MT(d) runtimes")
if Version(self.version) >= "3.22.0" and not self.dependencies["abseil"].options.shared:
raise ConanInvalidConfiguration(f"Shared build of protobuf requires shared Abseil on MSVC to avoid ODR violations.")

Check warning on line 107 in recipes/protobuf/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Using an f-string that does not have any interpolated variables

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
Expand All @@ -94,13 +124,13 @@
tc.cache_variables["protobuf_BUILD_LIBPROTOC"] = self.settings.os != "tvOS"
tc.cache_variables["protobuf_DISABLE_RTTI"] = not self.options.with_rtti
if is_msvc(self) or self._is_clang_cl:
runtime = msvc_runtime_flag(self)
if not runtime:
runtime = self.settings.get_safe("compiler.runtime")
tc.cache_variables["protobuf_MSVC_STATIC_RUNTIME"] = "MT" in runtime
tc.cache_variables["protobuf_MSVC_STATIC_RUNTIME"] = is_msvc_static_runtime(self)
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"
tc.variables["protobuf_ABSL_PROVIDER"] = "package"
if not valid_min_cppstd(self, self._min_cppstd):
valgur marked this conversation as resolved.
Show resolved Hide resolved
tc.variables["CMAKE_CXX_STANDARD"] = self._min_cppstd
uilianries marked this conversation as resolved.
Show resolved Hide resolved
tc.generate()

deps = CMakeDeps(self)
Expand All @@ -123,7 +153,7 @@
exe_ext = ".exe" if self.settings.os == "Windows" else ""
protoc_filename = "protoc" + exe_ext
module_folder_depth = len(os.path.normpath(self._cmake_install_base_path).split(os.path.sep))
protoc_rel_path = "{}bin/{}".format("".join(["../"] * module_folder_depth), protoc_filename)
protoc_rel_path = "{}bin/{}".format("../" * module_folder_depth, protoc_filename)
protoc_target = textwrap.dedent(f"""\
if(NOT TARGET protobuf::protoc)
# Locate protoc executable
Expand Down Expand Up @@ -171,13 +201,6 @@
"endif()",
)

# https://github.com/protocolbuffers/protobuf/issues/9916
# it will be solved in protobuf 3.21.0
if Version(self.version) == "3.20.0":
replace_in_file(self, os.path.join(self.source_folder, "src", "google", "protobuf", "port_def.inc"),
"#elif PROTOBUF_GNUC_MIN(12, 0)",
"#elif PROTOBUF_GNUC_MIN(12, 2)")

def build(self):
self._patch_sources()
cmake = CMake(self)
Expand All @@ -191,15 +214,23 @@
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
os.unlink(os.path.join(self.package_folder, self._cmake_install_base_path, "protobuf-config-version.cmake"))
os.unlink(os.path.join(self.package_folder, self._cmake_install_base_path, f"protobuf-targets-{str(self.settings.build_type).lower()}.cmake"))
os.unlink(os.path.join(self.package_folder, self._cmake_install_base_path, "protobuf-targets.cmake"))
os.unlink(os.path.join(self.package_folder, self._cmake_install_base_path, "protobuf-targets-{}.cmake".format(str(self.settings.build_type).lower())))
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"))
if Version(self.version) < "3.22.0":
Copy link
Member

Choose a reason for hiding this comment

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

What's the proposal of this change? I see the same protobuf-generate.cmake being installed with 4.25.3:

-- Up-to-date: /Users/uilian/.conan/data/protobuf/4.25.3/_/_/package/799e25793bb4a51e590a0065a670b4676d489bda/lib/cmake/protobuf
-- Installing: /Users/uilian/.conan/data/protobuf/4.25.3/_/_/package/799e25793bb4a51e590a0065a670b4676d489bda/lib/cmake/protobuf/protobuf-module.cmake
-- Installing: /Users/uilian/.conan/data/protobuf/4.25.3/_/_/package/799e25793bb4a51e590a0065a670b4676d489bda/lib/cmake/protobuf/protobuf-generate.cmake
-- Installing: /Users/uilian/.conan/data/protobuf/4.25.3/_/_/package/799e25793bb4a51e590a0065a670b4676d489bda/lib/cmake/protobuf/protobuf-options.cmake
-- Installing: /Users/uilian/.conan/data/protobuf/4.25.3/_/_/package/799e25793bb4a51e590a0065a670b4676d489bda/lib/cmake/protobuf/protobuf-config.cmake
-- Installing: /Users/uilian/.conan/data/protobuf/4.25.3/_/_/package/799e25793bb4a51e590a0065a670b4676d489bda/lib/cmake/protobuf/protobuf-config-version.cmake

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why @toge saw a need for the if/else based on the version, but packaging protobuf-config.cmake is prohibited by the linter.

Copy link
Member

Choose a reason for hiding this comment

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

but packaging protobuf-config.cmake is prohibited by the linter.

We can skip it from the linter or hooks. Please, revert this change.

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"))
else:
# TODO: dirty hack, need to fix
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-protoc.cmake"))

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"))

if Version(self.version) >= "3.22.0":
rmdir(self, os.path.join(self.package_folder, "lib", "cmake", "utf8_range"))

def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_module_file_name", "Protobuf")
Expand All @@ -211,18 +242,32 @@
os.path.join(self._cmake_install_base_path, "protobuf-module.cmake"),
os.path.join(self._cmake_install_base_path, "protobuf-options.cmake"),
]
if Version(self.version) >= "3.22.0":
build_modules.append(os.path.join(self._cmake_install_base_path, "protobuf-protoc.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 Version(self.version) >= "3.22.0":
utf8_lib_prefix = "lib" if self._is_clang_cl else ""
# utf8_range
self.cpp_info.components["utf8_range"].set_property("cmake_target_name", "protobuf::utf8_range")
self.cpp_info.components["utf8_range"].libs = [utf8_lib_prefix + "utf8_range"]
# utf8_validity
self.cpp_info.components["utf8_validity"].set_property("cmake_target_name", "protobuf::utf8_validity")
self.cpp_info.components["utf8_validity"].libs = [utf8_lib_prefix + "utf8_validity"]

# libprotobuf
# https://github.com/protocolbuffers/protobuf/blob/v25.1/cmake/libprotobuf.cmake
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"]
self.cpp_info.components["libprotobuf"].requires += ["zlib::zlib"]
if Version(self.version) >= "3.22.0":
self.cpp_info.components["libprotobuf"].requires += ["abseil::abseil", "utf8_range", "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):
Expand All @@ -234,17 +279,21 @@
self.cpp_info.components["libprotobuf"].defines = ["PROTOBUF_USE_DLLS"]

# libprotoc
# https://github.com/protocolbuffers/protobuf/blob/v25.1/cmake/libprotobuc.cmake
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"]

# libprotobuf-lite
# https://github.com/protocolbuffers/protobuf/blob/v25.1/cmake/libprotobuf-lite.cmake
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 Version(self.version) >= "3.22.0":
self.cpp_info.components["libprotobuf-lite"].requires += ["abseil::abseil", "utf8_range", "utf8_validity"]
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):
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading