[Unstable][PATCH 1/2] UBUNTU: [Packaging] linux-bpf-dev: Restructure packaging

Juerg Haefliger juerg.haefliger at canonical.com
Thu Dec 5 14:32:47 UTC 2024


Building the linux-bpf-dev package requires bpftool and vmlinux which are
produced in different build steps. The current build/install order looks
like this:

1. build-flavor
   - build vmlinux

2. install-flavor
   - copy vmlinux to tmp/vmlinux
   - remove the flavor build directory

3. build-tools
   - build bpftool
   - bpftool tmp/vmlinux > vmlinux.h
   - remove tmp/vmlinux

4. install-tools
   - copy vmlinux.h to package directory
...

To fix out-of-space issues in LP, we have to remove the flavor build
directory at the end of the install-flavor step which means vmlinux
is no longer around afterwards, hence the ugly tmp/vmlinux dance.
Also, vmlinux.h is really a flavor build artifact so should be generated
in the build-flavor rather than the build-tools step.

Clean this up some by reording. Build the tools first and then produce
per-flavor linux.h and install it in the following step.

1. build-tools
   - build bpftool

2. install-tools

3. build-flavor
   - build vmlinux
   - bpftool vmlinux > vmlinux.h

4. install-flavor
   - copy vmlinux.h to package directory
   - remove the flavor build directory
...

Also drop the build-arch dependency from the stamp-build-perarch target
to prevent a circular dependency.

Note that this reordering is also necessary for an upcoming commit where
we want to install the tools into flavored packages.

Signed-off-by: Juerg Haefliger <juerg.haefliger at canonical.com>
---
 debian/rules.d/2-binary-arch.mk | 34 ++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/debian/rules.d/2-binary-arch.mk b/debian/rules.d/2-binary-arch.mk
index fcbb95b7942c..cb8d7d623f24 100644
--- a/debian/rules.d/2-binary-arch.mk
+++ b/debian/rules.d/2-binary-arch.mk
@@ -33,7 +33,7 @@ build-%: $(stampdir)/stamp-install-%
 # Do the actual build, including image and modules
 $(stampdir)/stamp-build-%: target_flavour = $*
 $(stampdir)/stamp-build-%: bldimg = $(call custom_override,build_image,$*)
-$(stampdir)/stamp-build-%: $(stampdir)/stamp-prepare-%
+$(stampdir)/stamp-build-%: $(stampdir)/stamp-build-perarch $(stampdir)/stamp-prepare-%
 	@echo Debug: $@ build_image $(build_image) bldimg $(bldimg)
 	$(kmake) O=$(builddir)/build-$* $(conc_level) $(bldimg) modules $(if $(filter true,$(do_dtbs)),dtbs)
 
@@ -44,6 +44,14 @@ ifeq ($(do_dbgsym_package),true)
 	fi
 endif
 
+ifeq ($(do_tools_bpftool),true)
+ifeq ($(do_tools_bpftool_stub),true)
+	echo '#error "Kernel does not support CONFIG_DEBUG_INFO_BTF"' > $(builddir)/build-$*/vmlinux.h
+else
+	$(builddirpa)/tools/bpf/bpftool/bpftool btf dump file $(builddir)/build-$*/vmlinux format c > $(builddir)/build-$*/vmlinux.h
+endif
+endif
+
 	# Collect the list of kernel source files used for this build. Need to do this early
 	# before modules are stripped. Fail if the resulting file is empty.
 	find $(builddir)/build-$* \( -name vmlinux -o -name \*.ko \) -exec dwarfdump -i {} \; | \
@@ -98,6 +106,7 @@ $(stampdir)/stamp-install-%: dbgpkgdir = $(CURDIR)/debian/$(bin_pkg_name)-$*-dbg
 $(stampdir)/stamp-install-%: signingv = $(CURDIR)/debian/$(bin_pkg_name)-signing/$(DEB_VERSION_UPSTREAM)-$(DEB_REVISION)
 $(stampdir)/stamp-install-%: toolspkgdir = $(CURDIR)/debian/$(tools_flavour_pkg_name)-$*
 $(stampdir)/stamp-install-%: cloudpkgdir = $(CURDIR)/debian/$(cloud_flavour_pkg_name)-$*
+$(stampdir)/stamp-install-%: bpfdevpkgdir = $(CURDIR)/debian/linux-bpf-dev
 $(stampdir)/stamp-install-%: basepkg = $(hdrs_pkg_name)
 $(stampdir)/stamp-install-%: baserustpkg = $(rust_pkg_name)
 $(stampdir)/stamp-install-%: indeppkg = $(indep_hdrs_pkg_name)
