diff mbox

[bug#50201,core-updates-frozen,0/52] Support cross-compilation in glib-or-gtk-build-system and fix cross-compilation errors

Message ID 5130a9b285c92995481da3eee481033f0e26a9b2.camel@telenet.be
State Accepted
Headers show

Commit Message

M Sept. 3, 2021, 12:35 p.m. UTC
Mathieu Othacehe schreef op ma 30-08-2021 om 14:58 [+0200]:
> Hey,
> 
> > +                         (string-append dir "/_giscanner.cpython-39-"
> > +                                        (normalise-system system) ".so"))
> 
> Won't this be "cpython-310-" or so when we will update the Python
> package definition?

Indeed.  I attached a patch independent of python's version number,
to be squashed in the v2 patch series.

Greetings,
Maxime

Comments

Mathieu Othacehe Sept. 19, 2021, 3:43 p.m. UTC | #1
Hello Maxime,

> Indeed.  I attached a patch independent of python's version number,
> to be squashed in the v2 patch series.

Nice, thanks. The series doesn't apply anymore, would you have a branch
somewhere that I could use?

Mathieu
M Sept. 19, 2021, 6:25 p.m. UTC | #2
Mathieu Othacehe schreef op zo 19-09-2021 om 15:43 [+0000]:
> Hello Maxime,
> 
> > Indeed.  I attached a patch independent of python's version number,
> > to be squashed in the v2 patch series.
> 
> Nice, thanks. The series doesn't apply anymore, would you have a branch
> somewhere that I could use?

The merge conflicts were trivial (in the copyright lines).
Anyway, you could find a rebased branch at <https://notabug.org/maximed/guix-gnunet/src/gtk-cross-fixes1>
(untested) (commit: 3936dfc4d1c29bb5311caa3597ca272c8326f0c3).

Greetings,
Maxime.
Mathieu Othacehe Sept. 20, 2021, 11:22 a.m. UTC | #3
Hello,

I pushed the series, with a minor modification to add a reference to our
discussion on introspection data cross-compilation.

It would be nice to remove the associated TODOs on core-updates while
this is still fresh.

Thanks for your work on that topic,

Mathieu
diff mbox

Patch

From 653b54de7b24db588a6d063beab82ae2218153e5 Mon Sep 17 00:00:00 2001
From: Maxime Devos <maximedevos@telenet.be>
Date: Fri, 3 Sep 2021 13:25:10 +0200
Subject: [PATCH] SQUASH! gobject-introspection! C extension correction!

* gnu/packages/glib.scm
  (python-extension-suffix, correct-library-name-phase): New procedures.
  (gobject-introspection)[arguments]<#:phases>{rename-library}: New phase.
---
 gnu/packages/glib.scm | 54 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 13 deletions(-)

diff --git a/gnu/packages/glib.scm b/gnu/packages/glib.scm
index 0c2f548f62..6a9c2ac318 100644
--- a/gnu/packages/glib.scm
+++ b/gnu/packages/glib.scm
@@ -381,6 +381,42 @@  functions for strings and common data structures.")
                   (string-append doc html))
                  #t)))))))))
 
+(define (python-extension-suffix python triplet)
+  "Determine the suffix for C extensions for PYTHON when compiled
+for TRIPLET."
+  ;; python uses strings like 'x86_64-linux-gnu' instead of
+  ;; 'x86_64-unknown-linux-gnu'.
+  (define normalised-system
+    (string-replace-substring triplet "-unknown-" "-"))
+  (define major.minor (version-major+minor (package-version python)))
+  (define majorminor (string-delete #\. major.minor))
+  (string-append
+    ;; If guix' python package used "--with-pydebug", a #\d would
+    ;; need to be added, likewise "--with-pymalloc" and "--with-wide-unicode"
+    ;; would require a #\m and #\u, see cpython's configure.ac.
+    ".cpython-" majorminor "-" normalised-system
+    (if (target-mingw? triplet)
+        ".dll"
+        ".so")))
+
+(define (correct-library-name-phase python name)
+  "Return a G-exp evaluating to a phase renaming the python extension NAME
+from what Meson thinks its name should be to what python expects its name
+to be.  NAME must not include the platform-specific suffix.  This can only
+be used when cross-compiling."
+  #~(lambda _
+      (define name #$name)
+      (define native-suffix
+        #$(python-extension-suffix python
+                                   (nix-system->gnu-triplet (%current-system))))
+      (define target-suffix
+        #$(python-extension-suffix python (%current-target-system)))
+      (define native-name
+        (string-append name native-suffix))
+      (define target-name
+        (string-append name target-suffix))
+      (rename-file native-name target-name)))
+
 (define gobject-introspection
   (package
     (name "gobject-introspection")
@@ -431,19 +467,11 @@  functions for strings and common data structures.")
                ;; 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)))))
+                     #$(correct-library-name-phase
+                         (this-package-input "python")
+                         #~(string-append #$output
+                                          "/lib/gobject-introspection/giscanner"
+                                          "/_giscanner"))))
                 #~()))))
     (native-inputs
      `(("glib" ,glib "bin")
-- 
2.33.0