]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
UBUNTU: [Packaging] introduce a separate linux-lib-rust package
authorAndrea Righi <andrea.righi@canonical.com>
Tue, 9 May 2023 07:17:00 +0000 (09:17 +0200)
committerRoxana Nicolescu <roxana.nicolescu@canonical.com>
Wed, 17 May 2023 11:34:16 +0000 (13:34 +0200)
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>
Acked-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
Acked-by: Tim Gardner <tim.gardner@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
debian.master/control.d/flavour-control.stub
debian/rules.d/0-common-vars.mk
debian/rules.d/1-maintainer.mk
debian/rules.d/2-binary-arch.mk
debian/rules.d/3-binary-indep.mk
debian/scripts/link-lib-rust [new file with mode: 0755]

index 2c0bcd194a5c727ea9a8b9718576e995b83ac375..67b3a877202a07ce2c5bb0bc85659abdda0b8af9 100644 (file)
@@ -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
index 6b79ba9300e8c0f804151e807c9eff4628fca253..e16e15ef53753ac49f2b17b5f09c95d3a4f8bb6e 100644 (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
index 6eded3eb4626af06bfd3bf7e61658365f02401e0..c625715eacf4103c6c9a1f71276e77bd449d8b76 100644 (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)"
index 689c9b788cd439e401f7a48e5c8de77daff13295..630a335616a740e13f414d4ac356b31a708f902a 100644 (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             \
index ccc1c1f0079d6c5421e74960b9eb48abf9b4855c..e1b545a4077aed4205c2d93843899a3e8094bb39 100644 (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 $@
 
diff --git a/debian/scripts/link-lib-rust b/debian/scripts/link-lib-rust
new file mode 100755 (executable)
index 0000000..0bea972
--- /dev/null
@@ -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