GNU bug report logs - #70985
[PATCH 0/4] Use specific errors for unsupported targets

Previous Next

Package: guix-patches;

Reported by: Christopher Baines <mail <at> cbaines.net>

Date: Thu, 16 May 2024 15:01:02 UTC

Severity: normal

Tags: patch

Done: Christopher Baines <mail <at> cbaines.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 70985 in the body.
You can then email your comments to 70985 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Thu, 16 May 2024 15:01:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Christopher Baines <mail <at> cbaines.net>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Thu, 16 May 2024 15:01:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: guix-patches <at> gnu.org
Subject: [PATCH 0/4] Use specific errors for unsupported targets
Date: Thu, 16 May 2024 15:59:56 +0100
[Message part 1 (text/plain, inline)]
I think when computing derivations any errors except from a small list
should be treated as bugs.

This has become more of an issue with the avr, or1k-elf and
xtensa-ath9k-elf targets since these targets both seem to not support a
large number of packages, and lead to generic errors or crashes.

I'm seeing this because logs relating to errors computing package
derivations are now taking up most of the data service logs around
processing revisions.


Christopher Baines (4):
  guix: packages: Add new &package-unsupported-target-error.
  gnu: tls: Raise conditions from target->openssl-target.
  gnu: cross-libc*: Raise conditions rather than returning #f.
  guix: build-system: meson: Don't error on unsupported targets.

 gnu/packages/cross-base.scm |  12 +++-
 gnu/packages/tls.scm        |  17 ++++--
 guix/build-system/meson.scm | 115 +++++++++++++++++++-----------------
 guix/packages.scm           |   7 +++
 guix/ui.scm                 |   7 +++
 5 files changed, 98 insertions(+), 60 deletions(-)


base-commit: 5a624adfd7b14c3717237d137bd0766c77f0f570
-- 
2.41.0
[signature.asc (application/pgp-signature, inline)]

Information forwarded to ludo <at> gnu.org, guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Thu, 16 May 2024 15:07:02 GMT) Full text and rfc822 format available.

Message #8 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH 3/4] gnu: cross-libc*: Raise conditions rather than returning
 #f.
Date: Thu, 16 May 2024 16:06:05 +0100
As this means that the error will be clearer for targets which are
unsupported.

* gnu/packages/cross-base.scm (cross-libc*): Raise conditions rather than
returning #f.

Change-Id: I820780ad738d85a98950de5608f3019e961ff7c8
---
 gnu/packages/cross-base.scm | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/gnu/packages/cross-base.scm b/gnu/packages/cross-base.scm
