UBUNTU: [Packaging] introduce a separate linux-lib-rust package

BugLink: https://bugs.launchpad.net/bugs/2015867

After enabling Rust in the kernel, the size of linux-headers increased
consistently.

Some work has been done to reduce the size, such as dropping the binary
artifacts (*.o and *.cmd), but it would be nice to keep the size of
linux-headers reasonably small to avoid wasting too much space in the
cloud images.

For this reason introduce a new package linux-lib-rust to ship all the
Rust headers and libraries required to build out-of-tree kernel modules
in Rust.

Before this patch: 96M	/usr/src/linux-headers-6.2.0-21-generic
 After this patch: 29M	/usr/src/linux-headers-6.2.0-21-generic

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
This commit is contained in:
Andrea Righi
2023-05-07 12:39:06 +02:00
committed by Paolo Pisati
parent a6e925fc62
commit ebc5a672c7
6 changed files with 51 additions and 5 deletions
@@ -100,6 +100,17 @@ Description: Linux kernel headers for version PKGVER on DESC
This is for sites that want the latest kernel headers. Please read
/usr/share/doc/linux-headers-PKGVER-ABINUM/debian.README.gz for details.
Package: SRCPKGNAME-lib-rust-PKGVER-ABINUM-FLAVOUR
Build-Profiles: <!stage1>
Architecture: amd64
Multi-Arch: foreign
Section: devel
Priority: optional
Depends: ${misc:Depends}, coreutils
Description: Rust library files related to Linux kernel version PKGVER
This package provides kernel library files for version PKGVER, that allow to
compile out-of-tree kernel modules written in Rust.
Package: linux-image=SIGN-ME-PKG=-PKGVER-ABINUM-FLAVOUR-dbgsym
Build-Profiles: <!stage1>
Architecture: ARCH
+2
View File
@@ -119,7 +119,9 @@ mods_pkg_name=linux-modules-$(abi_release)
mods_extra_pkg_name=linux-modules-extra-$(abi_release)
bldinfo_pkg_name=linux-buildinfo-$(abi_release)
hdrs_pkg_name=linux-headers-$(abi_release)
rust_pkg_name=$(src_pkg_name)-lib-rust-$(abi_release)
indep_hdrs_pkg_name=$(src_pkg_name)-headers-$(abi_release)
indep_lib_rust_pkg_name=$(src_pkg_name)-lib-rust-$(abi_release)
#
# The generation of content in the doc package depends on
+1
View File
@@ -69,6 +69,7 @@ printenv:
@echo "flavours = $(flavours)"
@echo "bin_pkg_name = $(bin_pkg_name)"
@echo "hdr_pkg_name = $(hdrs_pkg_name)"
@echo "rust_pkg_name = $(rust_pkg_name)"
@echo "doc_pkg_name = $(doc_pkg_name)"
@echo "libc_dev_version = $(libc_dev_version)"
@echo "ubuntu_selftests = $(ubuntu_selftests)"
+17 -5
View File
@@ -109,10 +109,12 @@ $(stampdir)/stamp-install-%: signingv = $(CURDIR)/debian/$(bin_pkg_name)-signing
$(stampdir)/stamp-install-%: toolspkgdir = $(CURDIR)/debian/$(tools_flavour_pkg_name)-$*
$(stampdir)/stamp-install-%: cloudpkgdir = $(CURDIR)/debian/$(cloud_flavour_pkg_name)-$*
$(stampdir)/stamp-install-%: basepkg = $(hdrs_pkg_name)
$(stampdir)/stamp-install-%: baserustpkg = $(rust_pkg_name)
$(stampdir)/stamp-install-%: indeppkg = $(indep_hdrs_pkg_name)
$(stampdir)/stamp-install-%: kernfile = $(call custom_override,kernel_file,$*)
$(stampdir)/stamp-install-%: instfile = $(call custom_override,install_file,$*)
$(stampdir)/stamp-install-%: hdrdir = $(CURDIR)/debian/$(basepkg)-$*/usr/src/$(basepkg)-$*
$(stampdir)/stamp-install-%: rustdir = $(CURDIR)/debian/$(baserustpkg)-$*/usr/src/$(baserustpkg)-$*
$(stampdir)/stamp-install-%: target_flavour = $*
$(stampdir)/stamp-install-%: MODHASHALGO=sha512
$(stampdir)/stamp-install-%: MODSECKEY=$(builddir)/build-$*/certs/signing_key.pem
@@ -130,6 +132,7 @@ $(stampdir)/stamp-install-%: $(stampdir)/stamp-build-% $(stampdir)/stamp-install
dh_prep -p$(bin_pkg_name)-$*
dh_prep -p$(mods_pkg_name)-$*
dh_prep -p$(hdrs_pkg_name)-$*
dh_prep -p$(rust_pkg_name)-$*
$(foreach _m,$(all_standalone_dkms_modules), \
$(if $(enable_$(_m)),dh_prep -p$(dkms_$(_m)_pkg_name)-$*;)\
)
@@ -336,10 +339,6 @@ endif
grep '^HOSTCC .*$(gcc)$$' $(hdrdir)/Makefile
grep '^CC .*$(gcc)$$' $(hdrdir)/Makefile
rm -rf $(hdrdir)/include2 $(hdrdir)/source
# Do not ship .o and .cmd artifacts in headers
find $(hdrdir) -name \*.o -or -name \*.cmd -exec rm -f {} \;
# Strip .so files (e.g., rust/libmacros.so) to reduce size even more
find $(hdrdir) -name libmacros.so -exec strip -s {} \;
# We do not need the retpoline information.
find $(hdrdir) -name \*.o.ur-\* -exec rm -f {} \;
# Copy over the compilation version.
@@ -386,7 +385,7 @@ endif
#
# Remove files which are generated at installation by postinst,
# except for modules.order and modules.builtin
#
#
# NOTE: need to keep this list in sync with postrm
#
mkdir $(pkgdir)/lib/modules/$(abi_release)-$*/_
@@ -554,6 +553,17 @@ endif
install -m644 $(DROOT)/canonical-certs.pem $(pkgdir_bldinfo)/usr/lib/linux/$(abi_release)-$*/canonical-certs.pem
install -m644 $(DROOT)/canonical-revoked-certs.pem $(pkgdir_bldinfo)/usr/lib/linux/$(abi_release)-$*/canonical-revoked-certs.pem
# Get rid of .o and .cmd artifacts in headers
find $(hdrdir) -name \*.o -or -name \*.cmd -exec rm -f {} \;
# Strip .so files (e.g., rust/libmacros.so) to reduce size even more
find $(hdrdir) -name libmacros.so -exec strip -s {} \;
# Generate Rust lib files
install -d -m755 $(rustdir)
mv $(hdrdir)/rust $(rustdir)
# Generate symlink for Rust lib directory in headers
$(SHELL) $(DROOT)/scripts/link-lib-rust "$(hdrdir)" "$(indeppkg)" "$*"
ifneq ($(do_full_build),false)
# Clean out this flavours build directory.
rm -rf $(builddir)/build-$*
@@ -626,6 +636,7 @@ binary-%: pkgimg_ex = $(mods_extra_pkg_name)-$*
binary-%: pkgdir_ex = $(CURDIR)/debian/$(extra_pkg_name)-$*
binary-%: pkgbldinfo = $(bldinfo_pkg_name)-$*
binary-%: pkghdr = $(hdrs_pkg_name)-$*
binary-%: pkgrust = $(rust_pkg_name)-$*
binary-%: dbgpkg = $(bin_pkg_name)-$*-dbgsym
binary-%: dbgpkgdir = $(CURDIR)/debian/$(bin_pkg_name)-$*-dbgsym
binary-%: pkgtools = $(tools_flavour_pkg_name)-$*
@@ -664,6 +675,7 @@ endif
$(call dh_all,$(pkgbldinfo))
$(call dh_all,$(pkghdr))
$(call dh_all,$(pkgrust))
ifneq ($(skipsub),true)
@set -e; for sub in $($(*)_sub); do \
+3
View File
@@ -9,6 +9,7 @@ build-indep:
#
indep_hdrpkg = $(indep_hdrs_pkg_name)
indep_hdrdir = $(CURDIR)/debian/$(indep_hdrpkg)/usr/src/$(indep_hdrpkg)
$(stampdir)/stamp-install-headers: $(stampdir)/stamp-prepare-indep
@echo Debug: $@
dh_testdir
@@ -25,6 +26,8 @@ ifeq ($(do_flavour_header_package),true)
(find arch -name include -type d -print | \
xargs -n1 -i: find : -type f) | \
cpio -pd --preserve-modification-time $(indep_hdrdir)
# Do not ship .o and .cmd artifacts in headers
find $(indep_hdrdir) -name \*.o -or -name \*.cmd -exec rm -f {} \;
endif
@touch $@
Vendored Executable
+17
View File
@@ -0,0 +1,17 @@
#!/bin/bash -e
. debian/debian.env
hdrdir="$1"
symdir="$2"
flavour="$3"
echo "Symlinking and copying Rust files for $flavour..."
# Symlink Rust folder
item=rust
relpath=$(echo $symdir | sed s/headers/lib-rust/)-$flavour/$item
echo ln -s ../$relpath $hdrdir/$item
ln -s ../$relpath $hdrdir/$item
exit