diff mbox series

[KINETIC] UBUNTU: [Packaging]: always use fully qualified <triplet>-gcc-VER toolchain

Message ID 20220725171513.205046-1-dimitri.ledkov@canonical.com
State New
Headers show
Series [KINETIC] UBUNTU: [Packaging]: always use fully qualified <triplet>-gcc-VER toolchain | expand

Commit Message

Dimitri John Ledkov July 25, 2022, 5:15 p.m. UTC
Always define $(gcc) variable and export it. Always use fully
qualified <triplet>-gcc-VER toolchains for native (GNU build) and
cross (GNU host) compilation. Generate matching build-dependencies for
native and cross builds.

This ensures that native and cross builds use the same fully qualified
toolchain binary, fixed in time, irrespective of gcc-defaults updates.

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
---
 debian.master/config/amd64/config.common.amd64  |  2 +-
 debian.master/config/arm64/config.common.arm64  |  2 +-
 debian.master/config/armhf/config.common.armhf  |  2 +-
 debian.master/config/config.common.ubuntu       |  6 +++---
 .../config/ppc64el/config.common.ppc64el        |  2 +-
 .../config/riscv64/config.common.riscv64        |  2 +-
 debian.master/config/s390x/config.common.s390x  |  2 +-
 debian/rules                                    |  1 +
 debian/rules.d/0-common-vars.mk                 | 17 ++++++++---------
 debian/rules.d/2-binary-arch.mk                 |  6 +-----
 debian/scripts/misc/kernelconfig                | 16 ++++++++++------
 11 files changed, 29 insertions(+), 29 deletions(-)

Comments

Andrea Righi July 26, 2022, 12:23 p.m. UTC | #1
On Mon, Jul 25, 2022 at 06:15:13PM +0100, Dimitri John Ledkov wrote:
> Always define $(gcc) variable and export it. Always use fully
> qualified <triplet>-gcc-VER toolchains for native (GNU build) and
> cross (GNU host) compilation. Generate matching build-dependencies for
> native and cross builds.
> 
> This ensures that native and cross builds use the same fully qualified
> toolchain binary, fixed in time, irrespective of gcc-defaults updates.
> 
> Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>

Applied to kinetic/linux. In this way we can still build the kernel
relying on gcc-11 for now, even if the default moved to gcc-12.

Thanks,
-Andrea
diff mbox series

Patch

diff --git a/debian.master/config/amd64/config.common.amd64 b/debian.master/config/amd64/config.common.amd64
index fbfc12054b..200e866d52 100644
--- a/debian.master/config/amd64/config.common.amd64
+++ b/debian.master/config/amd64/config.common.amd64
@@ -59,7 +59,7 @@  CONFIG_CADENCE_WATCHDOG=m
 CONFIG_CAIF=m
 CONFIG_CAN=m
 CONFIG_CB710_CORE=m
-CONFIG_CC_VERSION_TEXT="gcc (Ubuntu 11.3.0-3ubuntu1) 11.3.0"
+CONFIG_CC_VERSION_TEXT="x86_64-linux-gnu-gcc-11 (Ubuntu 11.3.0-5ubuntu1) 11.3.0"
 CONFIG_CDROM_PKTCDVD=m
 # CONFIG_CMA is not set
 CONFIG_CMDLINE_PARTITION=y
diff --git a/debian.master/config/arm64/config.common.arm64 b/debian.master/config/arm64/config.common.arm64
index 7b010d2f72..daaf5c7863 100644
--- a/debian.master/config/arm64/config.common.arm64
+++ b/debian.master/config/arm64/config.common.arm64
@@ -61,7 +61,7 @@  CONFIG_CADENCE_WATCHDOG=m
 CONFIG_CAIF=m
 CONFIG_CAN=m
 CONFIG_CB710_CORE=m
-CONFIG_CC_VERSION_TEXT="aarch64-linux-gnu-gcc (Ubuntu 11.3.0-3ubuntu1) 11.3.0"
+CONFIG_CC_VERSION_TEXT="aarch64-linux-gnu-gcc-11 (Ubuntu 11.3.0-3ubuntu1) 11.3.0"
 CONFIG_CDROM_PKTCDVD=m
 CONFIG_CMA=y
 CONFIG_CMDLINE="console=ttyAMA0"
