Rust links in some dynamic libraries even if only used by a disabled
feature gate.

This will be needed due to moving http-related code into the
proxmox-installer-common crate and thus pulling it in at more places.

Signed-off-by: Christoph Heiss <c.he...@proxmox.com>
---
Changes v3 -> v4:
  * use/copy script from proxmox-backup

Changes v2 -> v3:
  * no changes

Changes v1 -> v2:
  * print libraries being stripped from each binary

 debian/control                                |  1 +
 debian/rules                                  |  9 +++++++++
 .../scripts/elf-strip-unused-dependencies.sh  | 20 +++++++++++++++++++
 3 files changed, 30 insertions(+)
 create mode 100755 debian/scripts/elf-strip-unused-dependencies.sh

diff --git a/debian/control b/debian/control
index 04b0c6e..ff00cc2 100644
--- a/debian/control
+++ b/debian/control
@@ -26,6 +26,7 @@ Build-Depends: cargo:native,
                librust-toml-0.8-dev,
                librust-ureq-2.10-dev,
                libtest-mockmodule-perl,
+               patchelf,
                perl,
                rustc:native,
                shellcheck,
diff --git a/debian/rules b/debian/rules
index 1c03065..8a3f879 100755
--- a/debian/rules
+++ b/debian/rules
@@ -10,3 +10,12 @@ export BUILD_MODE=release
 
 override_dh_missing:
        dh_missing --fail-missing
+
+override_dh_strip:
+       dh_strip
+       for exe in $$(find \
+           debian/proxmox-installer \
+           debian/proxmox-auto-install-assistant \
+           -executable -type f); do \
+         debian/scripts/elf-strip-unused-dependencies.sh "$$exe" || true; \
+       done
diff --git a/debian/scripts/elf-strip-unused-dependencies.sh 
b/debian/scripts/elf-strip-unused-dependencies.sh
new file mode 100755
index 0000000..9f89c09
--- /dev/null
+++ b/debian/scripts/elf-strip-unused-dependencies.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+binary=$1
+
+exec 3< <(ldd -u "$binary" | grep -oP '[^/:]+$')
+
+patchargs=""
+dropped=""
+while read -r dep; do
+    dropped="$dep $dropped"
+    patchargs="--remove-needed $dep $patchargs"
+done <&3
+exec 3<&-
+
+if [[ $dropped == "" ]]; then
+    exit 0
+fi
+
+echo -e "patchelf '$binary' - removing unused dependencies:\n $dropped"
+patchelf $patchargs $binary
-- 
2.47.0



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to