blob: 703b0b1f1d6e9e4491beb1efdf80c68d4c80d27a [file] [edit]
# Copyright 2020-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
PYTHON_COMPAT=( python3_13 )
inherit cmake cmake-multilib cros-sanitizers flag-o-matic python-any-r1
DESCRIPTION="Abseil Common Libraries (C++), LTS Branch"
HOMEPAGE="https://abseil.io/"
SRC_URI="https://github.com/abseil/abseil-cpp/archive/${PV}.tar.gz -> ${P}.tar.gz"
LICENSE="Apache-2.0"
SLOT="0/${PVR}"
KEYWORDS="*"
IUSE="test"
DEPEND=""
RDEPEND="${DEPEND}
!dev-cpp/absl
"
BDEPEND="
${PYTHON_DEPS}
test? (
>=dev-cpp/gtest-1.13.0
sys-libs/timezone-data
)
"
RESTRICT="!test? ( test )"
PATCHES=(
"${FILESDIR}"/use-std-optional.patch
"${FILESDIR}"/abseil-cpp-20230802.0-dll.patch
)
MAJOR=$(ver_cut 1)
SOVERSION="${MAJOR:2:4}.0.0"
src_prepare() {
cmake_src_prepare
# un-hardcode abseil compiler flags
sed -i \
-e '/"-maes",/d' \
-e '/"-msse4.1",/d' \
-e '/"-mfpu=neon"/d' \
-e '/"-march=armv8-a+crypto"/d' \
absl/copts/copts.py || die
# now generate cmake files
python_fix_shebang absl/copts/generate_copts.py
absl/copts/generate_copts.py || die
# ChromeOS (b/264420866): Enable a "hardened" build.
sed -i 's/^#define ABSL_OPTION_HARDENED 0/#define ABSL_OPTION_HARDENED 1/' \
absl/base/options.h || die
}
multilib_src_configure() {
append-lfs-flags
# ChromeOS: Prevent exporting inline symbols to improve startup speed.
# (go/cros-symbol-slimming)
append-cxxflags -fvisibility-inlines-hidden
# ChromeOS: Assume no interposition and pre-bind DSO-local symbols to
# improve startup speed. (go/cros-symbol-slimming)
append-ldflags -Wl,-Bsymbolic-non-weak
sanitizers-setup-env # ChromeOS-specific asan fix.
# shellcheck disable=SC2034 # Used by cmake.eclass
local mycmakeargs=(
# We use `>= c++17` here so that std::string_view is used.
-DCMAKE_CXX_STANDARD=20
-DABSL_ENABLE_INSTALL=TRUE
-DABSL_USE_EXTERNAL_GOOGLETEST=ON
-DABSL_PROPAGATE_CXX_STD=TRUE
# ChromeOS: Enable building a monolithic libabseil_dll.so which
# significantly reduces the overhead of symbol resolution
# inside ld.so. See go/cros-absl-monolithic-so for a complete
# explanation and benchmark numbers.
-DABSL_BUILD_MONOLITHIC_SHARED_LIBS=ON
-DABSL_BUILD_TEST_HELPERS=$(usex test ON OFF)
-DABSL_BUILD_TESTING=$(usex test ON OFF)
$(usex test -DBUILD_TESTING=ON '') # intentional usex, it used both variables for tests.
)
cmake_src_configure
}
multilib_src_compile() {
cmake_src_compile
sed -e "s/@LIBS@/-labseil_dll/g" -e "s/@PV@/${PV}/g" \
"${FILESDIR}/absl.pc.in" > absl.pc || die
}
multilib_src_install() {
cmake_src_install
insinto "/usr/$(get_libdir)/pkgconfig"
doins absl.pc
# Compat symlinks from old separate .so files to monolithic libabseil_dll.so.
# This is needed for two use cases:
# - Packages that passes -labsl_foo flags directly, instead of using pkg-config or CMake.
# - Gradual migration of binpkgs or partner packages until they get rebuilt.
local targets=( "${D}/usr/$(get_libdir)/pkgconfig/"absl_*.pc )
local t libname
for t in "${targets[@]}"; do
libname="lib$(basename "${t}" .pc).so"
ln -sv "libabseil_dll.so.${SOVERSION}" "${D}/usr/$(get_libdir)/${libname}" || die
ln -sv "libabseil_dll.so.${SOVERSION}" "${D}/usr/$(get_libdir)/${libname}.${SOVERSION}" || die
done
# absl adds all the Cflags to all the pc files even though almost all the
# .pc files require absl_config.pc. This causes an explosion of flags when
# including multiple abseil sub-libraries through pkg-config. Until the
# issue is fixed upstream, strip them out here since this is easier to
# maintain than a version specific patch.
find "${D}/usr/$(get_libdir)/pkgconfig" -type f -not -name 'absl_config.pc' -print0 | xargs -0 sed -i '/^Cflags: /d' || die
}