[v2,1/2] do not add cross profile when building native package

Message ID 20251104154448.2737940-1-felix.moessbauer@siemens.com
State Superseded
Headers show
Series [v2,1/2] do not add cross profile when building native package | expand

Commit Message

MOESSBAUER, Felix Nov. 4, 2025, 3:44 p.m. UTC
When building a -native package, the cross profile must not be added as
otherwise stricter apt cache checks added in trixie trigger. It anyways
makes no sense to add the cross profile when BUILD_ARCH equals
PACKAGE_ARCH. Previously this check was implemented incorrectly, as the
build arch was compared to the DISTRO_ARCH, which is always the target
arch in isar terms. This resulted in the following error message in
sbuild:

 E: The package cache was built for different architectures: amd64 vs arm64
 W: You may want to run apt-get update to correct these problems
 E: The package cache file is corrupted
 E: apt-get dist-upgrade failed

On bookworm, the incorrect check remained unnoticed, as apt did not have
the stricter checks yet.

Fixes: 872ef2e3 ("dpkg-base: Fix enabling of cross build profile")
Tested-by: Benedikt Niedermayr <benedikt.niedermayr@siemens.com>
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/classes/dpkg-base.bbclass             | 2 +-
 meta/recipes-kernel/linux/linux-custom.inc | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Jan Kiszka Nov. 4, 2025, 4:19 p.m. UTC | #1
