From e49f2f7283e1d9f18e2f5f54647c07287cd70339 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 21 Jul 2025 19:30:10 +0200 Subject: build: allow picking 'rust' as a link_language rustc only needs to be a linker if there are any Rust-ABI dependencies. Skip it whenever linking to a C-ABI dependency. This makes it possible for Meson to pick 'rust' whenever it sees Rust sources, but not whenever it sees Rust used by a dependency with "rust_abi: 'c'". Signed-off-by: Paolo Bonzini --- mesonbuild/build.py | 7 +++++++ mesonbuild/compilers/compilers.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index fcdb7925f..4f581de31 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -885,6 +885,10 @@ class BuildTarget(Target): if isinstance(t, (CustomTarget, CustomTargetIndex)): continue # We can't know anything about these. for name, compiler in t.compilers.items(): + if name == 'rust': + # Rust is always linked through a C-ABI target, so do not add + # the compiler here + continue if name in link_langs and name not in self.compilers: self.compilers[name] = compiler @@ -1600,6 +1604,9 @@ class BuildTarget(Target): if isinstance(link_target, (CustomTarget, CustomTargetIndex)): continue for language in link_target.compilers: + if language == 'rust' and not link_target.uses_rust_abi(): + # All Rust dependencies must go through a C-ABI dependency, so ignore it + continue if language not in langs: langs.append(language) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 5915790d0..3b7f066f7 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -84,7 +84,7 @@ clib_langs = ('objcpp', 'cpp', 'objc', 'c', 'nasm', 'fortran') # List of languages that can be linked with C code directly by the linker # used in build.py:process_compilers() and build.py:get_dynamic_linker() # This must be sorted, see sort_clink(). -clink_langs = ('d', 'cuda') + clib_langs +clink_langs = ('rust', 'd', 'cuda') + clib_langs SUFFIX_TO_LANG = dict(itertools.chain(*( [(suffix, lang) for suffix in v] for lang, v in lang_suffixes.items()))) -- cgit v1.2.3