Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] multilib.bbclass: Check COMPATIBLE_HOST and abort early
@ 2026-11-15 22:14 Mark Hatle
  0 siblings, 0 replies; only message in thread
From: Mark Hatle @ 2026-11-15 22:14 UTC (permalink / raw)
  To: openembedded-core

The change duplicates the base.bbclass COMPATIBLE_HOST check in the
multilib.bbclass, after doing a basic expansion to quickly exit if
there is no reason to expand this recipe into a multilib.

For a baremetal SDK toolchain, there is a configuration that contains
54 multilibs.  This causes a pathalogical case of multilib expansion.

To attempt to prevent unnecessary multlib expansion, the baremetal
distribution sets:

  COMPATOS = ""
  # Set the regex for target recipes only, follow TARGET_OS default
  COMPATOS:class-target = ".*-linux${LIBCEXTENSION}${ABIEXTENSION}"
  COMPATIBLE_HOST ?= "${COMPATOS}"

Parse time still was taking almost 18 minutes.  It was determined that
the system was still expanding most recipes and then deciding the
multilib was not useful in that environment.

With the change, we now detect the COMPATIBLE_HOST sooner in the
multilib expansion and raise an exception if it should not be expanded.

This lowers the parse time down to about 90 seconds for the same
configuration.

AI-Generated: Uses GitHub Copilot
Signed-off-by: Mark Hatle <mark.hatle@amd.com>
---
The Clause via Copilot helped me determine this case.  In my baremetal
SDK for microblaze, I have a configuration with 54 multilibs defined.
This takes an exteremly long time (18 minutes or so) to parse before
any building begins.  With this change, it drops down to about 90s.

I've looked at this change, and I understand clearly what it's doing
and why, but I'm not really sure if it's right.  Also I'm not sure
if there may be additional checks that should also be done at this
point to help reduce the number of multilibs being processed when it
is not necessary.  (i.e. SKIP_RECIPE or other reasons.)

 meta/classes/multilib.bbclass | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/meta/classes/multilib.bbclass b/meta/classes/multilib.bbclass
index 55b8aee882..b178d64f7b 100644
--- a/meta/classes/multilib.bbclass
+++ b/meta/classes/multilib.bbclass
@@ -72,6 +72,27 @@ python multilib_virtclass_handler () {
             and not bb.data.inherits_class('packagegroup', d)):
         raise bb.parse.SkipRecipe("Don't extend allarch recipes which are not packagegroups")
 
+    # Apply base.bbclass's COMPATIBLE_HOST check before the setup below. That
+    # setup (e.g. expanding ALL_MULTILIB_PACKAGE_ARCHS) creates a datastore per
+    # multilib, so doing it for every variant only for base.bbclass to skip it
+    # later is quadratic in the number of multilibs and dominates parse time for
+    # configurations with many of them (e.g. baremetal toolchains). The variant's
+    # tune isn't in place yet, so evaluate HOST_SYS in a copy which has it.
+    source_mirror_fetch = bb.utils.to_boolean(d.getVar('SOURCE_MIRROR_FETCH', False)) or \
+            bb.utils.to_boolean(d.getVar('PARSE_ALL_RECIPES', False))
+    if not source_mirror_fetch:
+        mldata = bb.data.createCopy(d)
+        mldata.setVar("OVERRIDES", mldata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + variant)
+        mltune = mldata.getVar("DEFAULTTUNE:virtclass-multilib-" + variant, False)
+        if mltune:
+            mldata.setVar("DEFAULTTUNE", mltune)
+        need_host = mldata.getVar('COMPATIBLE_HOST')
+        if need_host:
+            import re
+            this_host = mldata.getVar('HOST_SYS')
+            if not re.match(need_host, this_host):
+                raise bb.parse.SkipRecipe("incompatible with host %s (not in COMPATIBLE_HOST)" % this_host)
+
     # Expand this since this won't work correctly once we set a multilib into place
     d.setVar("ALL_MULTILIB_PACKAGE_ARCHS", d.getVar("ALL_MULTILIB_PACKAGE_ARCHS"))
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-15 22:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15 22:14 [PATCH] multilib.bbclass: Check COMPATIBLE_HOST and abort early Mark Hatle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox