Subject: Re: bug#58126: libtirpc fails to find krb5-config during cross-compilation

From: Maxime Devos <[email-masked]>
Date: Tue, 27 Sep 2022 23:42:08 +0200

On 27-09-2022 23:02, Pavel Shlyak wrote:
> Reproducer (on x86-64 host):
> guix build --target=aarch64-linux-gnu libtirpc
> Output:
> configure: error: krb5-config tool not found. Use --disable-gssapi, or install Kerberos.
>

I have been working on some cross-compilation fixes, not properly sent 
and tested yet, which includes a fix for libtirpc (going by the commit 
log), see attachments.

Greetings,
Maxime.
From 88d0e2e448ee0f131fa61e4fe58ae39565e684de Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Sun, 18 Sep 2022 22:56:29 +0200
Subject: [PATCH 4/4] gnu: qpdf: Fix cross-compilation.

* gnu/packages/pdf.scm
(qpdf)[arguments]{#:configure-flags}: Set --with-random when cross-compiling.
---
 gnu/packages/pdf.scm | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gnu/packages/pdf.scm b/gnu/packages/pdf.scm
index ca4e7f2557..b1e74d34c8 100644
--- a/gnu/packages/pdf.scm
+++ b/gnu/packages/pdf.scm
@@ -854,6 +854,12 @@ (define-public qpdf
    (build-system gnu-build-system)
    (arguments
     `(#:disallowed-references (,perl)
+      ;; When cross-compiling, the configure script cannot determine the name
+      ;; of the source of randomness by itself.  /dev/urandom is correct on at
+      ;; least Linux.
+      #:configure-flags ,(if (%current-target-system)
+                             '(list "--with-random=/dev/urandom")
+                             '())
       #:phases
       (modify-phases %standard-phases
         (add-before 'configure 'patch-paths
-- 
2.37.3

From 4b70598eb6fd2bb1937f3b7ad2e49b05502b73bd Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Sun, 18 Sep 2022 22:34:43 +0200
Subject: [PATCH 3/4] gnu: libxkbcommon: Fix cross-compilation.

* gnu/packages/xdisorg.scm
(libxkbcommon)[native-inputs]: Add a few dependencies when cross-compiling.
---
 gnu/packages/xdisorg.scm | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/xdisorg.scm b/gnu/packages/xdisorg.scm
index 9908f29191..ab46010f24 100644
--- a/gnu/packages/xdisorg.scm
+++ b/gnu/packages/xdisorg.scm
@@ -503,7 +503,16 @@ (define-public libxkbcommon
            wayland-protocols
            xkeyboard-config))
     (native-inputs
-     (list bison doxygen pkg-config python))
+     `(,bison
+       ,doxygen
+       ,pkg-config
+       ,python
+       ,@(if (%current-target-system) ; for finding wayland-scanner
+             (list pkg-config-for-build
+                   ;; both 'inputs' and 'native-inputs' appears to be required
+                   wayland
+                   wayland-protocols)
+             '())))
     (arguments
      `(#:configure-flags
        (list (string-append "-Dxkb-config-root="
-- 
2.37.3

From 97713c594610b13d11b777ae0794021a8a3cf0ca Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Sun, 18 Sep 2022 22:16:10 +0200
Subject: [PATCH 2/4] gnu: [email-masked]: Fix cross-compilation.

* gnu/packages/gnome.scm
(librsvg-2.40)[arguments]{#:configure-flags}: Add --disable-introspection when
cross-compiling.
{#:disallowed-references}: Add gdk-pixbuf when cross-compiling.
[native-inputs]: Add gdk-pixbuf when cross-compiling.
---
 gnu/packages/gnome.scm | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/gnome.scm b/gnu/packages/gnome.scm
index c8a49040f4..3751bf13f5 100644
--- a/gnu/packages/gnome.scm
+++ b/gnu/packages/gnome.scm
@@ -3682,7 +3682,19 @@ (define-public librsvg-2.40
                 "1fljkag2gr7c4k5mn798lgf9903xslz8h51bgvl89nnay42qjqpp"))))
     (build-system gnu-build-system)
     (arguments
-     `(#:configure-flags (list "--disable-static")
+     ;; Currently the package fails to build when enabling introspection
+     ;; and cross-compiling.
+     `(#:configure-flags (list "--disable-static"
+                               ,@(if (%current-target-system)
+                                     '("--disable-introspection")
+                                     '()))
+       #:disallowed-references
+       ;; Make sure the cross-compiled gdk-pixbuf will be used instead of the
+       ;; native gdk-pixbuf.
+       ,(and (%current-target-system)
+             (list (gexp-input (this-package-native-input "gdk-pixbuf")
+                               #:native?
+                               #true)))
        #:phases
        (modify-phases %standard-phases
          (add-before 'configure 'pre-configure
@@ -3715,9 +3727,12 @@ (define-public librsvg-2.40
                            "bugs/340047.svg"
                            "bugs/749415.svg"))))))))
     (native-inputs
-     (list pkg-config
-           `(,glib "bin") ; glib-mkenums, etc.
-           gobject-introspection)) ; g-ir-compiler, etc.
+     `(,pkg-config
+       (,glib "bin") ; glib-mkenums, etc.
+       ,gobject-introspection ; g-ir-compiler, etc.
+       ,@(if (%current-target-system)
+             (list gdk-pixbuf) ; gdk-pixbuf-query-loaders
+             '())))
     (inputs
      (list pango libcroco libxml2))
     (propagated-inputs
-- 
2.37.3

From c33100536bd1c88c2e6ff8ef180834a6b5b8e350 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Sun, 18 Sep 2022 21:30:17 +0200
Subject: [PATCH 1/4] gnu: libtirpc: Fix cross-compilation for non-Hurd.

* gnu/packages/onc-rpc.scm
(libtirpc/hurd)[arguments]{#:configure-flags}: Copy to ...
(libtirpc)[argument]{#:configure-flags}: ... here and modernise with G-exps
and "guix style".
---
 gnu/packages/onc-rpc.scm | 42 ++++++++++++++++++++++++----------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/gnu/packages/onc-rpc.scm b/gnu/packages/onc-rpc.scm
index 873dc54c30..58c469c927 100644
--- a/gnu/packages/onc-rpc.scm
+++ b/gnu/packages/onc-rpc.scm
@@ -6,6 +6,7 @@
 ;;; Copyright © 2019 Marius Bakke <[email-masked]>
 ;;; Copyright © 2020 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2022 Efraim Flashner <[email-masked]>
+;;; Copyright © 2022 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -26,6 +27,7 @@ (define-module (gnu packages onc-rpc)
   #:use-module (guix licenses)
   #:use-module (guix packages)
   #:use-module (guix download)
+  #:use-module (guix gexp)
   #:use-module (guix git-download)
   #:use-module (gnu packages)
   #:use-module (gnu packages autotools)
@@ -50,19 +52,25 @@ (define-public libtirpc
                 "05zf16ilwwkzv4cccaac32nssrj3rg444n9pskiwbgk6y359an14"))))
     (build-system gnu-build-system)
     (arguments
-     `(#:configure-flags '("--disable-static")
-       #:phases
-       (modify-phases %standard-phases
-         (add-after 'unpack 'adjust-netconfig-reference
-           (lambda* (#:key outputs #:allow-other-keys)
-             (substitute* '("man/netconfig.5"
-                            "man/getnetconfig.3t"
-                            "man/getnetpath.3t"
-                            "man/rpc.3t"
-                            "src/getnetconfig.c"
-                            "tirpc/netconfig.h")
-               (("/etc/netconfig") (string-append (assoc-ref outputs "out")
-                                                  "/etc/netconfig"))))))))
+     (list #:configure-flags
+           ;; When cross-building the target system's krb5-config should be used.
+           ;; TODO(core-updates): Simplify by making it unconditional.
+           (if (%current-target-system)
+               #~(list "--disable-static"
+                       (string-append "KRB5_CONFIG="
+                                      #$(this-package-input "mit-krb5")
+                                      "/bin/krb5-config"))
+               #~'("--disable-static"))
+           #:phases #~(modify-phases %standard-phases
+                        (add-after 'unpack 'adjust-netconfig-reference
+                          (lambda _
+                            (substitute* '("man/netconfig.5"
+                                           "man/getnetconfig.3t"
+                                           "man/getnetpath.3t" "man/rpc.3t"
+                                           "src/getnetconfig.c"
+                                           "tirpc/netconfig.h")
+                              (("/etc/netconfig")
+                               (string-append #$output "/etc/netconfig"))))))))
     (inputs (list mit-krb5))
     (home-page "https://sourceforge.net/projects/libtirpc/")
     (synopsis "Transport-independent Sun/ONC RPC implementation")
@@ -81,10 +89,10 @@ (define-public libtirpc/hurd
     (arguments
      (substitute-keyword-arguments (package-arguments libtirpc)
        ((#:configure-flags flags ''())
-        ;; When cross-building the target system's krb5-config should be used.
-        `(list (string-append "ac_cv_prog_KRB5_CONFIG="
-                              (assoc-ref %build-inputs "mit-krb5")
-                              "/bin/krb5-config")))))))
+        ;; TODO(core-updates): Shouldn't be needed anymore.
+        #~(list (string-append "ac_cv_prog_KRB5_CONFIG="
+                               (assoc-ref %build-inputs "mit-krb5")
+                               "/bin/krb5-config")))))))
 
 (define libtirpc/fixed
   (package
-- 
2.37.3