From: Arnaud Ferraris <aferraris@debian.org>
Date: Fri, 15 Nov 2024 11:01:23 +0100
Subject: shell-rs: build: re-generate bindings before building exe

The build system provides a target named `update-rust-bindings` which
can be called manually to regenerate all Rust bindings. As we want to
ensure those are re-generated on Debian infra, make it a dependency of
the `cargo-build` target so bindings are always re-generated at build
time.

Forwarded: not-needed
---
 rust/meson.build        |  3 ++-
 rust/update-bindings.sh | 33 ++++++++++++++++++++-------------
 shell/src/meson.build   |  2 +-
 3 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/rust/meson.build b/rust/meson.build
index db9363d..34ecac9 100644
--- a/rust/meson.build
+++ b/rust/meson.build
@@ -4,7 +4,8 @@ cargo_fmt = find_program('cargo-fmt', required: get_option('profile') == 'devel'
 if gobject_introspection_dep.found() and cargo_fmt.found()
   gir_dir = rust_binding_root / 'gir-files'
 
-  run_target('update-rust-bindings',
+  update_bindings = custom_target('update-rust-bindings',
+    output: 'pps-girs',
     command: [
       rust_binding_root / 'update-bindings.sh',
       libppsview_gir[0].full_path(),
diff --git a/rust/update-bindings.sh b/rust/update-bindings.sh
index fa60ffc..c624a21 100755
--- a/rust/update-bindings.sh
+++ b/rust/update-bindings.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-if [ -n "${MESON_SOURCE_ROOT}" ]; then
-	cd "${MESON_SOURCE_ROOT}/rust"
+if [ -n "${DEB_SOURCE_DIR}" ]; then
+	pushd "${DEB_SOURCE_DIR}/rust"
 fi
 
 export PATH="$PATH:${MESON_SOURCE_ROOT}/rust/gir/target/release"
@@ -12,15 +12,22 @@ then
 	exit 1
 fi
 
-for g in ${@:1}; do
-	cp "$g" pps-girs
-done
+# Only re-generate bindings once to avoid useless rebuilds
+if ! [ -f "ev-girs/$(basename $1)" ]; then
+	for g in ${@:1}; do
+		cp "$g" pps-girs
+	done
 
-for d in papers-document papers-view; do
-	pushd $d > /dev/null
-	pushd sys > /dev/null
-	gir -o .
-	popd &> /dev/null
-	gir -o .
-	popd > /dev/null
-done
+	for d in papers-document papers-view; do
+		pushd $d > /dev/null
+		pushd sys > /dev/null
+		gir -o .
+		popd &> /dev/null
+		gir -o .
+		popd > /dev/null
+	done
+fi
+
+if [ -n "${DEB_SOURCE_DIR}" ]; then
+	popd
+fi
diff --git a/shell/src/meson.build b/shell/src/meson.build
index a47479f..b133f33 100644
--- a/shell/src/meson.build
+++ b/shell/src/meson.build
@@ -56,7 +56,7 @@ cargo_build = custom_target(
   build_always_stale: true,
   output: 'src',
   console: true,
-  depends: [papers_resources],
+  depends: [papers_resources, update_bindings],
   env: cargo_env,
   command: [
     cargo, 'build',
