From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mathieu Othacehe Subject: Re: Cross-compilation broken on canonical packages. Date: Sun, 22 Dec 2019 17:31:04 +0100 Message-ID: <87fthc9vav.fsf@gmail.com> References: <878snff7pv.fsf@gmail.com> <877e2zf7kv.fsf@gmail.com> <871rt0ntvy.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:48646) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ij48O-0007eN-O9 for guix-devel@gnu.org; Sun, 22 Dec 2019 11:31:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ij48N-0006ug-19 for guix-devel@gnu.org; Sun, 22 Dec 2019 11:31:12 -0500 In-reply-to: <871rt0ntvy.fsf@gnu.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello Ludo, Thanks for your explanation :) > This is expected: packages in =E2=80=98%final-inputs=E2=80=99 (those retu= rned by > =E2=80=98canonical-package=E2=80=99) are rooted in the bootstrap graph an= d 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-wip-Add-a-canonical-package-gexp-compiler.patch >From 6266c46181d2880684c89999519423be8d8a8ea3 Mon Sep 17 00:00:00 2001 From: Mathieu Othacehe 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 + (%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 ) 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 --=-=-=--