From e9189344b971f7ee0e2bec36650c57dbade4f122 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 20 Feb 2024 00:53:34 -0500 Subject: [PATCH 1/3] meson.eclass: refactor src_configure into a setter function This is necessary in order to get at the implementation of `meson setup` from other eclasses, which do not simply call meson_src_configure. The intended use case is distutils-r1, where a python build backend wraps meson and needs its arguments while calling meson on its own. This allows distutils-r1 to invoke `setup_meson_src_configure` followed by gpep517, and get access to: - the preparation which needs to be done, including setting up the environment - the array of setup arguments Signed-off-by: Eli Schwartz Signed-off-by: Sam James --- eclass/meson.eclass | 55 ++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/eclass/meson.eclass b/eclass/meson.eclass index d8bd93082ea55..629bf3be4f2e8 100644 --- a/eclass/meson.eclass +++ b/eclass/meson.eclass @@ -277,15 +277,12 @@ meson_feature() { usex "$1" "-D${2-$1}=enabled" "-D${2-$1}=disabled" } -# @FUNCTION: meson_src_configure -# @USAGE: [extra meson arguments] +# @FUNCTION: setup_meson_src_configure # @DESCRIPTION: -# This is the meson_src_configure function. -meson_src_configure() { - debug-print-function ${FUNCNAME} "$@" - - [[ -n "${NINJA_DEPEND}" ]] || ewarn "Unknown value '${NINJA}' for \${NINJA}" - +# Calculate the command line which meson should use, and other relevant +# variables. Invoke via "${MESONARGS[@]}" in the calling environment. +# This function is called from meson_src_configure. +setup_meson_src_configure() { local BUILD_CFLAGS=${BUILD_CFLAGS} local BUILD_CPPFLAGS=${BUILD_CPPFLAGS} local BUILD_CXXFLAGS=${BUILD_CXXFLAGS} @@ -314,8 +311,7 @@ meson_src_configure() { : "${BUILD_PKG_CONFIG_PATH:=${PKG_CONFIG_PATH}}" fi - local mesonargs=( - meson setup + MESONARGS=( --libdir "$(get_libdir)" --localstatedir "${EPREFIX}/var/lib" --prefix "${EPREFIX}/usr" @@ -341,11 +337,11 @@ meson_src_configure() { ) if [[ -n ${EMESON_BUILDTYPE} ]]; then - mesonargs+=( --buildtype "${EMESON_BUILDTYPE}" ) + MESONARGS+=( --buildtype "${EMESON_BUILDTYPE}" ) fi if tc-is-cross-compiler; then - mesonargs+=( --cross-file "$(_meson_create_cross_file)" ) + MESONARGS+=( --cross-file "$(_meson_create_cross_file)" ) fi BUILD_DIR="${BUILD_DIR:-${WORKDIR}/${P}-build}" @@ -353,7 +349,7 @@ meson_src_configure() { # Handle quoted whitespace eval "local -a MYMESONARGS=( ${MYMESONARGS} )" - mesonargs+=( + MESONARGS+=( # Arguments from ebuild "${emesonargs[@]}" @@ -362,12 +358,6 @@ meson_src_configure() { # Arguments from user "${MYMESONARGS[@]}" - - # Source directory - "${EMESON_SOURCE:-${S}}" - - # Build directory - "${BUILD_DIR}" ) # Used by symbolextractor.py @@ -379,13 +369,32 @@ meson_src_configure() { python_export_utf8_locale # https://bugs.gentoo.org/721786 - local -x BOOST_INCLUDEDIR="${BOOST_INCLUDEDIR-${EPREFIX}/usr/include}" - local -x BOOST_LIBRARYDIR="${BOOST_LIBRARYDIR-${EPREFIX}/usr/$(get_libdir)}" + export BOOST_INCLUDEDIR="${BOOST_INCLUDEDIR-${EPREFIX}/usr/include}" + export BOOST_LIBRARYDIR="${BOOST_LIBRARYDIR-${EPREFIX}/usr/$(get_libdir)}" +} + +# @FUNCTION: meson_src_configure +# @USAGE: [extra meson arguments] +# @DESCRIPTION: +# This is the meson_src_configure function. +meson_src_configure() { + debug-print-function ${FUNCNAME} "$@" + + [[ -n "${NINJA_DEPEND}" ]] || ewarn "Unknown value '${NINJA}' for \${NINJA}" ( + setup_meson_src_configure "$@" + MESONARGS+=( + # Source directory + "${EMESON_SOURCE:-${S}}" + + # Build directory + "${BUILD_DIR}" + ) + export -n {C,CPP,CXX,F,OBJC,OBJCXX,LD}FLAGS PKG_CONFIG_{LIBDIR,PATH} - echo "${mesonargs[@]}" >&2 - "${mesonargs[@]}" + echo meson setup "${MESONARGS[@]}" >&2 + meson setup "${MESONARGS[@]}" ) || die } From 5e7b32c59d53f8240dfd7a17e31fc533fa811f75 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 16 Jan 2024 00:43:58 -0500 Subject: [PATCH 2/3] meson.eclass: wire up LTO support directly into the meson options 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 Signed-off-by: Sam James --- eclass/meson.eclass | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/eclass/meson.eclass b/eclass/meson.eclass index 629bf3be4f2e8..b24bb40eb0a0f 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} @@ -283,6 +283,38 @@ meson_feature() { # variables. Invoke via "${MESONARGS[@]}" in the calling environment. # This function is called from meson_src_configure. setup_meson_src_configure() { + MESONARGS=() + 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. + MESONARGS+=( -Db_lto=true ) + + # respect -flto value, e.g. -flto=8, -flto=thin + local v=$(get-flag flto) + case ${v} in + thin) + MESONARGS+=( -Db_lto_mode=thin ) + ;; + ''|*[!0-9]*) + ;; + *) + MESONARGS+=( -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. + MESONARGS+=( -Db_lto=false ) + fi + local BUILD_CFLAGS=${BUILD_CFLAGS} local BUILD_CPPFLAGS=${BUILD_CPPFLAGS} local BUILD_CXXFLAGS=${BUILD_CXXFLAGS} @@ -311,7 +343,7 @@ setup_meson_src_configure() { : "${BUILD_PKG_CONFIG_PATH:=${PKG_CONFIG_PATH}}" fi - MESONARGS=( + MESONARGS+=( --libdir "$(get_libdir)" --localstatedir "${EPREFIX}/var/lib" --prefix "${EPREFIX}/usr" @@ -331,9 +363,7 @@ setup_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 From b95ea11330e446d0deb89ca7d78356cb2a7d0d06 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 20 Feb 2024 00:39:51 -0500 Subject: [PATCH 3/3] meson.eclass: prefer -D buildtype instead of --buildtype Because that is the logic which meson-python hardcodes, and meson needs to match calling convention. Signed-off-by: Eli Schwartz Closes: https://github.com/gentoo/gentoo/pull/35528 Signed-off-by: Sam James --- eclass/meson.eclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eclass/meson.eclass b/eclass/meson.eclass index b24bb40eb0a0f..9e877be53309c 100644 --- a/eclass/meson.eclass +++ b/eclass/meson.eclass @@ -367,7 +367,7 @@ setup_meson_src_configure() { ) if [[ -n ${EMESON_BUILDTYPE} ]]; then - MESONARGS+=( --buildtype "${EMESON_BUILDTYPE}" ) + MESONARGS+=( -Dbuildtype="${EMESON_BUILDTYPE}" ) fi if tc-is-cross-compiler; then