commit: 00df4cfd6749850a1e2dc15702f666042c8f889a
Author: James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Thu Jan 8 10:05:49 2026 +0000
Commit: James Le Cuirot <chewi <AT> gentoo <DOT> org>
CommitDate: Thu Jan 8 22:54:14 2026 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=00df4cfd
meson.eclass: Set rust and bindgen_clang_arguments fields in ini files
This is needed for cross-compiling and multilib. It also allows us to
respect the chosen linker and LDFLAGS like cargo.eclass does. Meson
actually handles this better than Cargo (without nightly features)
because it can apply these to both the native config and the cross
config.
rust-toolchain.eclass is needed in the cross case, but this no longer
supports EAPI 7. There are no EAPI 7 packages using Rust with Meson, so
we can conditionally inherit it.
I'm not 100% sure whether bindgen_clang_arguments needs further work for
cross-compiling (as opposed to multilib), but it doesn't look like it.
Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>
eclass/meson.eclass | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/eclass/meson.eclass b/eclass/meson.eclass
index c0c4be1a9019..d43eccaa5cc7 100644
--- a/eclass/meson.eclass
+++ b/eclass/meson.eclass
@@ -1,4 +1,4 @@
-# Copyright 2017-2025 Gentoo Authors
+# Copyright 2017-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: meson.eclass
@@ -42,6 +42,7 @@ if [[ -z ${_MESON_ECLASS} ]]; then
_MESON_ECLASS=1
inherit flag-o-matic multiprocessing ninja-utils python-utils-r1 sysroot
toolchain-funcs
+[[ ${EAPI} != 7 ]] && inherit rust-toolchain
BDEPEND=">=dev-build/meson-1.2.3
${NINJA_DEPEND}
@@ -149,6 +150,16 @@ _meson_create_cross_file() {
_meson_get_machine_info "${CHOST}"
local fn=${T}/meson.${CHOST}.${ABI}.ini
+ local CFLAGS_ABI=CFLAGS_${ABI:-${DEFAULT_ABI}}
+
+ if has rust-toolchain ${INHERITED}; then
+ local LD_A=( $(tc-getCC) ${LDFLAGS} )
+ local RUSTC=( rustc --target="$(rust_abi)"
--codegen=linker="${LD_A[0]}" )
+ LD_A=( "${LD_A[@]:1}" )
+ [[ ${LD_A[@]} ]] && RUSTC+=( "${LD_A[@]/#/--codegen=link-arg=}"
)
+ else
+ unset RUSTC
+ fi
cat > "${fn}" <<-EOF || die "failed to create cross file"
[binaries]
@@ -166,6 +177,7 @@ _meson_create_cross_file() {
# >=1.3.0.
pkgconfig = '$(tc-getPKG_CONFIG)'
pkg-config = '$(tc-getPKG_CONFIG)'
+ rust = $(_meson_env_array "${RUSTC[@]@Q}")
strip = $(_meson_env_array "$(tc-getSTRIP)")
windres = $(_meson_env_array "$(tc-getRC)")
@@ -183,8 +195,9 @@ _meson_create_cross_file() {
[properties]
needs_exe_wrapper = $(tc-is-cross-compiler && echo true || echo false)
- sys_root = '${SYSROOT}'
pkg_config_libdir =
'${PKG_CONFIG_LIBDIR:-${EPREFIX}/usr/$(get_libdir)/pkgconfig}'
+ bindgen_clang_arguments = $(_meson_env_array "${!CFLAGS_ABI}")
+ sys_root = '${SYSROOT}'
[host_machine]
system = '${system}'
@@ -208,6 +221,11 @@ _meson_create_native_file() {
local fn=${T}/meson.${CBUILD}.ini
+ local LD_A=( $(tc-getBUILD_CC) ${BUILD_LDFLAGS} )
+ local RUSTC=( rustc --codegen=linker="${LD_A[0]}" )
+ LD_A=( "${LD_A[@]:1}" )
+ [[ ${LD_A[@]} ]] && RUSTC+=( "${LD_A[@]/#/--codegen=link-arg=}" )
+
cat > "${fn}" <<-EOF || die "failed to create native file"
[binaries]
ar = $(_meson_env_array "$(tc-getBUILD_AR)")
@@ -223,6 +241,7 @@ _meson_create_native_file() {
# >=1.3.0.
pkgconfig = '$(tc-getBUILD_PKG_CONFIG)'
pkg-config = '$(tc-getBUILD_PKG_CONFIG)'
+ rust = $(_meson_env_array "${RUSTC[@]@Q}")
strip = $(_meson_env_array "$(tc-getBUILD_STRIP)")
windres = $(_meson_env_array "$(tc-getBUILD_PROG RC windres)")