From 63fa4fde4ec7d1151cbf4095e442ec1f96dcb4a1 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 12 Jul 2024 12:17:04 +0200 Subject: [PATCH] [CI] Build failures with ABSEIL 20240116 and CMAKE 3.30 (#3002) --- ci/fix-abseil-cpp-issue-1536.patch | 23 +++++++++++++++++++ ci/install_abseil.sh | 37 ++++++++++++++++++++++++++++++ tools/format.sh | 4 ++-- 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 ci/fix-abseil-cpp-issue-1536.patch diff --git a/ci/fix-abseil-cpp-issue-1536.patch b/ci/fix-abseil-cpp-issue-1536.patch new file mode 100644 index 0000000000..7004cf0479 --- /dev/null +++ b/ci/fix-abseil-cpp-issue-1536.patch @@ -0,0 +1,23 @@ +commit 779a3565ac6c5b69dd1ab9183e500a27633117d5 +Author: Derek Mauro +Date: Tue Jan 30 10:13:25 2024 -0800 + + Avoid export of testonly target absl::test_allocator in CMake builds + + Closes #1536 + + PiperOrigin-RevId: 602764437 + Change-Id: Ia5c20a3874262a2ddb8797f608af17d7e86dd6d6 + +diff --git a/absl/container/CMakeLists.txt b/absl/container/CMakeLists.txt +index 449a2cad..ee9ca9c3 100644 +--- a/absl/container/CMakeLists.txt ++++ b/absl/container/CMakeLists.txt +@@ -213,6 +213,7 @@ absl_cc_library( + DEPS + absl::config + GTest::gmock ++ TESTONLY + ) + + absl_cc_test( diff --git a/ci/install_abseil.sh b/ci/install_abseil.sh index 46a7870627..ced090cc64 100755 --- a/ci/install_abseil.sh +++ b/ci/install_abseil.sh @@ -7,6 +7,8 @@ set -ex export DEBIAN_FRONTEND=noninteractive [ -z "${ABSEIL_CPP_VERSION}" ] && export ABSEIL_CPP_VERSION="20240116.1" +TOPDIR=`pwd` + BUILD_DIR=/tmp/ INSTALL_DIR=/usr/local/ pushd $BUILD_DIR @@ -22,6 +24,41 @@ if [ ! -z "${CXX_STANDARD}" ]; then ABSEIL_CPP_BUILD_OPTIONS=(${ABSEIL_CPP_BUILD_OPTIONS[@]} "-DCMAKE_CXX_STANDARD=${CXX_STANDARD}") fi +# +# ABSEIL_CPP_VERSION="20240116.1" fails to build with CMake 3.30 +# ABSEIL_CPP_VERSION="20240116.2" fails to build with CMake 3.30 +# note that somehow the same builds with CMake 3.29.6 +# +# Error reported: +# CMake Error at CMake/AbseilHelpers.cmake:317 (target_link_libraries): +# The link interface of target "test_allocator" contains: +# +# GTest::gmock +# +# but the target was not found. Possible reasons include: +# +# * There is a typo in the target name. +# * A find_package call is missing for an IMPORTED target. +# * An ALIAS target is missing. +# +# Call Stack (most recent call first): +# absl/container/CMakeLists.txt:206 (absl_cc_library) +# +# Root cause: +# https://github.com/abseil/abseil-cpp/pull/1536 +# +# Applying fix from abseil commit 779a3565ac6c5b69dd1ab9183e500a27633117d5 +# +# TODO(marcalff) Cleanup once abseil is upgraded to the next LTS + + +if [ "${ABSEIL_CPP_VERSION}" = "20240116.1" ] || [ "${ABSEIL_CPP_VERSION}" = "20240116.2" ]; then + echo "Patching abseil" + patch -p1 < ${TOPDIR}/ci/fix-abseil-cpp-issue-1536.patch +else + echo "Not patching abseil" +fi + mkdir build && pushd build cmake "${ABSEIL_CPP_BUILD_OPTIONS[@]}" .. make -j $(nproc) diff --git a/tools/format.sh b/tools/format.sh index 65728b385f..3a3863a8ea 100755 --- a/tools/format.sh +++ b/tools/format.sh @@ -23,8 +23,8 @@ fi # No CRLF line endings, except Windows files. "${SED[@]}" 's/\r$//' $($FIND -name '*.ps1' -prune -o \ -name '*.cmd' -prune -o -type f -print) -# No trailing spaces. -"${SED[@]}" 's/ \+$//' $($FIND -type f -print) +# No trailing spaces, except in patch. +"${SED[@]}" 's/ \+$//' $($FIND -name "*.patch" -prune -o -type f -print) # If not overridden, try to use clang-format-18 or clang-format. if [[ -z "$CLANG_FORMAT" ]]; then