commit: a4eae64aa24da57d3f6292768565ed3a4115c99a
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Nov 10 04:04:50 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Nov 16 05:50:33 2025 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a4eae64a
meson.eclass: support incremental LTO for GCC
Support -flto-incremental=/path/to/cache being used with GCC. Personally,
I am using this hook in /etc/portage/bashrc:
```
pre_src_configure() {
if [[ -n ${PORTAGE_LTO_CACHE} ]] ; then
local lto_path=/var/tmp/portage/lto/${CATEGORY}/${PN}
mkdir -p "${lto_path}"
export CFLAGS="${CFLAGS} -flto-incremental=${lto_path}
-flto-compression-level=19"
export CXXFLAGS="${CXXFLAGS} -flto-incremental=${lto_path}
-flto-compression-level=19"
export LDFLAGS="${LDFLAGS} -flto-incremental=${lto_path}
-flto-compression-level=19"
fi
}
```
... and then `PORTAGE_LTO_CACHE=1` in my development environment.
Signed-off-by: Sam James <sam <AT> gentoo.org>
eclass/meson.eclass | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/eclass/meson.eclass b/eclass/meson.eclass
index a2bc5537e458..06675e02b82b 100644
--- a/eclass/meson.eclass
+++ b/eclass/meson.eclass
@@ -1,4 +1,4 @@
-# Copyright 2017-2024 Gentoo Authors
+# Copyright 2017-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: meson.eclass
@@ -305,6 +305,18 @@ setup_meson_src_configure() {
MESONARGS+=( -Db_lto_threads=${v} )
;;
esac
+
+ if has_version -b ">=dev-build/meson-1.10.0" ; then
+ local v=$(get-flag -flto-incremental=)
+ v=${v#-flto-incremental=}
+ if [[ ${v} ]] ; then
+ MESONARGS+=(
+ -Db_thinlto_cache=true
+ -Db_thinlto_cache_dir=${v}
+ )
+ fi
+ fi
+
# finally, remove it from *FLAGS to avoid passing it:
# - twice, with potentially different values
# - on excluded targets