index 2cc5f52e47..0488e397ef 100644
--- a/gnu/packages/cross-base.scm
+++ b/gnu/packages/cross-base.scm
@@ -46,6 +46,8 @@ (define-module (gnu packages cross-base)
   #:use-module (guix gexp)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35)
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
   #:export (cross-binutils
@@ -671,8 +673,8 @@ (define* (cross-libc* target
                       (xbinutils (cross-binutils target))
                       (xheaders (cross-kernel-headers target)))
   "Return LIBC cross-built for TARGET, a GNU triplet. Use XGCC and XBINUTILS
-and the cross tool chain.  If TARGET doesn't have a standard C library #f is
-returned."
+and the cross tool chain.  If TARGET doesn't have a standard C library an
+exception is raised."
   (match target
    ((? target-mingw?)
     (let ((machine (substring target 0 (string-index target #\-))))
@@ -745,7 +747,11 @@ (define* (cross-libc* target
    ((? target-avr?)
     (make-avr-libc #:xbinutils xbinutils
                    #:xgcc xgcc))
-   (else #f)))
+   (else
+    (raise (condition
+            (&package-unsupported-target-error
+             (package libc)
+             (target target)))))))
 
 (define* (cross-gcc-toolchain/implementation target
                                              #:key
-- 
2.41.0





Information forwarded to guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, rekado <at> elephly.net, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Thu, 16 May 2024 15:07:02 GMT) Full text and rfc822 format available.

Message #11 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH 1/4] guix: packages: Add new &package-unsupported-target-error.
Date: Thu, 16 May 2024 16:06:03 +0100
Some packages don't support cross building to specific targets, so add a error
type to signal this.

* guix/packages.scm (&package-unsupported-target-error): New condition type.
[package-unsupported-target-error? package-unsupported-target-error-target):
New procedures.
* guix/ui.scm (call-with-error-handling): Handle this new condition type.

Change-Id: Ib47813399e04b20d616a95f545b6aabe25736e92
---
 guix/packages.scm | 7 +++++++
 guix/ui.scm       | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/guix/packages.scm b/guix/packages.scm
index abe89cdb07..7fbb8d126b 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -173,6 +173,9 @@ (define-module (guix packages)
             package-error-invalid-input
             &package-cross-build-system-error
             package-cross-build-system-error?
+            &package-unsupported-target-error
+            package-unsupported-target-error?
+            package-unsupported-target-error-target
 
             package->bag
             bag->derivation
@@ -850,6 +853,10 @@ (define-condition-type &package-cyclic-dependency-error &package-error
 (define-condition-type &package-cross-build-system-error &package-error
   package-cross-build-system-error?)
 
+(define-condition-type &package-unsupported-target-error &package-error
+  package-unsupported-target-error?
+  (target package-unsupported-target-error-target))
+
 (define* (package-full-name package #:optional (delimiter "@"))
   "Return the full name of PACKAGE--i.e., `NAME <at> VERSION'.  By specifying
 DELIMITER (a string), you can customize what will appear between the name and
diff --git a/guix/ui.scm b/guix/ui.scm
index d82fa533cc..0bb1b3b3ba 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -756,6 +756,13 @@ (define (call-with-error-handling thunk)
                        (location->string loc)
                        (package-full-name package)
                        (build-system-name system))))
+             ((package-unsupported-target-error? c)
+              (let* ((package (package-error-package c))
+                     (loc     (package-location package)))
+                (leave (G_ "~a: ~a: does not support target `~a'~%")
+                       (location->string loc)
+                       (package-full-name package)
+                       (package-unsupported-target-error-target c))))
              ((gexp-input-error? c)
               (let ((input (gexp-error-invalid-input c)))
                 (leave (G_ "~s: invalid G-expression input~%")

base-commit: 5a624adfd7b14c3717237d137bd0766c77f0f570
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Thu, 16 May 2024 15:07:03 GMT) Full text and rfc822 format available.

Message #14 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH 2/4] gnu: tls: Raise conditions from target->openssl-target.
Date: Thu, 16 May 2024 16:06:04 +0100
Rather than rasising generic errors.

* gnu/packages/tls.scm (target->openssl-target): Raise conditions rather than
generic errors.
(openssl-1.1): Call target->openssl-target with the package.

Change-Id: I13c63328cdf6bc177b20879805246ad94ff2665b
---
 gnu/packages/tls.scm | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/tls.scm b/gnu/packages/tls.scm
index 719da8e113..f04e171a9b 100644
--- a/gnu/packages/tls.scm
+++ b/gnu/packages/tls.scm
@@ -84,7 +84,9 @@ (define-module (gnu packages tls)
   #:use-module (gnu packages time)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages base)
-  #:use-module (srfi srfi-1))
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35))
 
 (define-public libtasn1
   (package
@@ -390,7 +392,7 @@ (define-public guile2.2-gnutls
      (modify-inputs (package-inputs guile-gnutls)
        (replace "guile" guile-2.2)))))
 
-(define (target->openssl-target target)
+(define (target->openssl-target pkg target)
   "Return the value to set CONFIGURE_TARGET_ARCH to when cross-compiling
 OpenSSL for TARGET."
   ;; Keep this code outside the build code,
@@ -411,7 +413,10 @@ (define (target->openssl-target target)
                    ((target-linux? target)
                     "linux")
                    (else
-                    (error "unsupported openssl target kernel"))))
+                    (raise (condition
+                            (&package-unsupported-target-error
+                             (package pkg)
+                             (target target)))))))
             (arch
              (cond
               ((target-x86-32? target)
@@ -438,7 +443,10 @@ (define (target->openssl-target target)
               ((target-64bit? target)
                "generic64")
               (else
-               (error "unsupported openssl target architecture")))))
+               (raise (condition
+                       (&package-unsupported-target-error
+                        (package pkg)
+                        (target target))))))))
         (string-append kernel "-" arch))))
 
 (define-public openssl-1.1
@@ -488,6 +496,7 @@ (define-public openssl-1.1
                         (setenv "CROSS_COMPILE" (string-append target "-"))
                         (setenv "CONFIGURE_TARGET_ARCH"
                                 #$(target->openssl-target
+                                   this-package
                                    (%current-target-system))))))
                  #~())
           #$@(if (target-hurd?)
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Thu, 16 May 2024 15:07:03 GMT) Full text and rfc822 format available.

Message #17 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH 4/4] guix: build-system: meson: Don't error on unsupported
 targets.
Date: Thu, 16 May 2024 16:06:06 +0100
Rather than raising generic errors.

* guix/build-system/meson.scm (make-machine-alist): Return #f if the triplet
is unsupported.
(lower): Return #f if the machine alist is #f.

Change-Id: If6a1f8d1c2073e43107406ac186aa9c845005a95
---
 guix/build-system/meson.scm | 115 +++++++++++++++++++-----------------
 1 file changed, 62 insertions(+), 53 deletions(-)

diff --git a/guix/build-system/meson.scm b/guix/build-system/meson.scm
index bf9ca15ecc..b321417773 100644
--- a/guix/build-system/meson.scm
+++ b/guix/build-system/meson.scm
@@ -46,39 +46,46 @@ (define (make-machine-alist triplet)
   "Make an association list describing what should go into
 the ‘host_machine’ section of the cross file when cross-compiling
 for TRIPLET."
-  `((system . ,(cond ((target-hurd? triplet) "gnu")
-                     ((target-linux? triplet) "linux")
-                     ((target-mingw? triplet) "windows")
-                     ((target-avr? triplet) "none")
-                     (#t (error "meson: unknown operating system"))))
-    (cpu_family . ,(cond ((target-x86-32? triplet) "x86")
+  (let ((system
+         (cond
+          ((target-hurd? triplet) "gnu")
+          ((target-linux? triplet) "linux")
+          ((target-mingw? triplet) "windows")
+          ((target-avr? triplet) "none")
+          (else #f)))
+        (cpu-family
+         (cond ((target-x86-32? triplet) "x86")
+               ((target-x86-64? triplet) "x86_64")
+               ((target-arm32? triplet) "arm")
+               ((target-aarch64? triplet) "aarch64")
+               ((target-avr? triplet) "avr")
+               ((target-mips64el? triplet) "mips64")
+               ((target-powerpc? triplet)
+                (if (target-64bit? triplet)
+                    "ppc64"
+                    "ppc"))
+               ((target-riscv64? triplet) "riscv64")
+               (else #f))))
+    (and system
+         cpu-family
+         `((system . ,system)
+           (cpu_family . ,cpu-family)
+           (cpu . ,(cond ((target-x86-32? triplet) ; i386, ..., i686
+                          (substring triplet 0 4))
                          ((target-x86-64? triplet) "x86_64")
-                         ((target-arm32? triplet) "arm")
-                         ((target-aarch64? triplet) "aarch64")
+                         ((target-aarch64? triplet) "armv8-a")
+                         ((target-arm32? triplet) "armv7")
                          ((target-avr? triplet) "avr")
-                         ((target-mips64el? triplet) "mips64")
-                         ((target-powerpc? triplet)
-                          (if (target-64bit? triplet)
-                              "ppc64"
-                              "ppc"))
-                         ((target-riscv64? triplet) "riscv64")
-                         (#t (error "meson: unknown architecture"))))
-    (cpu . ,(cond ((target-x86-32? triplet) ; i386, ..., i686
-                   (substring triplet 0 4))
-                  ((target-x86-64? triplet) "x86_64")
-                  ((target-aarch64? triplet) "armv8-a")
-                  ((target-arm32? triplet) "armv7")
-                  ((target-avr? triplet) "avr")
-                  ;; According to #mesonbuild on OFTC, there does not appear
-                  ;; to be an official-ish list of CPU types recognised by
-                  ;; Meson, the "cpu" field is not used by Meson itself and
-                  ;; most software doesn't look at this field, except perhaps
-                  ;; for selecting optimisations, so set it to something
-                  ;; arbitrary.
-                  (#t "strawberries")))
-    (endian . ,(if (target-little-endian? triplet)
-                   "little"
-                   "big"))))
+                         ;; According to #mesonbuild on OFTC, there does not appear
+                         ;; to be an official-ish list of CPU types recognised by
+                         ;; Meson, the "cpu" field is not used by Meson itself and
+                         ;; most software doesn't look at this field, except perhaps
+                         ;; for selecting optimisations, so set it to something
+                         ;; arbitrary.
+                         (#t "strawberries")))
+           (endian . ,(if (target-little-endian? triplet)
+                          "little"
+                          "big"))))))
 
 (define (make-binaries-alist triplet)
   "Make an associatoin list describing what should go into
@@ -146,29 +153,31 @@ (define* (lower name
             '()
             '(#:target))))
 
-  (bag
-    (name name)
-    (system system) (target target)
-    (build-inputs `(("meson" ,meson)
-                    ("ninja" ,ninja)
-                    ,@native-inputs
-                    ,@(if target '() inputs)
-                    ;; Keep the standard inputs of 'gnu-build-system'.
-                    ,@(if target
-                          (standard-cross-packages target 'host)
+  (and
+   (make-machine-alist target)
+   (bag
+     (name name)
+     (system system) (target target)
+     (build-inputs `(("meson" ,meson)
+                     ("ninja" ,ninja)
+                     ,@native-inputs
+                     ,@(if target '() inputs)
+                     ;; Keep the standard inputs of 'gnu-build-system'.
+                     ,@(if target
+                           (standard-cross-packages target 'host)
+                           '())
+                     ,@(standard-packages)))
+     (host-inputs `(,@(if source
+                          `(("source" ,source))
                           '())
-                    ,@(standard-packages)))
-    (host-inputs `(,@(if source
-                         `(("source" ,source))
-                         '())
-                   ,@(if target inputs '())))
-    ;; Keep the standard inputs of 'gnu-buid-system'.
-    (target-inputs (if target
-                       (standard-cross-packages target 'target)
-                       '()))
-    (outputs outputs)
-    (build (if target meson-cross-build meson-build))
-    (arguments (strip-keyword-arguments private-keywords arguments))))
+                    ,@(if target inputs '())))
+     ;; Keep the standard inputs of 'gnu-buid-system'.
+     (target-inputs (if target
+                        (standard-cross-packages target 'target)
+                        '()))
+     (outputs outputs)
+     (build (if target meson-cross-build meson-build))
+     (arguments (strip-keyword-arguments private-keywords arguments)))))
 
 (define* (meson-build name inputs
                       #:key
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Thu, 16 May 2024 15:14:02 GMT) Full text and rfc822 format available.

Message #20 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Christopher Baines <mail <at> cbaines.net>
Cc: 70985 <at> debbugs.gnu.org
Subject: Re: [bug#70985] [PATCH 4/4] guix: build-system: meson: Don't error
 on unsupported targets.
Date: Thu, 16 May 2024 17:13:32 +0200
Hi,

Christopher Baines <mail <at> cbaines.net> writes:

> Rather than raising generic errors.
>
> * guix/build-system/meson.scm (make-machine-alist): Return #f if the triplet
> is unsupported.
> (lower): Return #f if the machine alist is #f.
>
> Change-Id: If6a1f8d1c2073e43107406ac186aa9c845005a95

[...]

> +  (and
> +   (make-machine-alist target)

I think this call is unnecessary (and kinda confusing because
‘make-machine-alist’ is a pure function) because ‘meson-cross-build’
calls ‘make-cross-file’, which calls ‘make-machine-alist’.

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Thu, 16 May 2024 15:16:01 GMT) Full text and rfc822 format available.

Message #23 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Christopher Baines <mail <at> cbaines.net>
Cc: 70985 <at> debbugs.gnu.org
Subject: Re: [bug#70985] [PATCH 3/4] gnu: cross-libc*: Raise conditions
 rather than returning #f.
Date: Thu, 16 May 2024 17:15:08 +0200
Christopher Baines <mail <at> cbaines.net> writes:

> As this means that the error will be clearer for targets which are
> unsupported.
>
> * gnu/packages/cross-base.scm (cross-libc*): Raise conditions rather than
> returning #f.
>
> Change-Id: I820780ad738d85a98950de5608f3019e961ff7c8

[...]

> -   (else #f)))
> +   (else
> +    (raise (condition
> +            (&package-unsupported-target-error
> +             (package libc)
> +             (target target)))))))

What I'm unsure is whether this works with libc-less triplets such as
‘avr’ or ‘or1k-elf’.

If it does, LGTM.

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Thu, 16 May 2024 15:18:02 GMT) Full text and rfc822 format available.

Message #26 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Christopher Baines <mail <at> cbaines.net>
Cc: 70985 <at> debbugs.gnu.org
Subject: Re: [bug#70985] [PATCH 0/4] Use specific errors for unsupported
 targets
Date: Thu, 16 May 2024 17:16:59 +0200
Christopher Baines <mail <at> cbaines.net> writes:

> I think when computing derivations any errors except from a small list
> should be treated as bugs.
>
> This has become more of an issue with the avr, or1k-elf and
> xtensa-ath9k-elf targets since these targets both seem to not support a
> large number of packages, and lead to generic errors or crashes.
>
> I'm seeing this because logs relating to errors computing package
> derivations are now taking up most of the data service logs around
> processing revisions.

Looks to me like a much welcome improvement, modulo the minor issues I
commented on.  Thanks!

Ludo'.




Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Thu, 16 May 2024 16:11:02 GMT) Full text and rfc822 format available.

Message #29 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 70985 <at> debbugs.gnu.org
Subject: Re: [bug#70985] [PATCH 4/4] guix: build-system: meson: Don't error
 on unsupported targets.
Date: Thu, 16 May 2024 17:10:16 +0100
[Message part 1 (text/plain, inline)]
Ludovic Courtès <ludo <at> gnu.org> writes:

> Christopher Baines <mail <at> cbaines.net> writes:
>
>> Rather than raising generic errors.
>>
>> * guix/build-system/meson.scm (make-machine-alist): Return #f if the triplet
>> is unsupported.
>> (lower): Return #f if the machine alist is #f.
>>
>> Change-Id: If6a1f8d1c2073e43107406ac186aa9c845005a95
>
> [...]
>
>> +  (and
>> +   (make-machine-alist target)
>
> I think this call is unnecessary (and kinda confusing because
> ‘make-machine-alist’ is a pure function) because ‘meson-cross-build’
> calls ‘make-cross-file’, which calls ‘make-machine-alist’.

The situation here is that the meson build system does support cross
builds, but make-machine-alist calls error for some targets which I'm
treating as a bug here, because error isn't really machine readable.

I think this line should actually be (or (not target)
(make-machine-alist target)) to handle the case where the target is #f,
but this is sort of helpful in that it changes the error to the usual
error when the build system doesn't support cross builds.

This is still far from perfect though as the UI would say that "build
system `meson' does not support cross builds", which is obviously wrong,
it just doesn't support cross builds for the given target. I'm not sure
how to signal this though?
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Thu, 16 May 2024 16:18:02 GMT) Full text and rfc822 format available.

Message #32 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 70985 <at> debbugs.gnu.org
Subject: Re: [bug#70985] [PATCH 3/4] gnu: cross-libc*: Raise conditions
 rather than returning #f.
Date: Thu, 16 May 2024 17:16:42 +0100
[Message part 1 (text/plain, inline)]
Ludovic Courtès <ludo <at> gnu.org> writes:

> Christopher Baines <mail <at> cbaines.net> writes:
>
>> As this means that the error will be clearer for targets which are
>> unsupported.
>>
>> * gnu/packages/cross-base.scm (cross-libc*): Raise conditions rather than
>> returning #f.
>>
>> Change-Id: I820780ad738d85a98950de5608f3019e961ff7c8
>
> [...]
>
>> -   (else #f)))
>> +   (else
>> +    (raise (condition
>> +            (&package-unsupported-target-error
>> +             (package libc)
>> +             (target target)))))))
>
> What I'm unsure is whether this works with libc-less triplets such as
> ‘avr’ or ‘or1k-elf’.

Hmm, it seems like this is erroring in some cases where it didn't
before, I'm not sure why though.

I ended up here through rust-sysroot-for-... since it calls
cross-libc. Handling cross-libc returning #f in the packages which use
it seems error prone, hence adding the exception inside of cross-libc*.

It looks liek cross-gcc-toolchain/implementation is expecting cross-libc
to return #f in some cases though, so maybe I need to add a guard there
somehow to handle the exception and ignore it, as happens when it
returns #f.
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 17 May 2024 09:55:01 GMT) Full text and rfc822 format available.

Message #35 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Jean-Pierre De Jesus Diaz <jean <at> foundation.xyz>
To: 70985 <at> debbugs.gnu.org
Cc: ludo <at> gnu.org, mail <at> cbaines.net
Subject: Re: [bug#70985] [PATCH 3/4] gnu: cross-libc*: Raise conditions rather
 than returning #f.
Date: Fri, 17 May 2024 09:53:16 +0000
Hello,

>> Christopher Baines <mail <at> cbaines.net> writes:
>>
>>> As this means that the error will be clearer for targets which are
>>> unsupported.
>>>
>>> * gnu/packages/cross-base.scm (cross-libc*): Raise conditions rather than
>>> returning #f.
>>>
>>> Change-Id: I820780ad738d85a98950de5608f3019e961ff7c8
>>
>> [...]
>>
>>> -   (else #f)))
>>> +   (else
>>> +    (raise (condition
>>> +            (&package-unsupported-target-error
>>> +             (package libc)
>>> +             (target target)))))))
>>
>> What I'm unsure is whether this works with libc-less triplets such as
>> ‘avr’ or ‘or1k-elf’.
>
>Hmm, it seems like this is erroring in some cases where it didn't
>before, I'm not sure why though.
>
>I ended up here through rust-sysroot-for-... since it calls
>cross-libc. Handling cross-libc returning #f in the packages which use
>it seems error prone, hence adding the exception inside of cross-libc*.
>
>It looks liek cross-gcc-toolchain/implementation is expecting cross-libc
>to return #f in some cases though, so maybe I need to add a guard there
>somehow to handle the exception and ignore it, as happens when it
>returns #f.

This is because some targets as Ludovic mentioned don't have a proper
libc, like most *-elf targets.  Also, gnu-build-system also depends on
cross-libc returning #f to check for those targets that don't have a
libc in `cross-standard-packages'.

Thanks,

Jean-Pierre




Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 05 Jul 2024 16:07:02 GMT) Full text and rfc822 format available.

Message #38 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH v2 2/6] gnu: tls: Raise conditions from target->openssl-target.
Date: Fri,  5 Jul 2024 18:05:59 +0200
Rather than rasising generic errors.

* gnu/packages/tls.scm (target->openssl-target): Raise conditions rather than
generic errors.
(openssl-1.1): Call target->openssl-target with the package.

Change-Id: I13c63328cdf6bc177b20879805246ad94ff2665b
---
 gnu/packages/tls.scm | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/tls.scm b/gnu/packages/tls.scm
index 760b917768..fdc003731d 100644
--- a/gnu/packages/tls.scm
+++ b/gnu/packages/tls.scm
@@ -84,7 +84,9 @@ (define-module (gnu packages tls)
   #:use-module (gnu packages time)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages base)
-  #:use-module (srfi srfi-1))
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35))
 
 (define-public libtasn1
   (package
@@ -390,7 +392,7 @@ (define-public guile2.2-gnutls
      (modify-inputs (package-inputs guile-gnutls)
        (replace "guile" guile-2.2)))))
 
-(define (target->openssl-target target)
+(define (target->openssl-target pkg target)
   "Return the value to set CONFIGURE_TARGET_ARCH to when cross-compiling
 OpenSSL for TARGET."
   ;; Keep this code outside the build code,
@@ -411,7 +413,10 @@ (define (target->openssl-target target)
                    ((target-linux? target)
                     "linux")
                    (else
-                    (error "unsupported openssl target kernel"))))
+                    (raise (condition
+                            (&package-unsupported-target-error
+                             (package pkg)
+                             (target target)))))))
             (arch
              (cond
               ((target-x86-32? target)
@@ -438,7 +443,10 @@ (define (target->openssl-target target)
               ((target-64bit? target)
                "generic64")
               (else
-               (error "unsupported openssl target architecture")))))
+               (raise (condition
+                       (&package-unsupported-target-error
+                        (package pkg)
+                        (target target))))))))
         (string-append kernel "-" arch))))
 
 (define-public openssl-1.1
@@ -488,6 +496,7 @@ (define-public openssl-1.1
                         (setenv "CROSS_COMPILE" (string-append target "-"))
                         (setenv "CONFIGURE_TARGET_ARCH"
                                 #$(target->openssl-target
+                                   this-package
                                    (%current-target-system))))))
                  #~())
           #$@(if (target-hurd?)
-- 
2.45.2





Information forwarded to cox.katherine.e+guix <at> gmail.com, sharlatanus <at> gmail.com, guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 05 Jul 2024 16:07:02 GMT) Full text and rfc822 format available.

Message #41 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH v2 6/6] build-system: go: Properly handle when a target is
 unsupported.
Date: Fri,  5 Jul 2024 18:06:03 +0200
* guix/build-system/go.scm (go-target): Properly handle when a target is
unsupported.

Change-Id: Ibc0becb8eb0a712d21116112c44e2bbbb707ddf4
---
 guix/build-system/go.scm | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/guix/build-system/go.scm b/guix/build-system/go.scm
index 0934fded07..fc53b3be9f 100644
--- a/guix/build-system/go.scm
+++ b/guix/build-system/go.scm
@@ -33,6 +33,8 @@ (define-module (guix build-system go)
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35)
   #:export (%go-build-system-modules
             go-build
             go-build-system
@@ -101,7 +103,13 @@ (define (go-target target)
                (_ arch))
              (match os
                ((or "mingw32" "cygwin") "windows")
-               (_ os))))))
+               (_ os))))
+      (_
+       (raise
+        (condition
+         (&unsupported-cross-compilation-target-error
+          (build-system go-build-system)
+          (target target)))))))
 
 (define %go-build-system-modules
   ;; Build-side modules imported and used by default.
-- 
2.45.2





Information forwarded to guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 05 Jul 2024 16:07:03 GMT) Full text and rfc822 format available.