@@ -116,7 +125,7 @@ $(foreach _m,$(all_dkms_modules), \
   $(eval $$(stampdir)/stamp-install-%: dkms_$(_m)_pkgdir = $$(CURDIR)/debian/$(dkms_$(_m)_pkg_name)-$$*) \
 )
 $(stampdir)/stamp-install-%: dbgpkgdir_dkms = $(if $(filter true,$(do_dbgsym_package)),$(dbgpkgdir)/usr/lib/debug/lib/modules/$(abi_release)-$*/kernel,"")
-$(stampdir)/stamp-install-%: $(stampdir)/stamp-build-% $(stampdir)/stamp-install-headers
+$(stampdir)/stamp-install-%: $(stampdir)/stamp-install-headers $(stampdir)/stamp-build-%
 	@echo Debug: $@ kernel_file $(kernel_file) kernfile $(kernfile) install_file $(install_file) instfile $(instfile)
 	dh_testdir
 	dh_prep -p$(bin_pkg_name)-$*
@@ -264,9 +273,6 @@ ifeq ($(do_dbgsym_package),true)
 	rm -f $(dbgpkgdir)/usr/lib/debug/lib/modules/$(abi_release)-$*/modules.*
 	rm -fr $(dbgpkgdir)/usr/lib/debug/lib/firmware
 endif
-ifeq ($(do_tools_bpftool),true)
-	cp $(builddir)/build-$*/vmlinux tools/bpf/bpftool/
-endif
 
 	# The flavour specific headers image
 	# TODO: Would be nice if we didn't have to dupe the original builddir
@@ -356,6 +362,11 @@ ifeq ($(do_tools_hyperv),true)
 	install -d $(cloudpkgdir)/usr/lib/linux-tools
 	$(LN) ../$(DEB_SOURCE)-tools-$(abi_release) $(cloudpkgdir)/usr/lib/linux-tools/$(abi_release)-$*
 endif
+endif
+ifeq ($(do_tools_bpftool),true)
+	install -d -m755 $(bpfdevpkgdir)/usr/include/$(DEB_HOST_MULTIARCH)/linux/
+	install -m644 $(builddir)/build-$*/vmlinux.h \
+		 $(bpfdevpkgdir)/usr/include/$(DEB_HOST_MULTIARCH)/linux/
 endif
 
 	# Build a temporary "installed headers" directory.
@@ -616,7 +627,7 @@ ifeq ($(do_any_tools),true)
 endif
 	$(stamp)
 
-$(stampdir)/stamp-build-perarch: $(stampdir)/stamp-prepare-perarch install-arch-headers build-arch
+$(stampdir)/stamp-build-perarch: install-arch-headers $(stampdir)/stamp-prepare-perarch
 	@echo Debug: $@
 ifeq ($(do_linux_tools),true)
 ifeq ($(do_tools_usbip),true)
@@ -644,14 +655,7 @@ ifeq ($(do_tools_perf),true)
 		$(kmake) prefix=/usr HAVE_CPLUS_DEMANGLE_SUPPORT=1 CROSS_COMPILE=$(CROSS_COMPILE) NO_LIBPERL=1 WERROR=0
 endif
 ifeq ($(do_tools_bpftool),true)
-	mv $(builddirpa)/tools/bpf/bpftool/vmlinux $(builddirpa)/vmlinux
 	$(kmake) CROSS_COMPILE=$(CROSS_COMPILE) -C $(builddirpa)/tools/bpf/bpftool
-ifneq ($(do_tools_bpftool_stub),true)
-	$(builddirpa)/tools/bpf/bpftool/bpftool btf dump file $(builddirpa)/vmlinux format c > $(builddirpa)/vmlinux.h
-else
-	echo '#error "Kernel does not support CONFIG_DEBUG_INFO_BTF"' > $(builddirpa)/vmlinux.h
-endif
-	rm -f $(builddirpa)/vmlinux
 endif
 ifeq ($(do_tools_x86),true)
 	cd $(builddirpa)/tools/power/x86/x86_energy_perf_policy && make CROSS_COMPILE=$(CROSS_COMPILE)
@@ -706,10 +710,6 @@ endif
 ifeq ($(do_tools_bpftool),true)
 	install -m755 $(builddirpa)/tools/bpf/bpftool/bpftool $(toolspkgdir)/usr/lib/$(DEB_SOURCE)-tools-$(abi_release)
 endif
-ifeq ($(do_tools_bpftool),true)
-	install -d -m755 $(CURDIR)/debian/linux-bpf-dev/usr/include/$(DEB_HOST_MULTIARCH)/linux/
-	install -m644 $(builddirpa)/vmlinux.h $(CURDIR)/debian/linux-bpf-dev/usr/include/$(DEB_HOST_MULTIARCH)/linux/vmlinux.h
-endif
 ifeq ($(do_tools_x86),true)
 	install -m755 \
 		$(addprefix $(builddirpa)/tools/power/x86/, x86_energy_perf_policy/x86_energy_perf_policy turbostat/turbostat) \
-- 
2.43.0




More information about the kernel-team mailing list