all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Mathieu Othacehe <m.othacehe@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guix-devel@gnu.org
Subject: Re: Cross-compilation broken on canonical packages.
Date: Sun, 22 Dec 2019 17:31:04 +0100	[thread overview]
Message-ID: <87fthc9vav.fsf@gmail.com> (raw)
In-Reply-To: <871rt0ntvy.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1855 bytes --]


Hello Ludo,

Thanks for your explanation :)

> This is expected: packages in ‘%final-inputs’ (those returned by
> ‘canonical-package’) are rooted in the bootstrap graph and cannot be
> cross-compiled.

Looking at canonical-package in (gnu packages commencement), I see that
there's already a switch on (%current-target-system). The given package
is directly returned if (%current-target-system) is set, which appears
to be what we want!

--8<---------------cut here---------------start------------->8---
         ;; In general we want CANON, except if we're cross-compiling: CANON
         ;; uses explicit inputs, so it is "anchored" in the bootstrapped
         ;; process, with dependencies on things that cannot be
         ;; cross-compiled.
         (if (%current-target-system)
             package
             canon))
--8<---------------cut here---------------end--------------->8---

But, this doesn't work as expected. I guess it is because of
(%current-target-system) evaluation time.

As I'm not fully understand everything here, I would propose to define a
gexp-compiler for "canonical-packages", but there's maybe a better thing
to do?

Anyway, the snippet below works fine with a gexp-compiler (patch
attached) and doesn't work with the current implementation of
canonical-package.

--8<---------------cut here---------------start------------->8---
(use-modules (guix)
             (gnu packages base))

(run-with-store (open-connection)
  (mlet* %store-monad
      ((gexp    -> #~(#$(canonical-package grep)))
       (drv     (gexp->script "test.scm" gexp
                               #:target "aarch64-linux-gnu"))
       (build   (built-derivations (list drv))))
    (return #t)))
--8<---------------cut here---------------end--------------->8---

WDYT?

Thanks,

Mathieu

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-wip-Add-a-canonical-package-gexp-compiler.patch --]
[-- Type: text/x-diff, Size: 3698 bytes --]

From 6266c46181d2880684c89999519423be8d8a8ea3 Mon Sep 17 00:00:00 2001
From: Mathieu Othacehe <m.othacehe@gmail.com>
Date: Sun, 22 Dec 2019 17:25:59 +0100
Subject: [PATCH] wip: Add a canonical-package gexp compiler.

---
 gnu/packages/base.scm         |  6 ++++++
 gnu/packages/commencement.scm | 40 +++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/gnu/packages/base.scm b/gnu/packages/base.scm
index e8150708c0..22b6e05dae 100644
--- a/gnu/packages/base.scm
+++ b/gnu/packages/base.scm
@@ -1337,6 +1337,12 @@ package needs iconv ,@(libiconv-if-needed) should be added."
          (proc  (module-ref iface 'canonical-package)))
     (proc package)))
 
+(define-public (canonical-package* package)
+  ;; Avoid circular dependency by lazily resolving 'commencement'.
+  (let* ((iface (resolve-interface '(gnu packages commencement)))
+         (proc  (module-ref iface 'make-canonical-package)))
+    (proc package)))
+
 (define-public (%final-inputs)
   "Return the list of \"final inputs\"."
   ;; Avoid circular dependency by lazily resolving 'commencement'.
diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm
index 14ecf246d4..41ab430388 100644
--- a/gnu/packages/commencement.scm
+++ b/gnu/packages/commencement.scm
@@ -54,8 +54,11 @@
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system trivial)
   #:use-module (guix memoization)
+  #:use-module (guix gexp)
+  #:use-module (guix records)
   #:use-module (guix utils)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-9)
   #:use-module (srfi srfi-26)
   #:use-module (ice-9 vlist)
   #:use-module (ice-9 match)
@@ -2613,5 +2616,42 @@ Fortran development to be installed in user profiles.  This includes
 gfortran, as well as libc (headers and binaries, plus debugging symbols
 in the @code{debug} output), and binutils.")))
 
+(define-record-type <canonical-package>
+  (%make-canonical-package name)
+  canonical-package?
+  (name canonical-package-name))
+
+(define-public (make-canonical-package package)
+  (%make-canonical-package package))
+
+(define-gexp-compiler (canonical-package-compiler
+                       (canonical-package <canonical-package>) system target)
+  ;; Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
+  ;; the implicit inputs of 'gnu-build-system', return that one, otherwise
+  ;; return PACKAGE.
+  ;;
+  ;; The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
+  ;; COREUTILS-FINAL vs. COREUTILS, etc.
+  (let ((name->package (fold (lambda (input result)
+                               (match input
+                                 ((_ package . outputs)
+                                  (vhash-cons (package-full-name package)
+                                              package result))))
+                             vlist-null
+                             `(("guile" ,guile-final)
+                               ,@%final-inputs)))
+        (package (canonical-package-name canonical-package)))
+    ;; XXX: This doesn't handle dependencies of the final inputs, such as
+    ;; libunistring, GMP, etc.
+    (match (vhash-assoc (package-full-name package) name->package)
+      ((_ . canon)
+       ;; In general we want CANON, except if we're cross-compiling: CANON
+       ;; uses explicit inputs, so it is "anchored" in the bootstrapped
+       ;; process, with dependencies on things that cannot be
+       ;; cross-compiled.
+       (if target
+           (package->cross-derivation package target system)
+           (package->derivation (pk canon) system)))
+      (_ (package->derivation package system)))))
 
 ;;; commencement.scm ends here
-- 
2.24.0


  reply	other threads:[~2019-12-22 16:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-14 11:49 Cross-compilation broken on canonical packages Mathieu Othacehe
2019-12-14 11:52 ` Mathieu Othacehe
2019-12-19 16:48   ` Ludovic Courtès
2019-12-22 16:31     ` Mathieu Othacehe [this message]
2019-12-30 18:48       ` Ludovic Courtès
2019-12-31  9:55         ` Mathieu Othacehe
2020-01-02 18:07           ` Ludovic Courtès
2020-01-02 22:00             ` Mathieu Othacehe
2020-01-03 12:03               ` Mathieu Othacehe
2020-02-11 13:01                 ` Mathieu Othacehe
2020-02-11 14:04                   ` Ludovic Courtès
2020-02-12 10:20                     ` Mathieu Othacehe
2020-02-24 16:11                       ` Ludovic Courtès
2020-03-06  9:19                         ` Mathieu Othacehe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fthc9vav.fsf@gmail.com \
    --to=m.othacehe@gmail.com \
    --cc=guix-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.