Add RUST_SUPPORTED_CODEGEN_BACKENDS for ebuilds to declare which codegen
backends they support. By default, this is the same as RUST_CODEGEN_BACKENDS
(so 'llvm' and 'gcc'). ebuilds can set RUST_SUPPORTED_CODEGEN_BACKENDS=( llvm )
to workaround bugs with alternative backends.

As future work, we can modify RUSTFLAGS to pass -Zcodegen-backend=PATH or
perhaps introduce another USE_EXPAND (bleh) to allow users to control the
default to determine when we need to pass that (the first codegen backend
specified when building Rust is the default). This is complicated by the fact
I'm not sure all Rust packages really respect RUSTFLAGS fully, see e.g.
bug #959723.

The priority at this time is to avoid disruption and facilitate experimenting.

TL;DR:
* If you want to use the GCC backend, either disable the LLVM one too by
  setting RUST_CODEGEN_BACKENDS, or pass -Zcodegen-backend=PATH in RUSTFLAGS.
* I hope we can make rust.eclass handle this in some more advanced way
  in future.

Bug: https://bugs.gentoo.org/959723
Bug: https://bugs.gentoo.org/965182
Signed-off-by: Sam James <[email protected]>
---
 eclass/rust.eclass | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/eclass/rust.eclass b/eclass/rust.eclass
index b5a992199dce1..6feed1eade16b 100644
--- a/eclass/rust.eclass
+++ b/eclass/rust.eclass
@@ -178,6 +178,13 @@ declare -a -g -r _RUST_SLOTS_ORDERED=(
 # an invalid combination of RUST and LLVM slots is detected; this probably
 # means that a LLVM slot in LLVM_COMPAT has had all of its Rust slots filtered.
 
+# @ECLASS_VARIABLE: RUST_SUPPORTED_CODEGEN_BACKENDS
+# @DESCRIPTION:
+# Defaults to all values of RUST_CODEGEN_BACKENDS. Can be defined as an
+# array as a subset of these to workaround bugs in alternative, upcoming
+# codegen backends.
+[[ ${#RUST_SUPPORTED_CODEGEN_BACKENDS[@]} -eq 0 ]] && 
RUST_SUPPORTED_CODEGEN_BACKENDS=( llvm gcc )
+
 # @ECLASS_VARIABLE: RUST_MULTILIB
 # @DEFAULT_UNSET
 # @DESCRIPTION:
@@ -250,6 +257,18 @@ _rust_set_globals() {
        _RUST_SLOTS=( "${_RUST_SLOTS[@]}" )
        readonly _RUST_SLOTS
 
+       # This will usually be the full set of supported backends, but
+       # on occasion, will be restricted to just 'llvm'.
+       local backend backend_usedep_joined
+       local backend_usedep=()
+       for backend in "${RUST_SUPPORTED_CODEGEN_BACKENDS[@]}" ; do
+               backend_usedep+=( "rust_codegen_backend_${backend}(+)" )
+       done
+       printf -v backend_usedep_joined "%s," "${backend_usedep[@]}"
+       # Strip trailing comma
+       backend_usedep_joined=${backend_usedep_joined%,}
+       RUST_REQ_USE+="${backend_usedep_joined}"
+
        local rust_dep=()
        local llvm_slot
        local rust_slot
-- 
2.51.2


Reply via email to