On 04.11.25 16:44, Felix Moessbauer wrote:
> When building a -native package, the cross profile must not be added as
> otherwise stricter apt cache checks added in trixie trigger. It anyways
> makes no sense to add the cross profile when BUILD_ARCH equals
> PACKAGE_ARCH. Previously this check was implemented incorrectly, as the
> build arch was compared to the DISTRO_ARCH, which is always the target
> arch in isar terms. This resulted in the following error message in
> sbuild:
> 
>  E: The package cache was built for different architectures: amd64 vs arm64
>  W: You may want to run apt-get update to correct these problems
>  E: The package cache file is corrupted
>  E: apt-get dist-upgrade failed
> 
> On bookworm, the incorrect check remained unnoticed, as apt did not have
> the stricter checks yet.
> 
> Fixes: 872ef2e3 ("dpkg-base: Fix enabling of cross build profile")
> Tested-by: Benedikt Niedermayr <benedikt.niedermayr@siemens.com>
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>  meta/classes/dpkg-base.bbclass             | 2 +-
>  meta/recipes-kernel/linux/linux-custom.inc | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass
> index 4468a49a..d8287e8d 100644
> --- a/meta/classes/dpkg-base.bbclass
> +++ b/meta/classes/dpkg-base.bbclass
> @@ -146,7 +146,7 @@ dpkg_runbuild() {
>  
>  def isar_deb_build_profiles(d):
>      deb_build_profiles = d.getVar('DEB_BUILD_PROFILES')
> -    if d.getVar('BUILD_ARCH') != d.getVar('DISTRO_ARCH'):
> +    if d.getVar('BUILD_ARCH') != d.getVar('PACKAGE_ARCH'):
>          deb_build_profiles += ' cross'
>      return deb_build_profiles.strip()
>  
> diff --git a/meta/recipes-kernel/linux/linux-custom.inc b/meta/recipes-kernel/linux/linux-custom.inc
> index f2892921..01398697 100644
> --- a/meta/recipes-kernel/linux/linux-custom.inc
> +++ b/meta/recipes-kernel/linux/linux-custom.inc
> @@ -109,7 +109,7 @@ KERNEL_NAME_PROVIDED ?= "${@ d.getVar('BPN').partition('linux-')[2]}"
>  
>  # Determine cross-profile override
>  python() {
> -    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")) and "class-native" not in d.getVar("OVERRIDES").split(":"):
> +    if d.getVar('BUILD_ARCH') != d.getVar('PACKAGE_ARCH') and bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")) and "class-native" not in d.getVar("OVERRIDES").split(":"):
>          d.appendVar("OVERRIDES", ":cross-profile")
>  }
>  

This looks like a separate patch, even if a dependency for this one. Or
would fixing linux-custom.inc not be possible before fixing dpkg-base?

Jan
MOESSBAUER, Felix Nov. 4, 2025, 6:24 p.m. UTC | #2
On Tue, 2025-11-04 at 17:19 +0100, Jan Kiszka wrote:
> On 04.11.25 16:44, Felix Moessbauer wrote:
> > When building a -native package, the cross profile must not be added as
> > otherwise stricter apt cache checks added in trixie trigger. It anyways
> > makes no sense to add the cross profile when BUILD_ARCH equals
> > PACKAGE_ARCH. Previously this check was implemented incorrectly, as the
> > build arch was compared to the DISTRO_ARCH, which is always the target
> > arch in isar terms. This resulted in the following error message in
> > sbuild:
> > 
> >  E: The package cache was built for different architectures: amd64 vs arm64
> >  W: You may want to run apt-get update to correct these problems
> >  E: The package cache file is corrupted
> >  E: apt-get dist-upgrade failed
> > 
> > On bookworm, the incorrect check remained unnoticed, as apt did not have
> > the stricter checks yet.
> > 
> > Fixes: 872ef2e3 ("dpkg-base: Fix enabling of cross build profile")
> > Tested-by: Benedikt Niedermayr <benedikt.niedermayr@siemens.com>
> > Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> > ---
> >  meta/classes/dpkg-base.bbclass             | 2 +-
> >  meta/recipes-kernel/linux/linux-custom.inc | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass
> > index 4468a49a..d8287e8d 100644
> > --- a/meta/classes/dpkg-base.bbclass
> > +++ b/meta/classes/dpkg-base.bbclass
> > @@ -146,7 +146,7 @@ dpkg_runbuild() {
> >  
> >  def isar_deb_build_profiles(d):
> >      deb_build_profiles = d.getVar('DEB_BUILD_PROFILES')
> > -    if d.getVar('BUILD_ARCH') != d.getVar('DISTRO_ARCH'):
> > +    if d.getVar('BUILD_ARCH') != d.getVar('PACKAGE_ARCH'):
> >          deb_build_profiles += ' cross'
> >      return deb_build_profiles.strip()
> >  
> > diff --git a/meta/recipes-kernel/linux/linux-custom.inc b/meta/recipes-kernel/linux/linux-custom.inc
> > index f2892921..01398697 100644
> > --- a/meta/recipes-kernel/linux/linux-custom.inc
> > +++ b/meta/recipes-kernel/linux/linux-custom.inc
> > @@ -109,7 +109,7 @@ KERNEL_NAME_PROVIDED ?= "${@ d.getVar('BPN').partition('linux-')[2]}"
> >  
> >  # Determine cross-profile override
> >  python() {
> > -    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")) and "class-native" not in d.getVar("OVERRIDES").split(":"):
> > +    if d.getVar('BUILD_ARCH') != d.getVar('PACKAGE_ARCH') and bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")) and "class-native" not in d.getVar("OVERRIDES").split(":"):
> >          d.appendVar("OVERRIDES", ":cross-profile")
> >  }
> >  
> 
> This looks like a separate patch, even if a dependency for this one. Or
> would fixing linux-custom.inc not be possible before fixing dpkg-base?

This needs to be fixed in a lockstep, as otherwise the :cross-profile
override and the DEB_BUILD_PROFILE = cross are not in sync.

Felix

> 
> Jan
> 
> -- 
> Siemens AG, Foundational Technologies
> Linux Expert Center
MOESSBAUER, Felix Nov. 6, 2025, 8:47 a.m. UTC | #3
On Tue, 2025-11-04 at 16:44 +0100, Felix Moessbauer wrote:
> When building a -native package, the cross profile must not be added as
> otherwise stricter apt cache checks added in trixie trigger. It anyways
> makes no sense to add the cross profile when BUILD_ARCH equals
> PACKAGE_ARCH. Previously this check was implemented incorrectly, as the
> build arch was compared to the DISTRO_ARCH, which is always the target
> arch in isar terms. This resulted in the following error message in
> sbuild:
> 
>  E: The package cache was built for different architectures: amd64 vs arm64
>  W: You may want to run apt-get update to correct these problems
>  E: The package cache file is corrupted
>  E: apt-get dist-upgrade failed
> 
> On bookworm, the incorrect check remained unnoticed, as apt did not have
> the stricter checks yet.
> 
> Fixes: 872ef2e3 ("dpkg-base: Fix enabling of cross build profile")
> Tested-by: Benedikt Niedermayr <benedikt.niedermayr@siemens.com>
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>  meta/classes/dpkg-base.bbclass             | 2 +-
>  meta/recipes-kernel/linux/linux-custom.inc | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass
> index 4468a49a..d8287e8d 100644
> --- a/meta/classes/dpkg-base.bbclass
> +++ b/meta/classes/dpkg-base.bbclass
> @@ -146,7 +146,7 @@ dpkg_runbuild() {
>  
>  def isar_deb_build_profiles(d):
>      deb_build_profiles = d.getVar('DEB_BUILD_PROFILES')
> -    if d.getVar('BUILD_ARCH') != d.getVar('DISTRO_ARCH'):
> +    if d.getVar('BUILD_ARCH') != d.getVar('PACKAGE_ARCH'):
>          deb_build_profiles += ' cross'
>      return deb_build_profiles.strip()
>  
> diff --git a/meta/recipes-kernel/linux/linux-custom.inc b/meta/recipes-kernel/linux/linux-custom.inc
> index f2892921..01398697 100644
> --- a/meta/recipes-kernel/linux/linux-custom.inc
> +++ b/meta/recipes-kernel/linux/linux-custom.inc
> @@ -109,7 +109,7 @@ KERNEL_NAME_PROVIDED ?= "${@ d.getVar('BPN').partition('linux-')[2]}"
>  
>  # Determine cross-profile override
>  python() {
> -    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")) and "class-native" not in d.getVar("OVERRIDES").split(":"):
> +    if d.getVar('BUILD_ARCH') != d.getVar('PACKAGE_ARCH') and bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")) and "class-native" not in d.getVar("OVERRIDES").split(":"):
>          d.appendVar("OVERRIDES", ":cross-profile")

I again see the same build error as reported by ... in the v1, but I
can only reproduce it in 100% clean CI runs with just that target. To
me it looks like the linux-kbuild-phy:arm64 package is still lingering
around in some cache which hides the error.

Anyways, back to the error:

I'm pretty sure we now model the build-dependency chain of packages
correctly, however it looks like the build of the kbuild-<kernel>
package has logical errors:

Currently, the linux-kbuild-phy is generated from linux-phy-native, but
for the host architecture (instead of the target architecture). This is
correct from bitbake perspective, but incorrect from debian
perspective, as the module needs the kbuild-<> package for the target
architecture.

IOW, currently we have the following situation:

- linux-<name> generates the image and headers for the target arch
(arm64)
- linux-<name>-native generates the kbuild package in the host arch
(amd64)

All that is correct, but not helpful. In the past, we generated an
architecture specific package from a -native recipe - which IMHO is
plain wrong.

To move forward, someone familiar with the linux-custom recipe needs to
have a look and model the overrides correctly. We further need to
clearly state which profile does what in human readable terms.

Felix

>  }
>  
> -- 
> 2.51.0

Patch

diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass
index 4468a49a..d8287e8d 100644
--- a/meta/classes/dpkg-base.bbclass
+++ b/meta/classes/dpkg-base.bbclass
@@ -146,7 +146,7 @@  dpkg_runbuild() {
 
 def isar_deb_build_profiles(d):
     deb_build_profiles = d.getVar('DEB_BUILD_PROFILES')
-    if d.getVar('BUILD_ARCH') != d.getVar('DISTRO_ARCH'):
+    if d.getVar('BUILD_ARCH') != d.getVar('PACKAGE_ARCH'):
         deb_build_profiles += ' cross'
     return deb_build_profiles.strip()
 
diff --git a/meta/recipes-kernel/linux/linux-custom.inc b/meta/recipes-kernel/linux/linux-custom.inc
index f2892921..01398697 100644
--- a/meta/recipes-kernel/linux/linux-custom.inc
+++ b/meta/recipes-kernel/linux/linux-custom.inc
@@ -109,7 +109,7 @@  KERNEL_NAME_PROVIDED ?= "${@ d.getVar('BPN').partition('linux-')[2]}"
 
 # Determine cross-profile override
 python() {
-    if d.getVar("DISTRO_ARCH") != d.getVar("HOST_ARCH") and bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")) and "class-native" not in d.getVar("OVERRIDES").split(":"):
+    if d.getVar('BUILD_ARCH') != d.getVar('PACKAGE_ARCH') and bb.utils.to_boolean(d.getVar("ISAR_CROSS_COMPILE")) and "class-native" not in d.getVar("OVERRIDES").split(":"):
         d.appendVar("OVERRIDES", ":cross-profile")
 }