Subject: [bug#50770] [PATCH core-updates-frozen] Cross-compile more (indirect) GTK+ dependencies

From: Maxime Devos <[email-masked]>
Date: Fri, 24 Sep 2021 01:22:37 +0200

User: guix
Usertags: cross-compilation

Hi guix,

This small patch series fixes a few easy-to-fix cross-compilation failures
of a few (indirect) dependencies of gtk+.  The first patch can also
be found at <https://issues.guix.gnu.org/50201#69>.

Greetings,
Maxime
From 732b0b84217ab5fd5bb74018f12a8f774b61b828 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Thu, 23 Sep 2021 12:33:01 +0200
Subject: [PATCH 1/6] gnu: pkg-config: Fix typo in search paths.

* gnu/packages/pkg-config.scm
  (pkg-config-for-build)[native-search-paths]: Use "PKG_CONFIG_PATH_FOR_BUILD"
  instead of "PKG_CONFIG_PATH".
---
 gnu/packages/pkg-config.scm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gnu/packages/pkg-config.scm b/gnu/packages/pkg-config.scm
index 2b4173a7db..dd0d18ae36 100644
--- a/gnu/packages/pkg-config.scm
+++ b/gnu/packages/pkg-config.scm
@@ -166,5 +166,5 @@ exec ~a \"$@\""
      (map (lambda (original)
             (search-path-specification
              (inherit original)
-             (variable "PKG_CONFIG_FOR_BUILD")))
+             (variable "PKG_CONFIG_PATH_FOR_BUILD")))
           (package-native-search-paths %pkg-config)))))

base-commit: 5b674fe5c317425405075c0deab222cbaed80d83
-- 
2.33.0

From fd922e259d430ed5617a541ea2d4f5f76eb1c1c0 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Thu, 23 Sep 2021 23:08:25 +0200
Subject: [PATCH 2/6] gnu: llvm: Let it cross-compile.

The derivation when compiling natively remains the same,
so this doesn't cause any rebuilds.

* gnu/packages/llvm.scm (llvm-12)[arguments]<#:configure-flags>: Set
  LLVM_TABLEGEN, LLVM_DEFAULT_TARGET_TRIPLE, LLVM_TARGET_ARCH and
  LLVM_TARGETS_TO_BUILD when cross-compiling.
---
 gnu/packages/llvm.scm | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 7cfa02ec99..3d62965cb8 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -17,6 +17,7 @@
 ;;; Copyright © 2020 Giacomo Leidi <[email-masked]>
 ;;; Copyright © 2020 Jakub Kądziołka <[email-masked]>
 ;;; Copyright © 2020 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;; Copyright © 2021 Julien Lepiller <[email-masked]>
 ;;; Copyright © 2021 Lars-Dominik Braun <[email-masked]>
 ;;;
@@ -39,6 +40,7 @@
   #:use-module (guix packages)
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (guix download)
+  #:use-module (guix gexp)
   #:use-module (guix git-download)
   #:use-module (guix memoization)
   #:use-module (guix utils)
