From 0d7358b2483e1af4c75b1c0dce729292ffa4fbcc Mon Sep 17 00:00:00 2001
From: Anders Roxell <anders.roxell@linaro.org>
Date: Tue, 9 Dec 2025 09:20:32 +0100
Subject: [PATCH 2/8] kbuild: Add tuxmake backend support

KernelCI needed to support tuxmake, a thin wrapper around the kernel
build system that provides consistent toolchain handling and build
configuration.

Implemented _build_with_tuxmake() method that uses tuxmake with
--runtime=null to build kernel and modules. Added USE_TUXMAKE=1
environment variable for backward compatibility. TuxMake accepts
the same toolchain identifiers as KernelCI, so no mapping needed.
Both backends share the same artifact packaging methods.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 kernelci/kbuild.py | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/kernelci/kbuild.py b/kernelci/kbuild.py
index c1b050bc097b..b57974245fdf 100644
--- a/kernelci/kbuild.py
+++ b/kernelci/kbuild.py
@@ -166,6 +166,9 @@ class KBuild():
             if isinstance(self._defconfig, str) and '+' in self._defconfig:
                 self._defconfig = self._defconfig.split('+')
             self._backend = params.get('backend', 'make')
+            # Support USE_TUXMAKE environment variable for backward compatibility
+            if os.environ.get('USE_TUXMAKE') == '1':
+                self._backend = 'tuxmake'
             self._fragments = params['fragments']
             self._fragment_configs = fragment_configs or {}
             if 'coverage' in self._fragments:
@@ -640,7 +643,12 @@ trap - ERR
         print("Generating shell script")
         fragnum = self._parse_fragments(firmware=True)
         self._merge_frags(fragnum)
-        self._build_with_make()
+
+        if self._backend == 'tuxmake':
+            self._build_with_tuxmake()
+        else:
+            self._build_with_make()
+
         self._write_metadata()
         # terminate all active jobs
         self.startjob(None)
@@ -700,6 +708,26 @@ trap 'case $stage in
         else:
             self._build_dtbs_check()
 
+    def _build_with_tuxmake(self):
+        """ Build kernel using tuxmake """
+        self.startjob("build_tuxmake")
+        self.addcmd("cd " + self._srcdir)
+
+        tuxmake_cmd = (
+            f"tuxmake --runtime=null "
+            f"--target-arch={self._arch} "
+            f"--toolchain={self._compiler} "
+            f"kernel modules"
+        )
+
+        print(f"Building with tuxmake: {tuxmake_cmd}")
+        self.addcmd(tuxmake_cmd)
+        self.addcmd("cd ..")
+
+        # Package artifacts using existing methods
+        self._package_kimage()
+        self._package_modules()
+
     def _build_kernel(self):
         """ Add kernel build steps """
         self.startjob("build_kernel")
-- 
2.51.0

