APPLIED[L]: [SRU][L/M][PATCH] UBUNTU: [Packaging] introduce a separate linux-lib-rust package

Stefan Bader stefan.bader at canonical.com
Fri May 12 10:18:28 UTC 2023


On 09.05.23 09:17, Andrea Righi wrote:
> 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 at canonical.com>
> ---
>   debian.master/control.d/flavour-control.stub | 11 ++++++++++
>   debian/rules.d/0-common-vars.mk              |  2 ++
>   debian/rules.d/1-maintainer.mk               |  1 +
>   debian/rules.d/2-binary-arch.mk              | 22 +++++++++++++++-----
>   debian/rules.d/3-binary-indep.mk             |  3 +++
>   debian/scripts/link-lib-rust                 | 17 +++++++++++++++
>   6 files changed, 51 insertions(+), 5 deletions(-)
>   create mode 100755 debian/scripts/link-lib-rust
> 
> diff --git a/debian.master/control.d/flavour-control.stub b/debian.master/control.d/flavour-control.stub
> index 2c0bcd194a5c7..67b3a877202a0 100644
> --- a/debian.master/control.d/flavour-control.stub
> +++ b/debian.master/control.d/flavour-control.stub
> @@ -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
> diff --git a/debian/rules.d/0-common-vars.mk b/debian/rules.d/0-common-vars.mk
> index 6b79ba9300e8c..e16e15ef53753 100644
> --- a/debian/rules.d/0-common-vars.mk
> +++ b/debian/rules.d/0-common-vars.mk
> @@ -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
> diff --git a/debian/rules.d/1-maintainer.mk b/debian/rules.d/1-maintainer.mk
> index 6eded3eb4626a..c625715eacf41 100644
> --- a/debian/rules.d/1-maintainer.mk
> +++ b/debian/rules.d/1-maintainer.mk
> @@ -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)"
> diff --git a/debian/rules.d/2-binary-arch.mk b/debian/rules.d/2-binary-arch.mk
> index 689c9b788cd43..630a335616a74 100644
> --- a/debian/rules.d/2-binary-arch.mk
> +++ b/debian/rules.d/2-binary-arch.mk
> @@ -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		\
> diff --git a/debian/rules.d/3-binary-indep.mk b/debian/rules.d/3-binary-indep.mk
> index ccc1c1f0079d6..e1b545a4077ae 100644
> --- a/debian/rules.d/3-binary-indep.mk
> +++ b/debian/rules.d/3-binary-indep.mk
> @@ -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 $@
>   
> diff --git a/debian/scripts/link-lib-rust b/debian/scripts/link-lib-rust
> new file mode 100755
> index 0000000000000..0bea9729431d2
> --- /dev/null
> +++ b/debian/scripts/link-lib-rust
> @@ -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

Applied to lunar:linux/master-next. Thanks.

-Stefan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0xE8675DEECBEECEA3.asc
Type: application/pgp-keys
Size: 44613 bytes
Desc: OpenPGP public key
URL: <https://lists.ubuntu.com/archives/kernel-team/attachments/20230512/78b95a5b/attachment-0001.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ubuntu.com/archives/kernel-team/attachments/20230512/78b95a5b/attachment-0001.sig>


More information about the kernel-team mailing list