@@ -498,13 +500,30 @@ output), and Binutils.")
     (propagated-inputs
      `(("zlib" ,zlib)))                 ;to use output from llvm-config
     (arguments
-     `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
-                           "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
-                           "-DBUILD_SHARED_LIBS:BOOL=TRUE"
-                           "-DLLVM_ENABLE_FFI:BOOL=TRUE"
-                           "-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities
-                           "-DLLVM_INSTALL_UTILS=ON") ; Needed for rustc.
-
+     ;; TODO(core-updates): Unconditionally use quasiquote
+     `(#:configure-flags
+       ,#~(#$(if (%current-target-system)
+                 #~quasiquote
+                 #~quote)
+           ;; These options are required for cross-compiling LLVM according to
+           ;; https://llvm.org/docs/HowToCrossCompileLLVM.html.
+           (#$@(if (%current-target-system)
+                   #~(,(string-append "-DLLVM_TABLEGEN="
+                                      #+(file-append this-package
+                                                     "/bin/llvm-tblgen"))
+                      #$(string-append "-DLLVM_DEFAULT_TARGET_TRIPLE="
+                                       (%current-target-system))
+                      #$(string-append "-DLLVM_TARGET_ARCH="
+                                       (system->llvm-target))
+                      #$(string-append "-DLLVM_TARGETS_TO_BUILD="
+                                       (system->llvm-target)))
+                   #~())
+            "-DCMAKE_SKIP_BUILD_RPATH=FALSE"
+            "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
+            "-DBUILD_SHARED_LIBS:BOOL=TRUE"
+            "-DLLVM_ENABLE_FFI:BOOL=TRUE"
+            "-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities
+            "-DLLVM_INSTALL_UTILS=ON")) ; Needed for rustc.
        ;; Don't use '-g' during the build, to save space.
        #:build-type "Release"
        #:phases
-- 
2.33.0

From dd6654f5924f329f126e8e1df0e932c376c0983a Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Thu, 23 Sep 2021 23:47:17 +0200
Subject: [PATCH 3/6] gnu: xev: Pass --disable-malloc0returnsnull when
 cross-compiling.

This fixes a configure error when cross-compilation and doesn't
cause any rebuilds.

* gnu/packages/xorg.scm (xev)[arguments]<#:configure-flags>:
  Add malloc0flags.
---
 gnu/packages/xorg.scm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gnu/packages/xorg.scm b/gnu/packages/xorg.scm
index 235ff184f9..f3e9d93ba7 100644
--- a/gnu/packages/xorg.scm
+++ b/gnu/packages/xorg.scm
@@ -2441,6 +2441,7 @@ DRI (Direct Rendering Infrastructure) drivers.")
           (base32
             "1ql592pdhddhkipkrsxn929y9l2nn02a5fh2z3dx47kmzs5y006p"))))
     (build-system gnu-build-system)
+    (arguments `(#:configure-flags ',(malloc0-flags)))
     (inputs
       `(("libxrender" ,libxrender)
         ("libxrandr" ,libxrandr)
-- 
2.33.0

From 89d148355a1380a3365bac4d1ed8e11248781e35 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Thu, 23 Sep 2021 23:49:18 +0200
Subject: [PATCH 4/6] gnu: libxv: Pass --disable-malloc0returnsnull when
 cross-compiling.

This fixes a configure error when cross-compilation and doesn't
cause any rebuilds.

* gnu/packages/xorg.scm (libxv)[arguments]<#:configure-flags>:
  Add malloc0flags.
---
 gnu/packages/xorg.scm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gnu/packages/xorg.scm b/gnu/packages/xorg.scm
index f3e9d93ba7..f53962d618 100644
--- a/gnu/packages/xorg.scm
+++ b/gnu/packages/xorg.scm
@@ -4959,7 +4959,7 @@ protocol and arbitrary X extension protocol.")
             "125hn06bd3d8y97hm2pbf5j55gg4r2hpd3ifad651i4sr7m16v6j"))))
     (build-system gnu-build-system)
     (arguments
-     '(#:configure-flags '("--disable-static")))
+     `(#:configure-flags '(,@(malloc0-flags) "--disable-static")))
     (propagated-inputs
      `(("xorgproto" ,xorgproto)))
     (inputs
-- 
2.33.0

From 79d8fd6f4877eed6987c15df7dbdfe8b7ef4d4bc Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Thu, 23 Sep 2021 23:49:42 +0200
Subject: [PATCH 5/6] gnu: libxvmc: Pass --disable-malloc0returnsnull when
 cross-compiling.

This fixes a configure error when cross-compilation and doesn't
cause any rebuilds.

* gnu/packages/xorg.scm (libxvmc)[arguments]<#:configure-flags>:
  Add malloc0flags.
---
 gnu/packages/xorg.scm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gnu/packages/xorg.scm b/gnu/packages/xorg.scm
index f53962d618..92706c0240 100644
--- a/gnu/packages/xorg.scm
+++ b/gnu/packages/xorg.scm
@@ -5272,7 +5272,7 @@ new API's in libXft, or the legacy API's in libX11.")
             "1kbdjsvkm5l7axv7g477qj18sab2wnqhliy6197syzizgfbsfgbb"))))
     (build-system gnu-build-system)
     (arguments
-     '(#:configure-flags '("--disable-static")))
+     `(#:configure-flags '(,@(malloc0-flags) "--disable-static")))
     (propagated-inputs
       `(("libxv" ,libxv)))
     (inputs
-- 
2.33.0

From b68db7b327b4c0f372efbb7fb39791230adb54c9 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Thu, 23 Sep 2021 23:50:28 +0200
Subject: [PATCH 6/6] gnu: gusb: Don't build introspection data when
 cross-compiling.

This fixes a configure error when cross-compilation and doesn't
cause any rebuilds.

* gnu/packages/gnome.scm (gusb)[arguments]<#:configure-flags>:
  Set 'introspection' and 'vapi' to false.
---
 gnu/packages/gnome.scm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/gnome.scm b/gnu/packages/gnome.scm
index 497713cddc..47eb552603 100644
--- a/gnu/packages/gnome.scm
+++ b/gnu/packages/gnome.scm
@@ -6573,7 +6573,14 @@ DAV, and others.")
      `(("glib" ,glib)
        ("libusb" ,libusb)))
     (arguments
-     `(#:tests? #f)) ;libusb fails to initialize.  Wonder what that is.
+     `(#:tests? #f ;libusb fails to initialize.  Wonder what that is.
+       #:configure-flags
+       ,(if (%current-target-system)
+            ;; Introspection data cannot currently be cross-compiled.
+            ''("-Dintrospection=false"
+               ;; Requires introspection data.
+               "-Dvapi=false")
+            ''())))
     (home-page "https://github.com/hughsie/libgusb")
     (synopsis "GLib binding for libusb1")
     (description
-- 
2.33.0