Subject: [PATCH 16/52] gobject-introspection: Correct library name when cross-compiling.

From: Maxime Devos <[email-masked]>
Date: Wed, 25 Aug 2021 20:02:56 +0200

* gnu/packages/glib.scm
  (gobject-introspection)[arguments]<#:phases>{rename-library}:
  Correct the name of the python extension when cross-compiling.
---
 gnu/packages/glib.scm | 37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/gnu/packages/glib.scm b/gnu/packages/glib.scm
index ac38cd40d2..0c2f548f62 100644
--- a/gnu/packages/glib.scm
+++ b/gnu/packages/glib.scm
@@ -411,21 +411,40 @@ functions for strings and common data structures.")
                  "-Dbuild_introspection_data=false"))
              '())
        #:phases
+       ,#~
        (modify-phases %standard-phases
-         ,@(if (%current-target-system)
-               ;; 'typelibs' is undefined.
-               `((add-after 'unpack 'set-typelibs
-                   (lambda _
-                     (substitute* "meson.build"
-                       (("\\bsources: typelibs\\b")
-                        "sources: []")))))
-               '())
+         #$@(if (%current-target-system)
+                ;; 'typelibs' is undefined.
+                `((add-after 'unpack 'set-typelibs
+                    (lambda _
+                      (substitute* "meson.build"
+                        (("\\bsources: typelibs\\b")
+                         "sources: []")))))
+                '())
          (add-after 'unpack 'do-not-use-/usr/bin/env
            (lambda _
              (substitute* "tools/g-ir-tool-template.in"
                (("#!@PYTHON_CMD@")
                 (string-append "#!" (which "python3"))))
-             #t)))))
+             #t))
+         #$@(if (%current-target-system)
+               ;; Meson gives python extensions an incorrect name, see
+               ;; <https://github.com/mesonbuild/meson/issues/7049>.
+                #~((add-after 'install 'rename-library
+                     (lambda* (#:key build target #:allow-other-keys)
+                       (define dir
+                         (string-append #$output
+                                        "/lib/gobject-introspection/giscanner"))
+                       ;; python uses strings like 'x86_64-linux-gnu', not
+                       ;; 'x86_64-unknown-linux-gnu'.
+                       (define (normalise-system system)
+                         ((@ (ice-9 string-fun) string-replace-substring)
+                          system "-unknown-" "-"))
+                       (define (extension system)
+                         (string-append dir "/_giscanner.cpython-39-"
+                                        (normalise-system system) ".so"))
+                       (rename-file (extension build) (extension target)))))
+                #~()))))
     (native-inputs
      `(("glib" ,glib "bin")
        ("pkg-config" ,pkg-config)
-- 
2.33.0