diff mbox series

[bug#61776] gnu: perl-extutils-pkgconfig: Support cross-compilation.

Message ID 20230225011934.27451-1-maxim.cournoyer@gmail.com
State New
Headers show
Series [bug#61776] gnu: perl-extutils-pkgconfig: Support cross-compilation. | expand

Commit Message

Maxim Cournoyer Feb. 25, 2023, 1:19 a.m. UTC
* guix/search-paths.scm ($PKG_CONFIG_PATH): New variable.
* gnu/packages/pkg-config.scm (%pkg-config): Use it.
* gnu/packages/perl.scm (perl-extutils-pkgconfig-for-target): New procedure.
(perl-extutils-pkgconfig): Turn into a syntax that
conditionally expands to...
(cross-perl-extutils-pkgconfig): ... this when %current-target-system is set,
or...
(%perl-extutils-pkgconfig): ... this in a native compilation context.
[arguments]: New field.
[propagated-inputs]: Turn into...
[native-inputs]: ... this.
[native-search-paths]: New field.
---

 gnu/packages/perl.scm       | 63 ++++++++++++++++++++++++++++++++++---
 gnu/packages/pkg-config.scm |  5 ++-
 guix/search-paths.scm       |  8 +++++
 3 files changed, 68 insertions(+), 8 deletions(-)


base-commit: b12ee1ee5b8b53bf27b79ce81b1b2158cc7de484

Comments

Christopher Baines March 2, 2023, 9:51 a.m. UTC | #1
Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> * guix/search-paths.scm ($PKG_CONFIG_PATH): New variable.
> * gnu/packages/pkg-config.scm (%pkg-config): Use it.
> * gnu/packages/perl.scm (perl-extutils-pkgconfig-for-target): New procedure.
> (perl-extutils-pkgconfig): Turn into a syntax that
> conditionally expands to...
> (cross-perl-extutils-pkgconfig): ... this when %current-target-system is set,
> or...
> (%perl-extutils-pkgconfig): ... this in a native compilation context.
> [arguments]: New field.
> [propagated-inputs]: Turn into...
> [native-inputs]: ... this.
> [native-search-paths]: New field.
> ---
>
>  gnu/packages/perl.scm       | 63 ++++++++++++++++++++++++++++++++++---
>  gnu/packages/pkg-config.scm |  5 ++-
>  guix/search-paths.scm       |  8 +++++
>  3 files changed, 68 insertions(+), 8 deletions(-)

I guess I've been sent this email personally because of "teams", it's
quite confusing, I can't determine the bug number from the email, but I
believe it's #61776. I'm going to reply to that bug.

Anyway, according to QA this might break perl-gtk2. Unfortunately the
comparison is a bit confused due to the openmpi related breakage, so do
ignore that in the comparison.
Maxim Cournoyer March 2, 2023, 6:27 p.m. UTC | #2
Hi Christopher,

Christopher Baines <mail@cbaines.net> writes:

> Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:
>
>> * guix/search-paths.scm ($PKG_CONFIG_PATH): New variable.
>> * gnu/packages/pkg-config.scm (%pkg-config): Use it.
>> * gnu/packages/perl.scm (perl-extutils-pkgconfig-for-target): New procedure.
>> (perl-extutils-pkgconfig): Turn into a syntax that
>> conditionally expands to...
>> (cross-perl-extutils-pkgconfig): ... this when %current-target-system is set,
>> or...
>> (%perl-extutils-pkgconfig): ... this in a native compilation context.
>> [arguments]: New field.
>> [propagated-inputs]: Turn into...
>> [native-inputs]: ... this.
>> [native-search-paths]: New field.
>> ---
>>
>>  gnu/packages/perl.scm       | 63 ++++++++++++++++++++++++++++++++++---
>>  gnu/packages/pkg-config.scm |  5 ++-
>>  guix/search-paths.scm       |  8 +++++
>>  3 files changed, 68 insertions(+), 8 deletions(-)
>
> I guess I've been sent this email personally because of "teams", it's
> quite confusing, I can't determine the bug number from the email, but I
> believe it's #61776. I'm going to reply to that bug.

Indeed!  Patman uses '--cc=email' instead of
'--add-header=X:-Debbugs-Cc: email', which explains why recipients do
not see the actual bug #.  I'll see if I can modify the behavior of the
tool.

> Anyway, according to QA this might break perl-gtk2. Unfortunately the
> comparison is a bit confused due to the openmpi related breakage, so do
> ignore that in the comparison.

I'll look into it and report back, thanks!
Maxim Cournoyer March 7, 2023, 3:12 a.m. UTC | #3
Hi,

Christopher Baines <mail@cbaines.net> writes:

> Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:
>
>> * guix/search-paths.scm ($PKG_CONFIG_PATH): New variable.
>> * gnu/packages/pkg-config.scm (%pkg-config): Use it.
>> * gnu/packages/perl.scm (perl-extutils-pkgconfig-for-target): New procedure.
>> (perl-extutils-pkgconfig): Turn into a syntax that
>> conditionally expands to...
>> (cross-perl-extutils-pkgconfig): ... this when %current-target-system is set,
>> or...
>> (%perl-extutils-pkgconfig): ... this in a native compilation context.
>> [arguments]: New field.
>> [propagated-inputs]: Turn into...
>> [native-inputs]: ... this.
>> [native-search-paths]: New field.
>> ---
>>
>>  gnu/packages/perl.scm       | 63 ++++++++++++++++++++++++++++++++++---
>>  gnu/packages/pkg-config.scm |  5 ++-
>>  guix/search-paths.scm       |  8 +++++
>>  3 files changed, 68 insertions(+), 8 deletions(-)
>
> I guess I've been sent this email personally because of "teams", it's
> quite confusing, I can't determine the bug number from the email, but I
> believe it's #61776. I'm going to reply to that bug.
>
> Anyway, according to QA this might break perl-gtk2. Unfortunately the
> comparison is a bit confused due to the openmpi related breakage, so do
> ignore that in the comparison.

I fixed perl-gtk2; it also required pkg-config, which
perl-extutils-pkgconfig no longer propagates, and pushed.

Thanks for the heads-up and the useful data!
diff mbox series

Patch

diff --git a/gnu/packages/perl.scm b/gnu/packages/perl.scm
index 7b97e7adfa..69a897d827 100644
--- a/gnu/packages/perl.scm
+++ b/gnu/packages/perl.scm
@@ -28,7 +28,7 @@ 
 ;;; Copyright © 2020 Paul Garlick <pgarlick@tourbillion-technology.com>
 ;;; Copyright © 2020 Nicolas Goaziou <mail@nicolasgoaziou.fr>
 ;;; Copyright © 2020 Malte Frank Gerdes <malte.f.gerdes@gmail.com>
-;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2021, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
 ;;; Copyright © 2021 Raghav Gururajan <rg@raghavgururajan.name>
 ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
@@ -63,6 +63,8 @@  (define-module (gnu packages perl)
   #:use-module (guix utils)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system perl)
+  #:use-module (guix memoization)
+  #:use-module (guix search-paths)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bash)
   #:use-module (gnu packages compression)
@@ -90,7 +92,8 @@  (define-module (gnu packages perl)
   #:use-module (gnu packages video)
   #:use-module (gnu packages web)
   #:use-module (gnu packages xml)
-  #:use-module (gnu packages xorg))
+  #:use-module (gnu packages xorg)
+  #:export (perl-extutils-pkgconfig))
 
 ;;;
 ;;; Please: Try to add new module packages in alphabetic order.
@@ -4618,7 +4621,10 @@  (define-public perl-extutils-parsexs
 handle Perl/XS typemap files, and their submodules.")
     (license (package-license perl))))
 
-(define-public perl-extutils-pkgconfig
+;; This is the "primitive" perl-extutils-pkgconfig package.  People should use
+;; `perl-extutils-pkgconfig' instead (see below)', but we export
+;; %perl-extutils-pkgconfig so that `fold-packages' finds it.
+(define-public %perl-extutils-pkgconfig
   (package
     (name "perl-extutils-pkgconfig")
     (version "1.16")
@@ -4630,8 +4636,32 @@  (define-public perl-extutils-pkgconfig
                (base32
                 "0vhwh0731rhh1sswmvagq0myn754dnkab8sizh6d3n6pjpcwxsmv"))))
     (build-system perl-build-system)
-    (propagated-inputs
-     (list pkg-config))
+    ;; XXX: Patch the pkg-config references to avoid propagating it, as that
+    ;; would cause the search path to be wrong when cross-building, due to
+    ;; propagated inputs being treated as host inputs, not native inputs.
+    (arguments
+     (list
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'patch-pkg-config-path
+            (lambda* (#:key native-inputs inputs #:allow-other-keys)
+              (let* ((target #$(%current-target-system))
+                     (pkg-config-name (if target
+                                          (string-append target "-pkg-config")
+                                          "pkg-config"))
+                     (pkg-config (search-input-file
+                                  (or native-inputs inputs)
+                                  (string-append "bin/" pkg-config-name))))
+                (substitute* '("Makefile.PL"
+                               "lib/ExtUtils/PkgConfig.pm")
+                  (("qx/pkg-config([^/]*)/" _ args)
+                   (string-append "`" pkg-config args "`"))
+                  (("(`|\")pkg-config" _ quote)
+                   (string-append quote pkg-config)))))))))
+    (native-inputs (list pkg-config))
+    ;; Note: do not use the pkg-config syntax here, as the search paths fields
+    ;; are not thunked and its value could be wrong.
+    (native-search-paths (list $PKG_CONFIG_PATH))
     (home-page "https://metacpan.org/release/ExtUtils-PkgConfig")
     (synopsis "Simplistic interface to pkg-config")
     (description
@@ -4641,6 +4671,29 @@  (define-public perl-extutils-pkgconfig
 It is really just boilerplate code that you would have written yourself.")
     (license license:lgpl2.1+)))
 
+(define-public cross-perl-extutils-pkgconfig
+  (mlambda (target)
+    "Return a perl-extutils-pkgconfig for TARGET, adjusting the search paths."
+    (package
+      (inherit %perl-extutils-pkgconfig)
+      ;; Ignore native inputs, and set `PKG_CONFIG_PATH' for target inputs.
+      (native-search-paths '())
+      (search-paths (list $PKG_CONFIG_PATH)))))
+
+(define (perl-extutils-pkgconfig-for-target target)
+  "Return a perl-extutils-pkgconfig package for TARGET, which may be either #f
+for a native build, or a GNU triplet."
+  (if target
+      (cross-perl-extutils-pkgconfig target)
+      %perl-extutils-pkgconfig))
+
+;; This hack mimics the one for pkg-config, to allow automatically choosing
+;; the native or the cross `pkg-config' depending on whether it's being used
+;; in a cross-build environment or not.
+(define-syntax perl-extutils-pkgconfig
+  (identifier-syntax (perl-extutils-pkgconfig-for-target
+                      (%current-target-system))))
+
 (define-public perl-extutils-typemaps-default
   (package
     (name "perl-extutils-typemaps-default")
diff --git a/gnu/packages/pkg-config.scm b/gnu/packages/pkg-config.scm
index 6263e90f1f..b15b646416 100644
--- a/gnu/packages/pkg-config.scm
+++ b/gnu/packages/pkg-config.scm
@@ -24,6 +24,7 @@  (define-module (gnu packages pkg-config)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix gexp)
+  #:use-module (guix search-paths)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system trivial)
   #:use-module (gnu packages bash)
@@ -66,9 +67,7 @@  (define-public %pkg-config
                 "ac_cv_func_posix_getgrgid_r=yes")
               '()))))
    (native-search-paths
-    (list (search-path-specification
-           (variable "PKG_CONFIG_PATH")
-           (files '("lib/pkgconfig" "lib64/pkgconfig" "share/pkgconfig")))))
+    (list $PKG_CONFIG_PATH))
    (home-page "https://www.freedesktop.org/wiki/Software/pkg-config")
    (license gpl2+)
    (synopsis "Helper tool used when compiling applications and libraries")
diff --git a/guix/search-paths.scm b/guix/search-paths.scm
index 4a8f5131ed..fcbe7b7953 100644
--- a/guix/search-paths.scm
+++ b/guix/search-paths.scm
@@ -34,6 +34,7 @@  (define-module (guix search-paths)
 
             $PATH
             $GUIX_EXTENSIONS_PATH
+            $PKG_CONFIG_PATH
             $SSL_CERT_DIR
             $SSL_CERT_FILE
 
@@ -83,6 +84,13 @@  (define $GUIX_EXTENSIONS_PATH
    (variable "GUIX_EXTENSIONS_PATH")
    (files '("share/guix/extensions"))))
 
+(define $PKG_CONFIG_PATH
+  ;; 'PKG_CONFIG_PATH' is used by pkg-config to locate available header files
+  ;; and libraries, via their .pc files.
+  (search-path-specification
+   (variable "PKG_CONFIG_PATH")
+   (files '("lib/pkgconfig" "lib64/pkgconfig" "share/pkgconfig"))))
+
 ;; Two variables for certificates (info "(guix)X.509 Certificates"),
 ;; respected by OpenSSL and possibly GnuTLS in the future
 ;; (https://gitlab.com/gnutls/gnutls/-/merge_requests/1541)