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

Update CMake configuration to add a dependency on Abseil #9793

Merged
merged 22 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7fa212b
Fix NPE during encoding and add regression test for issue 9507.
JasonLunn Mar 16, 2022
31a6482
Implement `respond_to?` in RubyMessage (#9677)
JasonLunn Mar 28, 2022
e097b36
Merge pull request #9714 from JasonLunn/3.20.x
jorgbrown Apr 2, 2022
d24edbc
Update protobuf version
mkruskal-google Apr 4, 2022
5edc844
Merge pull request #9727 from mlocati/build-packaged-php-extension
mkruskal-google Apr 5, 2022
803e371
Update protobuf version
mkruskal-google Apr 6, 2022
7db4eca
Update changelogs for 3.20.1-rc1
mkruskal-google Apr 6, 2022
c1093a2
Merge branch '3.20.x-202204051705' of github.com:mkruskal-google/prot…
mkruskal-google Apr 7, 2022
06750a8
Merge branch 'mkruskal-google-3.20.x-202204051705'
mkruskal-google Apr 7, 2022
b176d7b
Proof of concept for CMake Abseil dependency
mkruskal-google Apr 14, 2022
72c6de8
Merge branch 'protocolbuffers:main' into cmake_absl
mkruskal-google Apr 15, 2022
e3bfa24
Hooked up Abseil linking
mkruskal-google Apr 15, 2022
0087dc9
Adding test binaries
mkruskal-google Apr 15, 2022
7c729a3
Reverting absl::string view use added for testing. This will still b…
mkruskal-google Apr 15, 2022
da19870
Adding new cmake config to dist list
mkruskal-google Apr 15, 2022
487223c
Whitespace fixes and an attempt at fix for Windows Python Release (CM…
mkruskal-google Apr 15, 2022
b69dcff
Hook up LTS to windows cmake
mkruskal-google Apr 15, 2022
2038715
Fix 'git cd' typo
mkruskal-google Apr 15, 2022
dbdd8d8
Adding clarifying comment for fix
mkruskal-google Apr 15, 2022
2c9ec8f
Adding abseil dependency to protobuf-lite too
mkruskal-google Apr 15, 2022
80e169a
Update submodules instead of cloning abseil-cpp
mkruskal-google Apr 17, 2022
5dd53aa
Adding explicit pointer to abseil root directory
mkruskal-google Apr 17, 2022
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
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# These are fetched as external repositories.
third_party/abseil-cpp
third_party/benchmark
third_party/googletest
_build/
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
path = third_party/googletest
url = https://github.com/google/googletest.git
ignore = dirty
[submodule "third_party/abseil-cpp"]
path = third_party/abseil-cpp
url = https://github.com/abseil/abseil-cpp.git
branch = lts_2021_11_02
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/cmaketest.map)

find_package(Threads REQUIRED)

# We can install dependencies from submodules if we're running
# CMake v3.13 or newer.
if(CMAKE_VERSION VERSION_LESS 3.13)
set(_protobuf_INSTALL_SUPPORTED_FROM_MODULE OFF)
else()
set(_protobuf_INSTALL_SUPPORTED_FROM_MODULE ON)
endif()


set(_protobuf_FIND_ZLIB)
if (protobuf_WITH_ZLIB)
find_package(ZLIB)
Expand Down Expand Up @@ -301,6 +310,10 @@ if (protobuf_UNICODE)
add_definitions(-DUNICODE -D_UNICODE)
endif (protobuf_UNICODE)

set(protobuf_ABSL_PROVIDER "module" CACHE STRING "Provider of absl library")
set_property(CACHE protobuf_ABSL_PROVIDER PROPERTY STRINGS "module" "package")

include(${protobuf_SOURCE_DIR}/cmake/abseil-cpp.cmake)
include(${protobuf_SOURCE_DIR}/cmake/libprotobuf-lite.cmake)
include(${protobuf_SOURCE_DIR}/cmake/libprotobuf.cmake)
if (protobuf_BUILD_LIBPROTOC)
Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,7 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \
BUILD \
WORKSPACE \
CMakeLists.txt \
cmake/abseil-cpp.cmake \
cmake/CMakeLists.txt \
cmake/README.md \
cmake/conformance.cmake \
Expand Down
28 changes: 28 additions & 0 deletions cmake/abseil-cpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
if(protobuf_ABSL_PROVIDER STREQUAL "module")
if(NOT ABSL_ROOT_DIR)
set(ABSL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp)
endif()
if(EXISTS "${ABSL_ROOT_DIR}/CMakeLists.txt")
if(protobuf_INSTALL)
# When protobuf_INSTALL is enabled and Abseil will be built as a module,
# Abseil will be installed along with protobuf for convenience.
set(ABSL_ENABLE_INSTALL ON)
endif()
add_subdirectory(${ABSL_ROOT_DIR} third_party/abseil-cpp)
else()
message(WARNING "protobuf_ABSL_PROVIDER is \"module\" but ABSL_ROOT_DIR is wrong")
endif()
if(protobuf_INSTALL AND NOT _protobuf_INSTALL_SUPPORTED_FROM_MODULE)
message(WARNING "protobuf_INSTALL will be forced to FALSE because protobuf_ABSL_PROVIDER is \"module\" and CMake version (${CMAKE_VERSION}) is less than 3.13.")
set(protobuf_INSTALL FALSE)
endif()
elseif(protobuf_ABSL_PROVIDER STREQUAL "package")
# Use "CONFIG" as there is no built-in cmake module for absl.
find_package(absl REQUIRED CONFIG)
endif()
set(_protobuf_FIND_ABSL "if(NOT TARGET absl::strings)\n find_package(absl CONFIG)\nendif()")

set(protobuf_ABSL_USED_TARGETS
absl::strings
absl::strings_internal
)
3 changes: 3 additions & 0 deletions cmake/libprotobuf-lite.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ if(protobuf_HAVE_LD_VERSION_SCRIPT)
LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotobuf-lite.map)
endif()
target_link_libraries(libprotobuf-lite PRIVATE ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(libprotobuf-lite
PRIVATE ${ABSL_ROOT_DIR}
)
if(protobuf_LINK_LIBATOMIC)
target_link_libraries(libprotobuf-lite PRIVATE atomic)
endif()
Expand Down
3 changes: 3 additions & 0 deletions cmake/libprotobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ if(protobuf_HAVE_LD_VERSION_SCRIPT)
LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotobuf.map)
endif()
target_link_libraries(libprotobuf PRIVATE ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(libprotobuf
mkruskal-google marked this conversation as resolved.
Show resolved Hide resolved
PRIVATE ${ABSL_ROOT_DIR}
)
if(protobuf_WITH_ZLIB)
target_link_libraries(libprotobuf PRIVATE ${ZLIB_LIBRARIES})
endif()
Expand Down
3 changes: 3 additions & 0 deletions cmake/libprotoc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ if(protobuf_HAVE_LD_VERSION_SCRIPT)
LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotoc.map)
endif()
target_link_libraries(libprotoc PRIVATE libprotobuf)
target_include_directories(libprotoc
PRIVATE ${ABSL_ROOT_DIR}
)
if(protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotoc
PUBLIC PROTOBUF_USE_DLLS
Expand Down
1 change: 1 addition & 0 deletions cmake/protobuf-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake")

# Depend packages
@_protobuf_FIND_ZLIB@
@_protobuf_FIND_ABSL@

# Imported targets
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake")
Expand Down
6 changes: 5 additions & 1 deletion cmake/protoc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ set(protoc_rc_files
endif()

add_executable(protoc ${protoc_files} ${protoc_rc_files})
target_link_libraries(protoc libprotoc libprotobuf)
target_link_libraries(protoc
libprotoc
libprotobuf
${protobuf_ABSL_USED_TARGETS}
)
add_executable(protobuf::protoc ALIAS protoc)

set_target_properties(protoc PROPERTIES
Expand Down
17 changes: 15 additions & 2 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ else()
set(googlemock_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googlemock")
set(googletest_source_dir "${protobuf_SOURCE_DIR}/third_party/googletest/googletest")
include_directories(
${ABSL_ROOT_DIR}
${googlemock_source_dir}
${googletest_source_dir}
${googletest_source_dir}/include
Expand Down Expand Up @@ -255,7 +256,14 @@ if (MSVC)
/wd4146 # unary minus operator applied to unsigned type, result still unsigned
)
endif()
target_link_libraries(tests protobuf-lite-test-common protobuf-test-common libprotoc libprotobuf GTest::gmock_main)
target_link_libraries(tests
protobuf-lite-test-common
protobuf-test-common
libprotoc
libprotobuf
GTest::gmock_main
${protobuf_ABSL_USED_TARGETS}
)

set(test_plugin_files
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/mock_code_generator.cc
Expand All @@ -265,7 +273,12 @@ set(test_plugin_files
)

add_executable(test_plugin ${test_plugin_files})
target_link_libraries(test_plugin libprotoc libprotobuf GTest::gmock)
target_link_libraries(test_plugin
libprotoc
libprotobuf
GTest::gmock
${protobuf_ABSL_USED_TARGETS}
)

set(lite_test_files
${protobuf_SOURCE_DIR}/src/google/protobuf/lite_unittest.cc
Expand Down
2 changes: 1 addition & 1 deletion kokoro/release/python/linux/build_artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ git clone https://github.com/matthew-brett/multibuild.git
# silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180).
# IMPORTANT: always pin multibuild at the same commit for:
# - linux/build_artifacts.sh
# - linux/build_artifacts.sh
# - macos/build_artifacts.sh
Copy link
Member

Choose a reason for hiding this comment

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

Were these changes meant to be included? I think this PR must have been based on the 3.20.x branch because it seems to be including some commits that are on 3.20.x but haven't been merged to main yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

No this was based on main. I just came across these and got confused, and thought I should update them

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, I see. It's still strange that a bunch of unrelated commits show up here: https://github.com/protocolbuffers/protobuf/pull/9793/commits But I guess if you do "squash and merge" then it won't matter.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yea I think I was originally off of 3.20.x and switched to main in commit 72c6de8. Squash and merge should keep it hidden though :)

# - windows/build_artifacts.bat
(cd multibuild; git checkout b89bb903e94308be79abefa4f436bf123ebb1313)
cp kokoro/release/python/linux/config.sh config.sh
Expand Down
2 changes: 1 addition & 1 deletion kokoro/release/python/macos/build_artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ git clone https://github.com/matthew-brett/multibuild.git
# silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180).
# IMPORTANT: always pin multibuild at the same commit for:
# - linux/build_artifacts.sh
# - linux/build_artifacts.sh
# - macos/build_artifacts.sh
# - windows/build_artifacts.bat
(cd multibuild; git checkout b89bb903e94308be79abefa4f436bf123ebb1313)
cp kokoro/release/python/macos/config.sh config.sh
Expand Down
7 changes: 6 additions & 1 deletion kokoro/release/python/windows/build_artifacts.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ REM Pin multibuild scripts at a known commit to avoid potentially unwanted futur
REM silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180).
REM IMPORTANT: always pin multibuild at the same commit for:
REM - linux/build_artifacts.sh
REM - linux/build_artifacts.sh
REM - macos/build_artifacts.sh
REM - windows/build_artifacts.bat
cd multibuild
git checkout b89bb903e94308be79abefa4f436bf123ebb1313
Expand All @@ -34,6 +34,11 @@ SET ZLIB_ROOT=%cd%\zlib
del /Q zlib.zip
del /Q zlib-src.zip

REM Update Submodules
REM This is needed because this build uses CMake <3.13.
git submodule update --init --recursive
SET ABSL_ROOT_DIR=%cd%\third_party\abseil-cpp

REM Create directory for artifacts
SET ARTIFACT_DIR=%cd%\artifacts
mkdir %ARTIFACT_DIR%
Expand Down
2 changes: 1 addition & 1 deletion kokoro/release/python/windows/build_single_artifact.bat
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mkdir src\.libs

mkdir vcprojects
pushd vcprojects
cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% -Dprotobuf_UNICODE=%UNICODE% -Dprotobuf_BUILD_TESTS=OFF ../cmake || goto :error
cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% -Dprotobuf_UNICODE=%UNICODE% -Dprotobuf_BUILD_TESTS=OFF -DABSL_ROOT_DIR=%ABSL_ROOT_DIR% ../cmake || goto :error
msbuild protobuf.sln /p:Platform=%vcplatform% /p:Configuration=Release || goto :error
dir /s /b
popd
Expand Down
1 change: 1 addition & 0 deletions third_party/abseil-cpp
Submodule abseil-cpp added at 8c6e53