From: Eli Schwartz <eschwartz93@gmail.com>
To: gentoo-dev@lists.gentoo.org
Subject: [gentoo-dev] [PATCH 1/3] meson.eclass: wire up LTO support directly into the meson options
Date: Mon, 19 Feb 2024 23:26:47 -0500 [thread overview]
Message-ID: <20240220043235.3889132-2-eschwartz93@gmail.com> (raw)
In-Reply-To: <20240220043235.3889132-1-eschwartz93@gmail.com>
meson's builtin LTO support allows meson to introspect whether LTO is
enabled and do some fancy things, such as forcing LTO off for a single
target that is known to be special(ly bad) and not support LTO.
Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
---
eclass/meson.eclass | 36 ++++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/eclass/meson.eclass b/eclass/meson.eclass
index d8bd93082ea5..c2ae289019e9 100644
--- a/eclass/meson.eclass
+++ b/eclass/meson.eclass
@@ -41,7 +41,7 @@ esac
if [[ -z ${_MESON_ECLASS} ]]; then
_MESON_ECLASS=1
-inherit multiprocessing ninja-utils python-utils-r1 toolchain-funcs
+inherit flag-o-matic multiprocessing ninja-utils python-utils-r1 toolchain-funcs
BDEPEND=">=dev-build/meson-1.2.1
${NINJA_DEPEND}
@@ -286,6 +286,36 @@ meson_src_configure() {
[[ -n "${NINJA_DEPEND}" ]] || ewarn "Unknown value '${NINJA}' for \${NINJA}"
+ local ltoflags=()
+ if tc-is-lto; then
+ # We want to connect -flto in *FLAGS to the dedicated meson option,
+ # to ensure that meson has visibility into what the user set. Although
+ # it is unlikely projects will check `get_option('b_lto')` and change
+ # their behavior, individual targets which are broken with LTO can
+ # disable it per target. Injecting via *FLAGS means that meson cannot
+ # strip -flto from that target.
+ ltoflags+=( -Db_lto=true )
+
+ # respect -flto value, e.g. -flto=8, -flto=thin
+ local v=$(get-flag flto)
+ case ${v} in
+ thin)
+ ltoflags+=( -Db_lto_mode=thin )
+ ;;
+ ''|*[!0-9]*)
+ ;;
+ *) ltoflags+=( -Db_lto_threads=${v} )
+ esac
+ # finally, remove it from *FLAGS to avoid passing it:
+ # - twice, with potentially different values
+ # - on excluded targets
+ filter-lto
+ else
+ # Prevent projects from enabling LTO by default. In Gentoo, LTO is
+ # enabled via setting *FLAGS appropriately.
+ ltoflags+=( -Db_lto=false )
+ fi
+
local BUILD_CFLAGS=${BUILD_CFLAGS}
local BUILD_CPPFLAGS=${BUILD_CPPFLAGS}
local BUILD_CXXFLAGS=${BUILD_CXXFLAGS}
@@ -335,9 +365,7 @@ meson_src_configure() {
# an upstream development matter. bug #754279.
-Dwerror=false
- # Prevent projects from enabling LTO by default. In Gentoo, LTO is
- # enabled via setting *FLAGS appropriately.
- -Db_lto=false
+ "${ltoflags[@]}"
)
if [[ -n ${EMESON_BUILDTYPE} ]]; then
--
2.43.0
next prev parent reply other threads:[~2024-02-20 4:33 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-20 4:26 [gentoo-dev] [PATCH 0/3] eclass updates for meson <> distutils <> LTO Eli Schwartz
2024-02-20 4:26 ` Eli Schwartz [this message]
2024-02-20 5:58 ` [gentoo-dev] [PATCH 1/3] meson.eclass: wire up LTO support directly into the meson options Mike Gilbert
2024-02-20 6:09 ` Eli Schwartz
2024-02-20 6:24 ` Mike Gilbert
2024-02-20 6:33 ` Eli Schwartz
2024-02-20 6:37 ` Eli Schwartz
2024-02-20 6:40 ` Sam James
2024-02-20 4:26 ` [gentoo-dev] [PATCH 2/3] distutils-r1.eclass: wire up meson-python to meson.eclass Eli Schwartz
2024-02-20 4:42 ` Sam James
2024-02-20 5:12 ` Eli Schwartz
2024-02-20 6:14 ` [gentoo-dev] [PATCH v2 0/5] eclass updates for meson <> distutils <> LTO Eli Schwartz
2024-02-20 6:14 ` [gentoo-dev] [PATCH v2 1/5] meson.eclass: wire up LTO support directly into the meson options Eli Schwartz
2024-02-20 6:14 ` [gentoo-dev] [PATCH v2 2/5] meson.eclass: prefer -D buildtype instead of --buildtype Eli Schwartz
2024-02-20 6:14 ` [gentoo-dev] [PATCH v2 3/5] meson.eclass: refactor src_configure into a setter function Eli Schwartz
2024-02-20 6:42 ` [gentoo-dev] " Eli Schwartz
2024-02-20 6:14 ` [gentoo-dev] [PATCH v2 4/5] distutils-r1.eclass: wire up meson-python to meson.eclass Eli Schwartz
2024-02-20 6:55 ` Michał Górny
2024-02-20 20:45 ` Eli Schwartz
2024-02-20 6:14 ` [gentoo-dev] [PATCH v2 5/5] distutils-r1.eclass: fix src_configure to handle flag-o-matic correctly Eli Schwartz
2024-02-20 6:28 ` [gentoo-dev] [PATCH 2/3] distutils-r1.eclass: wire up meson-python to meson.eclass Michał Górny
2024-02-20 4:26 ` [gentoo-dev] [PATCH 3/3] distutils-r1.eclass: fix src_configure to handle flag-o-matic correctly Eli Schwartz
2024-02-20 6:35 ` Michał Górny
2024-02-20 4:41 ` [gentoo-dev] [PATCH 0/3] eclass updates for meson <> distutils <> LTO Sam James
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240220043235.3889132-2-eschwartz93@gmail.com \
--to=eschwartz93@gmail.com \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox