Skip to content

Commit

Permalink
TESTING: Protobuf v26 vs v27
Browse files Browse the repository at this point in the history
* be able to test a locally cloned and hacker version
  • Loading branch information
Mizux committed Jul 19, 2024
1 parent 5e6f23b commit 6e53020
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ git_repository(
# This statement defines the @com_google_protobuf repo.
git_repository(
name = "com_google_protobuf",
patches = ["//patches:protobuf-v27.2.patch"],
patches = ["//patches:protobuf-v27.patch"],
patch_args = ["-p1"],
tag = "v27.2",
remote = "https://github.com/protocolbuffers/protobuf.git",
Expand Down
13 changes: 11 additions & 2 deletions cmake/dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,20 @@ if(BUILD_Protobuf)
#set(protobuf_BUILD_LIBUPB ON)
FetchContent_Declare(
Protobuf
#SOURCE_DIR "${CMAKE_SOURCE_DIR}/pb"

GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git"
GIT_TAG "v27.2"
GIT_TAG "v27.2" # NACK
#GIT_TAG "v27.1" # NACK
#GIT_TAG "v27.0" # NACK
PATCH_COMMAND git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../../patches/protobuf-v27.patch"

#GIT_TAG "v26.1" # ACK
#PATCH_COMMAND git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../../patches/protobuf-v26.patch"

GIT_SHALLOW TRUE
GIT_SUBMODULES ""
PATCH_COMMAND git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../../patches/protobuf-v27.2.patch")
)
FetchContent_MakeAvailable(Protobuf)
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "fetched")
Expand Down
68 changes: 68 additions & 0 deletions patches/protobuf-v26.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 312eeb928..3e154785b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,7 +41,7 @@ else (BUILD_SHARED_LIBS)
endif (BUILD_SHARED_LIBS)
option(protobuf_BUILD_SHARED_LIBS "Build Shared Libraries" ${protobuf_BUILD_SHARED_LIBS_DEFAULT})
include(CMakeDependentOption)
-cmake_dependent_option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON
+cmake_dependent_option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" OFF
"NOT protobuf_BUILD_SHARED_LIBS" OFF)
set(protobuf_WITH_ZLIB_DEFAULT ON)
option(protobuf_WITH_ZLIB "Build with zlib support" ${protobuf_WITH_ZLIB_DEFAULT})
@@ -158,24 +158,16 @@ endif()

set(_protobuf_FIND_ZLIB)
if (protobuf_WITH_ZLIB)
- find_package(ZLIB)
- if (ZLIB_FOUND)
- set(HAVE_ZLIB 1)
- # FindZLIB module define ZLIB_INCLUDE_DIRS variable
- # Set ZLIB_INCLUDE_DIRECTORIES for compatible
- set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS})
- # Using imported target if exists
- if (TARGET ZLIB::ZLIB)
- set(ZLIB_LIBRARIES ZLIB::ZLIB)
- set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()")
- endif (TARGET ZLIB::ZLIB)
- else (ZLIB_FOUND)
- set(HAVE_ZLIB 0)
- # Explicitly set these to empty (override NOT_FOUND) so cmake doesn't
- # complain when we use them later.
- set(ZLIB_INCLUDE_DIRECTORIES)
- set(ZLIB_LIBRARIES)
- endif (ZLIB_FOUND)
+ if (NOT TARGET ZLIB::ZLIB)
+ find_package(ZLIB REQUIRED)
+ endif()
+ set(HAVE_ZLIB 1)
+ # FindZLIB module define ZLIB_INCLUDE_DIRS variable
+ # Set ZLIB_INCLUDE_DIRECTORIES for compatible
+ set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS})
+ # Using imported target if exists
+ set(ZLIB_LIBRARIES ZLIB::ZLIB)
+ set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND AND NOT TARGET ZLIB::ZLIB)\n find_package(ZLIB REQUIRED)\nendif()")
endif (protobuf_WITH_ZLIB)

# We need to link with libatomic on systems that do not have builtin atomics, or
@@ -277,7 +269,6 @@ else (MSVC)
endif (MSVC)

include_directories(
- ${ZLIB_INCLUDE_DIRECTORIES}
${protobuf_BINARY_DIR}
# Support #include-ing other top-level directories, i.e. upb_generator.
${protobuf_SOURCE_DIR}
diff --git a/cmake/install.cmake b/cmake/install.cmake
index 52914a8ea..d7dc5f232 100644
--- a/cmake/install.cmake
+++ b/cmake/install.cmake
@@ -31,6 +31,7 @@ foreach(_library ${_protobuf_libraries})
set_property(TARGET ${_library}
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${protobuf_SOURCE_DIR}/src>
+ $<BUILD_INTERFACE:${protobuf_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
if (UNIX AND NOT APPLE)
set_property(TARGET ${_library}
16 changes: 14 additions & 2 deletions patches/protobuf-v27.2.patch → patches/protobuf-v27.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9b51e9722..33c1021d4 100644
index 9b51e972..33c1021d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,7 +42,7 @@ else (BUILD_SHARED_LIBS)
Expand Down Expand Up @@ -54,8 +54,20 @@ index 9b51e9722..33c1021d4 100644
${protobuf_BINARY_DIR}
# Support #include-ing other top-level directories, i.e. upb_generator.
${protobuf_SOURCE_DIR}
diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake
index 11c09b1b..fdea9ce1 100644
--- a/cmake/libprotobuf.cmake
+++ b/cmake/libprotobuf.cmake
@@ -28,6 +28,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
endif()
target_include_directories(libprotobuf PUBLIC
$<BUILD_INTERFACE:${protobuf_SOURCE_DIR}/src>
+ $<BUILD_INTERFACE:${protobuf_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(libprotobuf PUBLIC ${protobuf_ABSL_USED_TARGETS})
diff --git a/src/google/protobuf/port.h b/src/google/protobuf/port.h
index 4fec7dc13..afb6f846a 100644
index 4fec7dc1..afb6f846 100644
--- a/src/google/protobuf/port.h
+++ b/src/google/protobuf/port.h
@@ -49,31 +49,35 @@ inline PROTOBUF_ALWAYS_INLINE void StrongPointer(T* var) {
Expand Down

0 comments on commit 6e53020

Please sign in to comment.