Subject: Re: [bug#70985] [PATCH v2 5/6] gnu: rust: Guard against cross-libc returning #f.

From: Christopher Baines <[email-masked]>
Date: Fri, 12 Jul 2024 14:56:04 +0100

Efraim Flashner <[email-masked]> 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.