diff --git a/debian.master/config/armhf/config.common.armhf b/debian.master/config/armhf/config.common.armhf
index 4deed44707..4c5c17d743 100644
--- a/debian.master/config/armhf/config.common.armhf
+++ b/debian.master/config/armhf/config.common.armhf
@@ -56,7 +56,7 @@  CONFIG_CADENCE_WATCHDOG=m
 CONFIG_CAIF=m
 CONFIG_CAN=m
 CONFIG_CB710_CORE=m
-CONFIG_CC_VERSION_TEXT="arm-linux-gnueabihf-gcc (Ubuntu 11.3.0-3ubuntu1) 11.3.0"
+CONFIG_CC_VERSION_TEXT="arm-linux-gnueabihf-gcc-11 (Ubuntu 11.3.0-3ubuntu1) 11.3.0"
 CONFIG_CDROM_PKTCDVD=m
 CONFIG_CMA=y
 CONFIG_CMDLINE=""
diff --git a/debian.master/config/config.common.ubuntu b/debian.master/config/config.common.ubuntu
index 4da2a53894..a8b6166ab2 100644
--- a/debian.master/config/config.common.ubuntu
+++ b/debian.master/config/config.common.ubuntu
@@ -928,7 +928,7 @@  CONFIG_AS_IS_GNU=y
 CONFIG_AS_SHA1_NI=y
 CONFIG_AS_SHA256_NI=y
 CONFIG_AS_TPAUSE=y
-CONFIG_AS_VERSION=23800
+CONFIG_AS_VERSION=23890
 CONFIG_AS_VFP_VMRS_FPINST=y
 CONFIG_AT76C50X_USB=m
 CONFIG_AT803X_PHY=m
@@ -5841,7 +5841,7 @@  CONFIG_LDISC_AUTOLOAD=y
 # CONFIG_LD_HEAD_STUB_CATCH is not set
 CONFIG_LD_IS_BFD=y
 CONFIG_LD_ORPHAN_WARN=y
-CONFIG_LD_VERSION=23800
+CONFIG_LD_VERSION=23890
 CONFIG_LEDS_88PM860X=m
 CONFIG_LEDS_AAEON=m
 CONFIG_LEDS_AAT1290=m
@@ -7726,7 +7726,7 @@  CONFIG_PAGE_SIZE_LESS_THAN_64KB=y
 # CONFIG_PAGE_TABLE_CHECK is not set
 CONFIG_PAGE_TABLE_ISOLATION=y
 CONFIG_PAHOLE_HAS_SPLIT_BTF=y
-CONFIG_PAHOLE_VERSION=122
+CONFIG_PAHOLE_VERSION=123
 CONFIG_PALMAS_GPADC=m
 CONFIG_PANASONIC_LAPTOP=m
 CONFIG_PANEL=m
diff --git a/debian.master/config/ppc64el/config.common.ppc64el b/debian.master/config/ppc64el/config.common.ppc64el
index 35e2899b10..ad9c8c1136 100644
--- a/debian.master/config/ppc64el/config.common.ppc64el
+++ b/debian.master/config/ppc64el/config.common.ppc64el
@@ -55,7 +55,7 @@  CONFIG_CADENCE_WATCHDOG=m
 CONFIG_CAIF=m
 CONFIG_CAN=m
 CONFIG_CB710_CORE=m
-CONFIG_CC_VERSION_TEXT="powerpc64le-linux-gnu-gcc (Ubuntu 11.3.0-3ubuntu1) 11.3.0"
+CONFIG_CC_VERSION_TEXT="powerpc64le-linux-gnu-gcc-11 (Ubuntu 11.3.0-3ubuntu1) 11.3.0"
 CONFIG_CDROM_PKTCDVD=m
 CONFIG_CMA=y
 CONFIG_CMDLINE=""
diff --git a/debian.master/config/riscv64/config.common.riscv64 b/debian.master/config/riscv64/config.common.riscv64
index 1bd7d002f2..9500e3f68c 100644
--- a/debian.master/config/riscv64/config.common.riscv64
+++ b/debian.master/config/riscv64/config.common.riscv64
@@ -54,7 +54,7 @@  CONFIG_CADENCE_WATCHDOG=m
 CONFIG_CAIF=m
 CONFIG_CAN=m
 CONFIG_CB710_CORE=m
-CONFIG_CC_VERSION_TEXT="riscv64-linux-gnu-gcc (Ubuntu 11.3.0-1ubuntu1) 11.3.0"
+CONFIG_CC_VERSION_TEXT="riscv64-linux-gnu-gcc-11 (Ubuntu 11.3.0-1ubuntu1) 11.3.0"
 CONFIG_CDROM_PKTCDVD=m
 CONFIG_CMA=y
 CONFIG_CMDLINE=""
diff --git a/debian.master/config/s390x/config.common.s390x b/debian.master/config/s390x/config.common.s390x
index 1347877e85..5bed8649ae 100644
--- a/debian.master/config/s390x/config.common.s390x
+++ b/debian.master/config/s390x/config.common.s390x
@@ -45,7 +45,7 @@  CONFIG_AUTOFS_FS=y
 # CONFIG_CAIF is not set
 # CONFIG_CAN is not set
 # CONFIG_CB710_CORE is not set
-CONFIG_CC_VERSION_TEXT="s390x-linux-gnu-gcc (Ubuntu 11.3.0-3ubuntu1) 11.3.0"
+CONFIG_CC_VERSION_TEXT="s390x-linux-gnu-gcc-11 (Ubuntu 11.3.0-3ubuntu1) 11.3.0"
 # CONFIG_CDROM_PKTCDVD is not set
 CONFIG_CMA=y
 # CONFIG_CMDLINE_PARTITION is not set
diff --git a/debian/rules b/debian/rules
index 9fb38875be..a60fb58457 100755
--- a/debian/rules
+++ b/debian/rules
@@ -195,6 +195,7 @@  $(DEBIAN)/control.stub: 				\
 		-e 's/SRCPKGNAME/$(src_pkg_name)/g'                             \
 		-e 's/=HUMAN=/$(human_arch)/g'                                  \
 		-e 's/=SERIES=/$(series)/g'                                     \
+		-e 's/\(^Build-Depends:$$\)/\1\n$(GCC_BUILD_DEPENDS)/g'         \
 	  > $(DEBIAN)/control.stub;
 	flavours="$(sort $(wildcard $(DEBIAN)/control.d/vars.* $(DEBIAN)/sub-flavours/*.vars))";\
 	for i in $$flavours; do							\
diff --git a/debian/rules.d/0-common-vars.mk b/debian/rules.d/0-common-vars.mk
index e60c262ad1..bf6b45afd3 100644
--- a/debian/rules.d/0-common-vars.mk
+++ b/debian/rules.d/0-common-vars.mk
@@ -112,18 +112,15 @@  DEB_BUILD_ARCH = $(shell dpkg-architecture -qDEB_BUILD_ARCH)
 # packaging phase fails, but you can at least compile the kernel quickly.
 #
 arch := $(DEB_HOST_ARCH)
-ifneq ($(arch),$(DEB_HOST_ARCH))
-	CROSS_COMPILE ?= $(shell dpkg-architecture -a$(arch) -qDEB_HOST_GNU_TYPE -f 2>/dev/null)-
-endif
+CROSS_COMPILE ?= $(DEB_HOST_GNU_TYPE)-
 
 #
-# Detect invocations of the form 'dpkg-buildpackage -B -aarmhf' within
-# an x86'en schroot. This is the only way to build all of the packages
-# (except for tools).
+# Set consistent toolchain
+# If a given kernel wants to change this, they can do so via their own
+# $(DEBIAN)/rules.d/hooks.mk and $(DEBIAN)/rules.d/$(arch).mk files
 #
-ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
-	CROSS_COMPILE ?= $(DEB_HOST_GNU_TYPE)-
-endif
+export gcc?=gcc-11
+GCC_BUILD_DEPENDS=\ $(gcc), $(gcc)-aarch64-linux-gnu [arm64] <cross>, $(gcc)-arm-linux-gnueabihf [armhf] <cross>, $(gcc)-powerpc64le-linux-gnu [ppc64el] <cross>, $(gcc)-riscv64-linux-gnu [riscv64] <cross>, $(gcc)-s390x-linux-gnu [s390x] <cross>, $(gcc)-x86-64-linux-gnu [amd64] <cross>,
 
 abidir		:= $(CURDIR)/$(DEBIAN)/__abi.current/$(arch)
 prev_abidir	:= $(CURDIR)/$(DEBIAN)/abi/$(arch)
@@ -257,6 +254,8 @@  PYTHON ?= $(firstword $(wildcard /usr/bin/python3) $(wildcard /usr/bin/python2)
 # target_flavour is filled in for each step
 kmake = make ARCH=$(build_arch) \
 	CROSS_COMPILE=$(CROSS_COMPILE) \
+	HOSTCC=$(DEB_BUILD_GNU_TYPE)-$(gcc) \
+	CC=$(CROSS_COMPILE)$(gcc) \
 	KERNELVERSION=$(abi_release)-$(target_flavour) \
 	CONFIG_DEBUG_SECTION_MISMATCH=y \
 	KBUILD_BUILD_VERSION="$(uploadnum)" \
diff --git a/debian/rules.d/2-binary-arch.mk b/debian/rules.d/2-binary-arch.mk
index afc680b4ad..181de6e63f 100644
--- a/debian/rules.d/2-binary-arch.mk
+++ b/debian/rules.d/2-binary-arch.mk
@@ -10,11 +10,7 @@  build_cd =
 build_O  = O=$(builddir)/build-$*
 endif
 
-# Typically supplied from the arch makefile, e.g., debian.master/control.d/armhf.mk
-ifneq ($(gcc),)
-kmake += CC=$(CROSS_COMPILE)$(gcc)
-endif
-
+# TODO this is probably wrong, and should be using $(DEB_HOST_MULTIARCH)
 shlibdeps_opts = $(if $(CROSS_COMPILE),-- -l$(CROSS_COMPILE:%-=/usr/%)/lib)
 
 debian/scripts/fix-filenames: debian/scripts/fix-filenames.c
diff --git a/debian/scripts/misc/kernelconfig b/debian/scripts/misc/kernelconfig
index a1d791899c..5c3214b8ff 100755
--- a/debian/scripts/misc/kernelconfig
+++ b/debian/scripts/misc/kernelconfig
@@ -23,6 +23,13 @@  case "$mode" in
     *) echo "$0 called with invalid mode" 1>&2
        exit 1 ;;
 esac
+
+set -x
+if [ -z "$gcc" ]; then
+    echo "ERROR: gcc environment variable must be set"
+    exit 1
+fi
+
 kerneldir="`pwd`"
 confdir="$kerneldir/${DEBIAN}/config"
 variant="$2"
@@ -59,19 +66,16 @@  for arch in $archs; do
 	esac
 
 	# Determine cross toolchain to use for Kconfig compiler tests
-	cross_compile=""
-	deb_build_arch=$(dpkg-architecture -qDEB_BUILD_ARCH -a$arch 2>/dev/null)
-	deb_host_arch=$(dpkg-architecture -qDEB_HOST_ARCH -a$arch 2>/dev/null)
-	[ $deb_build_arch != $deb_host_arch ] && cross_compile="$(dpkg-architecture -qDEB_HOST_GNU_TYPE -a$arch 2>/dev/null)-"
+	cross_compile="$(dpkg-architecture -qDEB_HOST_GNU_TYPE -a$arch 2>/dev/null)-"
 
 	# Environment variables for 'make *config'. We omit CROSS_COMPILE
 	# for i386 since it is no longer supported after 19.04, however
 	# we maintain the configs for hwe.
 	modify_config=true
 	env="ARCH=$kernarch DEB_ARCH=$arch"
-	compiler_path=$(which "${cross_compile}gcc" || true)
+	compiler_path=$(which "${cross_compile}${gcc}" || true)
 	if [ "$compiler_path" != '' ]; then
-		env="$env CROSS_COMPILE=$cross_compile"
+		env="$env CROSS_COMPILE=$cross_compile CC=$compiler_path"
 	else
 		echo "WARNING: ${cross_compile}gcc not installed"
 		modify_config=