Message #44 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH v2 1/6] guix: packages: Add new
 &package-unsupported-target-error.
Date: Fri,  5 Jul 2024 18:05:58 +0200
Some packages don't support cross building to specific targets, so add a error
type to signal this.

* guix/packages.scm (&package-unsupported-target-error): New condition type.
[package-unsupported-target-error? package-unsupported-target-error-target):
New procedures.
* guix/ui.scm (call-with-error-handling): Handle this new condition type.

Change-Id: Ib47813399e04b20d616a95f545b6aabe25736e92
---
 guix/packages.scm | 7 +++++++
 guix/ui.scm       | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/guix/packages.scm b/guix/packages.scm
index f3a9a61785..e793714f2e 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -173,6 +173,9 @@ (define-module (guix packages)
             package-error-invalid-input
             &package-cross-build-system-error
             package-cross-build-system-error?
+            &package-unsupported-target-error
+            package-unsupported-target-error?
+            package-unsupported-target-error-target
 
             package->bag
             bag->derivation
@@ -850,6 +853,10 @@ (define-condition-type &package-cyclic-dependency-error &package-error
 (define-condition-type &package-cross-build-system-error &package-error
   package-cross-build-system-error?)
 
+(define-condition-type &package-unsupported-target-error &package-error
+  package-unsupported-target-error?
+  (target package-unsupported-target-error-target))
+
 (define* (package-full-name package #:optional (delimiter "@"))
   "Return the full name of PACKAGE--i.e., `NAME <at> VERSION'.  By specifying
 DELIMITER (a string), you can customize what will appear between the name and
diff --git a/guix/ui.scm b/guix/ui.scm
index d82fa533cc..0bb1b3b3ba 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -756,6 +756,13 @@ (define (call-with-error-handling thunk)
                        (location->string loc)
                        (package-full-name package)
                        (build-system-name system))))
+             ((package-unsupported-target-error? c)
+              (let* ((package (package-error-package c))
+                     (loc     (package-location package)))
+                (leave (G_ "~a: ~a: does not support target `~a'~%")
+                       (location->string loc)
+                       (package-full-name package)
+                       (package-unsupported-target-error-target c))))
              ((gexp-input-error? c)
               (let ((input (gexp-error-invalid-input c)))
                 (leave (G_ "~s: invalid G-expression input~%")

base-commit: 5ee2799cabba4b2d462ac064a98789d7bca07923
-- 
2.45.2





Information forwarded to efraim <at> flashner.co.il, guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 05 Jul 2024 16:07:03 GMT) Full text and rfc822 format available.

Message #47 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH v2 5/6] gnu: rust: Guard against cross-libc returning #f.
Date: Fri,  5 Jul 2024 18:06:02 +0200
* gnu/packages/rust.scm (make-rust-sysroot/implementation): Guard against
cross-libc returning #f.

Change-Id: Ia0d5c889c6f5cd3478ad985c79feb9ba1c472c29
---
 gnu/packages/rust.scm | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
index a385344473..f1de34b277 100644
--- a/gnu/packages/rust.scm
+++ b/gnu/packages/rust.scm
@@ -73,7 +73,9 @@ (define-module (gnu packages rust)
   #:use-module (ice-9 match)
   #:use-module (ice-9 optargs)
   #:use-module (srfi srfi-1)
-  #:use-module (srfi srfi-26))
+  #:use-module (srfi srfi-26)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35))
 
 ;; This is the hash for the empty file, and the reason it's relevant is not
 ;; the most obvious.
@@ -1464,7 +1466,11 @@ (define make-rust-sysroot/implementation
          (modify-inputs (package-native-inputs base-rust)
                         (prepend (cross-gcc target
                                             #:libc (cross-libc target))
-                                 (cross-libc target)
+                                 (or (cross-libc target) ; could be #f
+                                     (raise (condition
+                                             (&package-unsupported-target-error
+                                              (package (libc-for-target target))
+                                              (target target)))))
                                  (cross-binutils target)))))
       (properties
        `((hidden? . #t)
-- 
2.45.2





Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 05 Jul 2024 16:07:03 GMT) Full text and rfc822 format available.

Message #50 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH v2 4/6] build-system: meson: Use a more specific exception.
Date: Fri,  5 Jul 2024 18:06:01 +0200
This is handled by (guix ui).

* guix/build-system/meson.scm (make-machine-alist): Use a more specific
exception.

Change-Id: I842ba63739fdefe04460e938c7bc8aa54ea57b96
---
 guix/build-system/meson.scm | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/guix/build-system/meson.scm b/guix/build-system/meson.scm
index bf9ca15ecc..04d2241c79 100644
--- a/guix/build-system/meson.scm
+++ b/guix/build-system/meson.scm
@@ -30,6 +30,8 @@ (define-module (guix build-system meson)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system glib-or-gtk)
   #:use-module (guix packages)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35)
   #:export (%meson-build-system-modules
             meson-build-system
             make-cross-file))
@@ -50,7 +52,12 @@ (define (make-machine-alist triplet)
                      ((target-linux? triplet) "linux")
                      ((target-mingw? triplet) "windows")
                      ((target-avr? triplet) "none")
-                     (#t (error "meson: unknown operating system"))))
+                     (else
+                      (raise
+                       (condition
+                        (&unsupported-cross-compilation-target-error
+                         (build-system meson-build-system)
+                         (target triplet)))))))
     (cpu_family . ,(cond ((target-x86-32? triplet) "x86")
                          ((target-x86-64? triplet) "x86_64")
                          ((target-arm32? triplet) "arm")
@@ -62,7 +69,12 @@ (define (make-machine-alist triplet)
                               "ppc64"
                               "ppc"))
                          ((target-riscv64? triplet) "riscv64")
-                         (#t (error "meson: unknown architecture"))))
+                         (else
+                          (raise
+                           (condition
+                            (&unsupported-cross-compilation-target-error
+                             (build-system meson-build-system)
+                             (target triplet)))))))
     (cpu . ,(cond ((target-x86-32? triplet) ; i386, ..., i686
                    (substring triplet 0 4))
                   ((target-x86-64? triplet) "x86_64")
-- 
2.45.2





Information forwarded to guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 05 Jul 2024 16:07:04 GMT) Full text and rfc822 format available.

Message #53 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH v2 3/6] guix: packages: Add
 &unsupported-cross-compilation-target-error.
Date: Fri,  5 Jul 2024 18:06:00 +0200
* guix/packages.scm (&unsupported-cross-compilation-target-error): New
variable.
* guix/ui.scm (call-with-error-handling): Handle this new condition type.

Change-Id: I9e7782ee4799b5fecb3c890a75008c35c003f55d
---
 guix/packages.scm | 10 ++++++++++
 guix/ui.scm       |  7 +++++++
 2 files changed, 17 insertions(+)

diff --git a/guix/packages.scm b/guix/packages.scm
index e793714f2e..c953db9a03 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -160,6 +160,11 @@ (define-module (guix packages)
             %cuirass-supported-systems
             supported-package?
 
+            &unsupported-cross-compilation-target-error
+            unsupported-cross-compilation-target-error?
+            unsupported-cross-compilation-target-error-build-system
+            unsupported-cross-compilation-target-error-target
+
             &package-error
             package-error?
             package-error-package
@@ -834,6 +839,11 @@ (define-syntax-rule (this-package-native-input name)
 
 ;; Error conditions.
 
+(define-condition-type &unsupported-cross-compilation-target-error &error
+  unsupported-cross-compilation-target-error?
+  (build-system unsupported-cross-compilation-target-error-build-system)
+  (target unsupported-cross-compilation-target-error-target))
+
 (define-condition-type &package-error &error
   package-error?
   (package package-error-package))
diff --git a/guix/ui.scm b/guix/ui.scm
index 0bb1b3b3ba..9db6f6e9d7 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -763,6 +763,13 @@ (define (call-with-error-handling thunk)
                        (location->string loc)
                        (package-full-name package)
                        (package-unsupported-target-error-target c))))
+             ((unsupported-cross-compilation-target-error? c)
+              (let ((build-system
+                      (unsupported-cross-compilation-target-error-build-system c))
+                    (target (unsupported-cross-compilation-target-error-target c)))
+                (leave (G_ "the `~a' build system: does not support target `~a'~%")
+                       (build-system-name build-system)
+                       target)))
              ((gexp-input-error? c)
               (let ((input (gexp-error-invalid-input c)))
                 (leave (G_ "~s: invalid G-expression input~%")
-- 
2.45.2





Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Sun, 07 Jul 2024 16:28:03 GMT) Full text and rfc822 format available.

Message #56 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Efraim Flashner <efraim <at> flashner.co.il>
To: Christopher Baines <mail <at> cbaines.net>
Cc: 70985 <at> debbugs.gnu.org
Subject: Re: [bug#70985] [PATCH v2 5/6] gnu: rust: Guard against cross-libc
 returning #f.
Date: Sun, 7 Jul 2024 19:26:35 +0300
[Message part 1 (text/plain, inline)]
On Fri, Jul 05, 2024 at 06:06:02PM +0200, Christopher Baines wrote:
> * gnu/packages/rust.scm (make-rust-sysroot/implementation): Guard against
> cross-libc returning #f.
> 
> Change-Id: Ia0d5c889c6f5cd3478ad985c79feb9ba1c472c29
> ---
>  gnu/packages/rust.scm | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
> index a385344473..f1de34b277 100644
> --- a/gnu/packages/rust.scm
> +++ b/gnu/packages/rust.scm
> @@ -73,7 +73,9 @@ (define-module (gnu packages rust)
>    #:use-module (ice-9 match)
>    #:use-module (ice-9 optargs)
>    #:use-module (srfi srfi-1)
> -  #:use-module (srfi srfi-26))
> +  #:use-module (srfi srfi-26)
> +  #:use-module (srfi srfi-34)
> +  #:use-module (srfi srfi-35))
>  
>  ;; This is the hash for the empty file, and the reason it's relevant is not
>  ;; the most obvious.
> @@ -1464,7 +1466,11 @@ (define make-rust-sysroot/implementation
>           (modify-inputs (package-native-inputs base-rust)
>                          (prepend (cross-gcc target
>                                              #:libc (cross-libc target))
> -                                 (cross-libc target)
> +                                 (or (cross-libc target) ; could be #f
> +                                     (raise (condition
> +                                             (&package-unsupported-target-error
> +                                              (package (libc-for-target target))
> +                                              (target target)))))
>                                   (cross-binutils target)))))
>        (properties
>         `((hidden? . #t)
> -- 
> 2.45.2

rust does support architectures without a libc, for example the mingw
targets a few lines above this snippet. I think it would make more sense
to only include (cross-libc target) and not if not.

I just tried building zoxide for powerpc-linux-gnu without (cross-libc
target) and it tried to link with the x86_64 libc, so it looks like it
is necessary where it is available.

How about we make this section even worse with:
(if (false-if-exception (cross-libc target))
    (modify-inputs ...
                   (cross-libc target)
                   ...)
    (modify-inputs ...))    ; no (cross-libc target)

In the meantime, I'll try to figure something out for actually putting
everything inside one modify-inputs so we don't have an ever expanding
number of them.

-- 
Efraim Flashner   <efraim <at> flashner.co.il>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Sun, 07 Jul 2024 16:59:01 GMT) Full text and rfc822 format available.

Message #59 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Efraim Flashner <efraim <at> flashner.co.il>
To: Christopher Baines <mail <at> cbaines.net>
Cc: 70985 <at> debbugs.gnu.org
Subject: Re: [bug#70985] [PATCH v2 5/6] gnu: rust: Guard against cross-libc
 returning #f.
Date: Sun, 7 Jul 2024 19:57:43 +0300
[Message part 1 (text/plain, inline)]
On Fri, Jul 05, 2024 at 06:06:02PM +0200, Christopher Baines wrote:
> * gnu/packages/rust.scm (make-rust-sysroot/implementation): Guard against
> cross-libc returning #f.
> 
> Change-Id: Ia0d5c889c6f5cd3478ad985c79feb9ba1c472c29
> ---
>  gnu/packages/rust.scm | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
> index a385344473..f1de34b277 100644
> --- a/gnu/packages/rust.scm
> +++ b/gnu/packages/rust.scm
> @@ -73,7 +73,9 @@ (define-module (gnu packages rust)
>    #:use-module (ice-9 match)
>    #:use-module (ice-9 optargs)
>    #:use-module (srfi srfi-1)
> -  #:use-module (srfi srfi-26))
> +  #:use-module (srfi srfi-26)
> +  #:use-module (srfi srfi-34)
> +  #:use-module (srfi srfi-35))
>  
>  ;; This is the hash for the empty file, and the reason it's relevant is not
>  ;; the most obvious.
> @@ -1464,7 +1466,11 @@ (define make-rust-sysroot/implementation
>           (modify-inputs (package-native-inputs base-rust)
>                          (prepend (cross-gcc target
>                                              #:libc (cross-libc target))
> -                                 (cross-libc target)
> +                                 (or (cross-libc target) ; could be #f
> +                                     (raise (condition
> +                                             (&package-unsupported-target-error
> +                                              (package (libc-for-target target))
> +                                              (target target)))))
>                                   (cross-binutils target)))))
>        (properties
>         `((hidden? . #t)
> -- 
> 2.45.2

This will probably work:

(native-inputs
 `((,(string-append "gcc-cross-" target) ,(cross-gcc target
                                                     #:libc (cross-libc target)))
   ,(when (false-if-exception (cross-libc target))
          `(,(string-append "glibc-cross-" target) ,(cross-libc target)))
   (,(string-append "binutils-cross-" target) ,(cross-binutils target))
   ,(when (target-mingw? target)
      (if (string=? "i686-w64-mingw32" target)
          `("mingw-w64-i686-winpthreads" ,mingw-w64-i686-winpthreads)
          `("mingw-w64-x86_64-winpthreads" ,mingw-w64-x86_64-winpthreads)))
   ,@(package-native-inputs base-rust)))

-- 
Efraim Flashner   <efraim <at> flashner.co.il>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Tue, 09 Jul 2024 09:26:01 GMT) Full text and rfc822 format available.

Message #62 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: Efraim Flashner <efraim <at> flashner.co.il>
Cc: 70985 <at> debbugs.gnu.org
Subject: Re: [bug#70985] [PATCH v2 5/6] gnu: rust: Guard against cross-libc
 returning #f.
Date: Tue, 09 Jul 2024 11:25:04 +0200
[Message part 1 (text/plain, inline)]
Efraim Flashner <efraim <at> flashner.co.il> writes:

> On Fri, Jul 05, 2024 at 06:06:02PM +0200, Christopher Baines wrote:
>> * gnu/packages/rust.scm (make-rust-sysroot/implementation): Guard against
>> cross-libc returning #f.
>> 
>> Change-Id: Ia0d5c889c6f5cd3478ad985c79feb9ba1c472c29
>> ---
>>  gnu/packages/rust.scm | 10 ++++++++--
>>  1 file changed, 8 insertions(+), 2 deletions(-)
>> 
>> diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
>> index a385344473..f1de34b277 100644
>> --- a/gnu/packages/rust.scm
>> +++ b/gnu/packages/rust.scm
>> @@ -73,7 +73,9 @@ (define-module (gnu packages rust)
>>    #:use-module (ice-9 match)
>>    #:use-module (ice-9 optargs)
>>    #:use-module (srfi srfi-1)
>> -  #:use-module (srfi srfi-26))
>> +  #:use-module (srfi srfi-26)
>> +  #:use-module (srfi srfi-34)
>> +  #:use-module (srfi srfi-35))
>>  
>>  ;; This is the hash for the empty file, and the reason it's relevant is not
>>  ;; the most obvious.
>> @@ -1464,7 +1466,11 @@ (define make-rust-sysroot/implementation
>>           (modify-inputs (package-native-inputs base-rust)
>>                          (prepend (cross-gcc target
>>                                              #:libc (cross-libc target))
>> -                                 (cross-libc target)
>> +                                 (or (cross-libc target) ; could be #f
>> +                                     (raise (condition
>> +                                             (&package-unsupported-target-error
>> +                                              (package (libc-for-target target))
>> +                                              (target target)))))
>>                                   (cross-binutils target)))))
>>        (properties
>>         `((hidden? . #t)
>> -- 
>> 2.45.2
>
> This will probably work:
>
> (native-inputs
>  `((,(string-append "gcc-cross-" target) ,(cross-gcc target
>                                                      #:libc (cross-libc target)))
>    ,(when (false-if-exception (cross-libc target))
>           `(,(string-append "glibc-cross-" target) ,(cross-libc target)))
>    (,(string-append "binutils-cross-" target) ,(cross-binutils target))
>    ,(when (target-mingw? target)
>       (if (string=? "i686-w64-mingw32" target)
>           `("mingw-w64-i686-winpthreads" ,mingw-w64-i686-winpthreads)
>           `("mingw-w64-x86_64-winpthreads" ,mingw-w64-x86_64-winpthreads)))
>    ,@(package-native-inputs base-rust)))

Thanks for taking a look. In the latest patches cross-libc isn't
changing to raise an exception (as that ended up being too complicated),
so I'm not sure the false-if-exception is going to work.

I'd also maybe stick with modify-inputs, as at least that avoids the
older inputs style.

If I've followed your first email correctly, are you thinking of
something like this?

      (native-inputs
       (if (target-mingw? target)
         (modify-inputs (package-native-inputs base-rust)
                        (prepend (cross-gcc target
                                            #:libc (cross-libc target))
                                 (cross-binutils target)
                                 (if (string=? "i686-w64-mingw32" target)
                                     mingw-w64-i686-winpthreads
                                     mingw-w64-x86_64-winpthreads)))
         (modify-inputs (or (and=> (cross-libc target)
                                   (lambda (x-libc)
                                     (modify-inputs
                                         (package-native-inputs base-rust)
                                       (prepend x-libc))))
                            (package-native-inputs base-rust))
                        (prepend (cross-gcc target
                                            #:libc (cross-libc target))
                                 (cross-binutils target)))))
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Tue, 09 Jul 2024 15:23:01 GMT) Full text and rfc822 format available.

Message #65 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Efraim Flashner <efraim <at> flashner.co.il>
To: Christopher Baines <mail <at> cbaines.net>
Cc: 70985 <at> debbugs.gnu.org
Subject: Re: [bug#70985] [PATCH v2 5/6] gnu: rust: Guard against cross-libc
 returning #f.
Date: Tue, 9 Jul 2024 18:21:05 +0300
[Message part 1 (text/plain, inline)]
On Tue, Jul 09, 2024 at 11:25:04AM +0200, Christopher Baines wrote:
> Efraim Flashner <efraim <at> flashner.co.il> writes:
> 
> > On Fri, Jul 05, 2024 at 06:06:02PM +0200, Christopher Baines wrote:
> >> * gnu/packages/rust.scm (make-rust-sysroot/implementation): Guard against
> >> cross-libc returning #f.
> >> 
> >> Change-Id: Ia0d5c889c6f5cd3478ad985c79feb9ba1c472c29
> >> ---
> >>  gnu/packages/rust.scm | 10 ++++++++--
> >>  1 file changed, 8 insertions(+), 2 deletions(-)
> >> 
> >> diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
> >> index a385344473..f1de34b277 100644
> >> --- a/gnu/packages/rust.scm
> >> +++ b/gnu/packages/rust.scm
> >> @@ -73,7 +73,9 @@ (define-module (gnu packages rust)
> >>    #:use-module (ice-9 match)
> >>    #:use-module (ice-9 optargs)
> >>    #:use-module (srfi srfi-1)
> >> -  #:use-module (srfi srfi-26))
> >> +  #:use-module (srfi srfi-26)
> >> +  #:use-module (srfi srfi-34)
> >> +  #:use-module (srfi srfi-35))
> >>  
> >>  ;; This is the hash for the empty file, and the reason it's relevant is not
> >>  ;; the most obvious.
> >> @@ -1464,7 +1466,11 @@ (define make-rust-sysroot/implementation
> >>           (modify-inputs (package-native-inputs base-rust)
> >>                          (prepend (cross-gcc target
> >>                                              #:libc (cross-libc target))
> >> -                                 (cross-libc target)
> >> +                                 (or (cross-libc target) ; could be #f
> >> +                                     (raise (condition
> >> +                                             (&package-unsupported-target-error
> >> +                                              (package (libc-for-target target))
> >> +                                              (target target)))))
> >>                                   (cross-binutils target)))))
> >>        (properties
> >>         `((hidden? . #t)
> >> -- 
> >> 2.45.2
> >
> > This will probably work:
> >
> > (native-inputs
> >  `((,(string-append "gcc-cross-" target) ,(cross-gcc target
> >                                                      #:libc (cross-libc target)))
> >    ,(when (false-if-exception (cross-libc target))
> >           `(,(string-append "glibc-cross-" target) ,(cross-libc target)))
> >    (,(string-append "binutils-cross-" target) ,(cross-binutils target))
> >    ,(when (target-mingw? target)
> >       (if (string=? "i686-w64-mingw32" target)
> >           `("mingw-w64-i686-winpthreads" ,mingw-w64-i686-winpthreads)
> >           `("mingw-w64-x86_64-winpthreads" ,mingw-w64-x86_64-winpthreads)))
> >    ,@(package-native-inputs base-rust)))
> 
> Thanks for taking a look. In the latest patches cross-libc isn't
> changing to raise an exception (as that ended up being too complicated),
> so I'm not sure the false-if-exception is going to work.

false-if-exception should work. We use it a couple of times in golang
packaging to skip the tests if we're building with gccgo.

(unless
  ;; The tests fail when run with gccgo.
  (false-if-exception (search-input-file inputs "/bin/gccgo"))
  (apply (assoc-ref %standard-phases 'check) args)))))))

> I'd also maybe stick with modify-inputs, as at least that avoids the
> older inputs style.
> 
> If I've followed your first email correctly, are you thinking of
> something like this?
> 
>       (native-inputs
>        (if (target-mingw? target)
>          (modify-inputs (package-native-inputs base-rust)
>                         (prepend (cross-gcc target
>                                             #:libc (cross-libc target))
>                                  (cross-binutils target)
>                                  (if (string=? "i686-w64-mingw32" target)
>                                      mingw-w64-i686-winpthreads
>                                      mingw-w64-x86_64-winpthreads)))
>          (modify-inputs (or (and=> (cross-libc target)
>                                    (lambda (x-libc)
>                                      (modify-inputs
>                                          (package-native-inputs base-rust)
>                                        (prepend x-libc))))
>                             (package-native-inputs base-rust))
>                         (prepend (cross-gcc target
>                                             #:libc (cross-libc target))
>                                  (cross-binutils target)))))

Thanks, I hate it :) That said, if it works then it's fine. (I lose my
confidence from (cross-libc target) getting renamed to x-libc)

I played around with it a bit more. The problem is that we can only
logic our way around before modify-inputs or inside
prepend/append/delete, so options are a bit limited as to what we can
do. I came up with the following, which I think should also work:

      (native-inputs
       (modify-inputs (package-native-inputs base-rust)
         (prepend (cross-binutils target))
         (prepend
           (cond ((and (target-mingw? target)
                       (target-x86-32? target))
                  mingw-w64-i686-winpthreads)
                 ((and (target-mingw? target)
                       (target-x86-64? target))
                  mingw-w64-x86_64-winpthreads)
                 ((or (target-linux? target)
                      (target-hurd? target))
                  (cross-libc target))
                 ;; We need something, and duplicating cross-binutils
                 ;; doesn't cause any problems.
                 (#t (cross-binutils target))))
         (prepend (cross-gcc target
                             #:libc (cross-libc target)))))

I don't like the '#t' branch of the cond, but it doesn't seem to break
anything. And we're explicit about who gets cross-libc.

I would like something like the following to work, but some of the
inputs get lost
      (native-inputs
       (modify-inputs (package-native-inputs base-rust)
         (prepend
           (cond ((and (target-mingw? target)
                       (target-x86-32? target))
                  (cross-gcc target
                             #:libc (cross-libc target))
                  mingw-w64-i686-winpthreads
                  (cross-binutils target))
                 ((and (target-mingw? target)
                       (target-x86-64? target))
                  (cross-gcc target
                             #:libc (cross-libc target))
                  mingw-w64-x86_64-winpthreads
                  (cross-binutils target))
                 ((or (target-linux? target)
                      (target-hurd? target))
                  (cross-gcc target
                             #:libc (cross-libc target))
                  (cross-libc target)
                  (cross-binutils target))
                 (else
                  (cross-gcc target
                             #:libc (cross-libc target))
                  (cross-binutils target))))))

-- 
Efraim Flashner   <efraim <at> flashner.co.il>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
[signature.asc (application/pgp-signature, inline)]

Information forwarded to efraim <at> flashner.co.il, guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 12 Jul 2024 13:42:01 GMT) Full text and rfc822 format available.

Message #68 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH v3 5/6] gnu: rust: Guard against unsupported rust targets.
Date: Fri, 12 Jul 2024 14:41:44 +0100
As cross-libc may return #f in this case, and the config.toml file
construction will also fail if the platform rust-target is #f..

* gnu/packages/rust.scm (make-rust-sysroot/implementation): Guard against
unsupported rust targets.

Change-Id: Ia0d5c889c6f5cd3478ad985c79feb9ba1c472c29
---
 gnu/packages/rust.scm | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
index a385344473..8119f4560a 100644
--- a/gnu/packages/rust.scm
+++ b/gnu/packages/rust.scm
@@ -73,7 +73,9 @@ (define-module (gnu packages rust)
   #:use-module (ice-9 match)
   #:use-module (ice-9 optargs)
   #:use-module (srfi srfi-1)
-  #:use-module (srfi srfi-26))
+  #:use-module (srfi srfi-26)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35))
 
 ;; This is the hash for the empty file, and the reason it's relevant is not
 ;; the most obvious.
@@ -1309,6 +1311,13 @@ (define*-public (make-rust-sysroot target)
 
 (define make-rust-sysroot/implementation
   (mlambda (target base-rust)
+    (unless (platform-rust-target (lookup-platform-by-target target))
+      (raise
+       (condition
+        (&package-unsupported-target-error
+         (package base-rust)
+         (target target)))))
+
     (package
       (inherit base-rust)
       (name (string-append "rust-sysroot-for-" target))
-- 
2.45.2





Information forwarded to guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 12 Jul 2024 13:42:02 GMT) Full text and rfc822 format available.

Message #71 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH v3 1/6] guix: packages: Add new
 &package-unsupported-target-error.
Date: Fri, 12 Jul 2024 14:41:40 +0100
Some packages don't support cross building to specific targets, so add a error
type to signal this.

* guix/packages.scm (&package-unsupported-target-error): New condition type.
[package-unsupported-target-error? package-unsupported-target-error-target):
New procedures.
* guix/ui.scm (call-with-error-handling): Handle this new condition type.

Change-Id: Ib47813399e04b20d616a95f545b6aabe25736e92
---
 guix/packages.scm | 7 +++++++
 guix/ui.scm       | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/guix/packages.scm b/guix/packages.scm
index f3a9a61785..e793714f2e 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -173,6 +173,9 @@ (define-module (guix packages)
             package-error-invalid-input
             &package-cross-build-system-error
             package-cross-build-system-error?
+            &package-unsupported-target-error
+            package-unsupported-target-error?
+            package-unsupported-target-error-target
 
             package->bag
             bag->derivation
@@ -850,6 +853,10 @@ (define-condition-type &package-cyclic-dependency-error &package-error
 (define-condition-type &package-cross-build-system-error &package-error
   package-cross-build-system-error?)
 
+(define-condition-type &package-unsupported-target-error &package-error
+  package-unsupported-target-error?
+  (target package-unsupported-target-error-target))
+
 (define* (package-full-name package #:optional (delimiter "@"))
   "Return the full name of PACKAGE--i.e., `NAME <at> VERSION'.  By specifying
 DELIMITER (a string), you can customize what will appear between the name and
diff --git a/guix/ui.scm b/guix/ui.scm
index d82fa533cc..0bb1b3b3ba 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -756,6 +756,13 @@ (define (call-with-error-handling thunk)
                        (location->string loc)
                        (package-full-name package)
                        (build-system-name system))))
+             ((package-unsupported-target-error? c)
+              (let* ((package (package-error-package c))
+                     (loc     (package-location package)))
+                (leave (G_ "~a: ~a: does not support target `~a'~%")
+                       (location->string loc)
+                       (package-full-name package)
+                       (package-unsupported-target-error-target c))))
              ((gexp-input-error? c)
               (let ((input (gexp-error-invalid-input c)))
                 (leave (G_ "~s: invalid G-expression input~%")

base-commit: d11912ac254d1dd8f5d1f5d67c59d0f6d6b68006
-- 
2.45.2





Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 12 Jul 2024 13:42:02 GMT) Full text and rfc822 format available.

Message #74 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH v3 4/6] build-system: meson: Use a more specific exception.
Date: Fri, 12 Jul 2024 14:41:43 +0100
This is handled by (guix ui).

* guix/build-system/meson.scm (make-machine-alist): Use a more specific
exception.

Change-Id: I842ba63739fdefe04460e938c7bc8aa54ea57b96
---
 guix/build-system/meson.scm | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/guix/build-system/meson.scm b/guix/build-system/meson.scm
index bf9ca15ecc..04d2241c79 100644
--- a/guix/build-system/meson.scm
+++ b/guix/build-system/meson.scm
@@ -30,6 +30,8 @@ (define-module (guix build-system meson)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system glib-or-gtk)
   #:use-module (guix packages)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35)
   #:export (%meson-build-system-modules
             meson-build-system
             make-cross-file))
@@ -50,7 +52,12 @@ (define (make-machine-alist triplet)
                      ((target-linux? triplet) "linux")
                      ((target-mingw? triplet) "windows")
                      ((target-avr? triplet) "none")
-                     (#t (error "meson: unknown operating system"))))
+                     (else
+                      (raise
+                       (condition
+                        (&unsupported-cross-compilation-target-error
+                         (build-system meson-build-system)
+                         (target triplet)))))))
     (cpu_family . ,(cond ((target-x86-32? triplet) "x86")
                          ((target-x86-64? triplet) "x86_64")
                          ((target-arm32? triplet) "arm")
@@ -62,7 +69,12 @@ (define (make-machine-alist triplet)
                               "ppc64"
                               "ppc"))
                          ((target-riscv64? triplet) "riscv64")
-                         (#t (error "meson: unknown architecture"))))
+                         (else
+                          (raise
+                           (condition
+                            (&unsupported-cross-compilation-target-error
+                             (build-system meson-build-system)
+                             (target triplet)))))))
     (cpu . ,(cond ((target-x86-32? triplet) ; i386, ..., i686
                    (substring triplet 0 4))
                   ((target-x86-64? triplet) "x86_64")
-- 
2.45.2





Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 12 Jul 2024 13:42:03 GMT) Full text and rfc822 format available.

Message #77 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH v3 2/6] gnu: tls: Raise conditions from target->openssl-target.
Date: Fri, 12 Jul 2024 14:41:41 +0100
Rather than rasising generic errors.

* gnu/packages/tls.scm (target->openssl-target): Raise conditions rather than
generic errors.
(openssl-1.1): Call target->openssl-target with the package.

Change-Id: I13c63328cdf6bc177b20879805246ad94ff2665b
---
 gnu/packages/tls.scm | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/tls.scm b/gnu/packages/tls.scm
index 760b917768..fdc003731d 100644
--- a/gnu/packages/tls.scm
+++ b/gnu/packages/tls.scm
@@ -84,7 +84,9 @@ (define-module (gnu packages tls)
   #:use-module (gnu packages time)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages base)
-  #:use-module (srfi srfi-1))
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35))
 
 (define-public libtasn1
   (package
@@ -390,7 +392,7 @@ (define-public guile2.2-gnutls
      (modify-inputs (package-inputs guile-gnutls)
        (replace "guile" guile-2.2)))))
 
-(define (target->openssl-target target)
+(define (target->openssl-target pkg target)
   "Return the value to set CONFIGURE_TARGET_ARCH to when cross-compiling
 OpenSSL for TARGET."
   ;; Keep this code outside the build code,
@@ -411,7 +413,10 @@ (define (target->openssl-target target)
                    ((target-linux? target)
                     "linux")
                    (else
-                    (error "unsupported openssl target kernel"))))
+                    (raise (condition
+                            (&package-unsupported-target-error
+                             (package pkg)
+                             (target target)))))))
             (arch
              (cond
               ((target-x86-32? target)
@@ -438,7 +443,10 @@ (define (target->openssl-target target)
               ((target-64bit? target)
                "generic64")
               (else
-               (error "unsupported openssl target architecture")))))
+               (raise (condition
+                       (&package-unsupported-target-error
+                        (package pkg)
+                        (target target))))))))
         (string-append kernel "-" arch))))
 
 (define-public openssl-1.1
@@ -488,6 +496,7 @@ (define-public openssl-1.1
                         (setenv "CROSS_COMPILE" (string-append target "-"))
                         (setenv "CONFIGURE_TARGET_ARCH"
                                 #$(target->openssl-target
+                                   this-package
                                    (%current-target-system))))))
                  #~())
           #$@(if (target-hurd?)
-- 
2.45.2





Information forwarded to guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 12 Jul 2024 13:42:03 GMT) Full text and rfc822 format available.

Message #80 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH v3 3/6] guix: packages: Add
 &unsupported-cross-compilation-target-error.
Date: Fri, 12 Jul 2024 14:41:42 +0100
* guix/packages.scm (&unsupported-cross-compilation-target-error): New
variable.
* guix/ui.scm (call-with-error-handling): Handle this new condition type.

Change-Id: I9e7782ee4799b5fecb3c890a75008c35c003f55d
---
 guix/packages.scm | 10 ++++++++++
 guix/ui.scm       |  7 +++++++
 2 files changed, 17 insertions(+)

diff --git a/guix/packages.scm b/guix/packages.scm
index e793714f2e..c953db9a03 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -160,6 +160,11 @@ (define-module (guix packages)
             %cuirass-supported-systems
             supported-package?
 
+            &unsupported-cross-compilation-target-error
+            unsupported-cross-compilation-target-error?
+            unsupported-cross-compilation-target-error-build-system
+            unsupported-cross-compilation-target-error-target
+
             &package-error
             package-error?
             package-error-package
@@ -834,6 +839,11 @@ (define-syntax-rule (this-package-native-input name)
 
 ;; Error conditions.
 
+(define-condition-type &unsupported-cross-compilation-target-error &error
+  unsupported-cross-compilation-target-error?
+  (build-system unsupported-cross-compilation-target-error-build-system)
+  (target unsupported-cross-compilation-target-error-target))
+
 (define-condition-type &package-error &error
   package-error?
   (package package-error-package))
diff --git a/guix/ui.scm b/guix/ui.scm
index 0bb1b3b3ba..9db6f6e9d7 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -763,6 +763,13 @@ (define (call-with-error-handling thunk)
                        (location->string loc)
                        (package-full-name package)
                        (package-unsupported-target-error-target c))))
+             ((unsupported-cross-compilation-target-error? c)
+              (let ((build-system
+                      (unsupported-cross-compilation-target-error-build-system c))
+                    (target (unsupported-cross-compilation-target-error-target c)))
+                (leave (G_ "the `~a' build system: does not support target `~a'~%")
+                       (build-system-name build-system)
+                       target)))
              ((gexp-input-error? c)
               (let ((input (gexp-error-invalid-input c)))
                 (leave (G_ "~s: invalid G-expression input~%")
-- 
2.45.2





Information forwarded to cox.katherine.e+guix <at> gmail.com, sharlatanus <at> gmail.com, guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 12 Jul 2024 13:43:02 GMT) Full text and rfc822 format available.

Message #83 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: 70985 <at> debbugs.gnu.org
Subject: [PATCH v3 6/6] build-system: go: Properly handle when a target is
 unsupported.
Date: Fri, 12 Jul 2024 14:41:45 +0100
* guix/build-system/go.scm (go-target): Properly handle when a target is
unsupported.

Change-Id: Ibc0becb8eb0a712d21116112c44e2bbbb707ddf4
---
 guix/build-system/go.scm | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/guix/build-system/go.scm b/guix/build-system/go.scm
index 0934fded07..fc53b3be9f 100644
--- a/guix/build-system/go.scm
+++ b/guix/build-system/go.scm
@@ -33,6 +33,8 @@ (define-module (guix build-system go)
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35)
   #:export (%go-build-system-modules
             go-build
             go-build-system
@@ -101,7 +103,13 @@ (define (go-target target)
                (_ arch))
              (match os
                ((or "mingw32" "cygwin") "windows")
-               (_ os))))))
+               (_ os))))
+      (_
+       (raise
+        (condition
+         (&unsupported-cross-compilation-target-error
+          (build-system go-build-system)
+          (target target)))))))
 
 (define %go-build-system-modules
   ;; Build-side modules imported and used by default.
-- 
2.45.2





Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 12 Jul 2024 13:57:02 GMT) Full text and rfc822 format available.

Message #86 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: Efraim Flashner <efraim <at> flashner.co.il>
Cc: 70985 <at> debbugs.gnu.org
Subject: Re: [bug#70985] [PATCH v2 5/6] gnu: rust: Guard against cross-libc
 returning #f.
Date: Fri, 12 Jul 2024 14:56:04 +0100
[Message part 1 (text/plain, inline)]
Efraim Flashner <efraim <at> flashner.co.il> writes:

>> I'd also maybe stick with modify-inputs, as at least that avoids the
>> older inputs style.
>> 
>> If I've followed your first email correctly, are you thinking of
>> something like this?
>> 
>>       (native-inputs
>>        (if (target-mingw? target)
>>          (modify-inputs (package-native-inputs base-rust)
>>                         (prepend (cross-gcc target
>>                                             #:libc (cross-libc target))
>>                                  (cross-binutils target)
>>                                  (if (string=? "i686-w64-mingw32" target)
>>                                      mingw-w64-i686-winpthreads
>>                                      mingw-w64-x86_64-winpthreads)))
>>          (modify-inputs (or (and=> (cross-libc target)
>>                                    (lambda (x-libc)
>>                                      (modify-inputs
>>                                          (package-native-inputs base-rust)
>>                                        (prepend x-libc))))
>>                             (package-native-inputs base-rust))
>>                         (prepend (cross-gcc target
>>                                             #:libc (cross-libc target))
>>                                  (cross-binutils target)))))
>
> Thanks, I hate it :) That said, if it works then it's fine. (I lose my
> confidence from (cross-libc target) getting renamed to x-libc)
>
> I played around with it a bit more. The problem is that we can only
> logic our way around before modify-inputs or inside
> prepend/append/delete, so options are a bit limited as to what we can
> do. I came up with the following, which I think should also work:
>
>       (native-inputs
>        (modify-inputs (package-native-inputs base-rust)
>          (prepend (cross-binutils target))
>          (prepend
>            (cond ((and (target-mingw? target)
>                        (target-x86-32? target))
>                   mingw-w64-i686-winpthreads)
>                  ((and (target-mingw? target)
>                        (target-x86-64? target))
>                   mingw-w64-x86_64-winpthreads)
>                  ((or (target-linux? target)
>                       (target-hurd? target))
>                   (cross-libc target))
>                  ;; We need something, and duplicating cross-binutils
>                  ;; doesn't cause any problems.
>                  (#t (cross-binutils target))))
>          (prepend (cross-gcc target
>                              #:libc (cross-libc target)))))

I looked at this further and actually tried building the derivations for
different targets, and realised that there needs to be a
platform-rust-target set for it to work.

So maybe we don't need to bother with the inputs here and can just add a
guard at the top, e.g.

 (define make-rust-sysroot/implementation
   (mlambda (target base-rust)
+    (unless (platform-rust-target (lookup-platform-by-target target))
+      (raise
+       (condition
+        (&package-unsupported-target-error
+         (package base-rust)
+         (target target)))))
+


I've sent a new patch series to this effect.
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#70985; Package guix-patches. (Fri, 12 Jul 2024 14:30:02 GMT) Full text and rfc822 format available.

Message #89 received at 70985 <at> debbugs.gnu.org (full text, mbox):

From: Efraim Flashner <efraim <at> flashner.co.il>
To: Christopher Baines <mail <at> cbaines.net>
Cc: 70985 <at> debbugs.gnu.org
Subject: Re: [bug#70985] [PATCH v3 5/6] gnu: rust: Guard against unsupported
 rust targets.
Date: Fri, 12 Jul 2024 17:28:04 +0300
[Message part 1 (text/plain, inline)]
I like this. We can always add more platforms later with their
platform-rust-target later as needed.

On Fri, Jul 12, 2024 at 02:41:44PM +0100, Christopher Baines wrote:
> As cross-libc may return #f in this case, and the config.toml file
> construction will also fail if the platform rust-target is #f..
> 
> * gnu/packages/rust.scm (make-rust-sysroot/implementation): Guard against
> unsupported rust targets.
> 
> Change-Id: Ia0d5c889c6f5cd3478ad985c79feb9ba1c472c29
> ---
>  gnu/packages/rust.scm | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
> index a385344473..8119f4560a 100644
> --- a/gnu/packages/rust.scm
> +++ b/gnu/packages/rust.scm
> @@ -73,7 +73,9 @@ (define-module (gnu packages rust)
>    #:use-module (ice-9 match)
>    #:use-module (ice-9 optargs)
>    #:use-module (srfi srfi-1)
> -  #:use-module (srfi srfi-26))
> +  #:use-module (srfi srfi-26)
> +  #:use-module (srfi srfi-34)
> +  #:use-module (srfi srfi-35))
>  
>  ;; This is the hash for the empty file, and the reason it's relevant is not
>  ;; the most obvious.
> @@ -1309,6 +1311,13 @@ (define*-public (make-rust-sysroot target)
>  
>  (define make-rust-sysroot/implementation
>    (mlambda (target base-rust)
> +    (unless (platform-rust-target (lookup-platform-by-target target))
> +      (raise
> +       (condition
> +        (&package-unsupported-target-error
> +         (package base-rust)
> +         (target target)))))
> +
>      (package
>        (inherit base-rust)
>        (name (string-append "rust-sysroot-for-" target))
> -- 
> 2.45.2
> 
> 
> 

-- 
Efraim Flashner   <efraim <at> flashner.co.il>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
[signature.asc (application/pgp-signature, inline)]

Reply sent to Christopher Baines <mail <at> cbaines.net>:
You have taken responsibility. (Thu, 18 Jul 2024 14:17:01 GMT) Full text and rfc822 format available.

Notification sent to Christopher Baines <mail <at> cbaines.net>:
bug acknowledged by developer. (Thu, 18 Jul 2024 14:17:02 GMT) Full text and rfc822 format available.

Message #94 received at 70985-done <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: Efraim Flashner <efraim <at> flashner.co.il>
Cc: 70985-done <at> debbugs.gnu.org
Subject: Re: [bug#70985] [PATCH v3 5/6] gnu: rust: Guard against unsupported
 rust targets.
Date: Thu, 18 Jul 2024 15:16:47 +0100
[Message part 1 (text/plain, inline)]
Efraim Flashner <efraim <at> flashner.co.il> writes:

> I like this. We can always add more platforms later with their
> platform-rust-target later as needed.

Great. Late reply but I went ahead and pushed this to master as
32eda739664901b6df680e79f869e439a326572f.

Chris
[signature.asc (application/pgp-signature, inline)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 16 Aug 2024 11:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 209 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.