From mboxrd@z Thu Jan 1 00:00:00 1970 From: Manolis Ragkousis Subject: Re: [PATCH] gnu: cross-libc: Cross build the correct libc for GNU/Hurd systems. Date: Thu, 16 Jun 2016 19:32:01 +0300 Message-ID: <6bf591cf-2ea4-01fc-bd13-23ae60864714@gmail.com> References: <530b45d9-81f7-2415-c9ef-6c50a76a2e99@gmail.com> <87vb1el5w2.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------5D75DAAD979AFAC02A75CD97" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59182) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDaDD-00021a-FC for guix-devel@gnu.org; Thu, 16 Jun 2016 12:32:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDaD9-0004xW-1j for guix-devel@gnu.org; Thu, 16 Jun 2016 12:32:11 -0400 In-Reply-To: <87vb1el5w2.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: =?UTF-8?Q?Ludovic_Court=c3=a8s?= Cc: guix-devel@gnu.org This is a multi-part message in MIME format. --------------5D75DAAD979AFAC02A75CD97 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hello, Here is the updated patch. On 06/12/16 19:38, Ludovic Courtès wrote: > Could you move this procedure, as well as xgnumach-headers and co., to > the top level? That way there’d be less “clutter” in the definition of > ‘cross-libc’ itself. WDYT? I created (guix build cross-base) which exports cross-mig, cross-kernel-headers and cross-libc-for-target, which is what we need to produce a working cross-libc. Cross-mig is only used when target is GNU/Hurd. > > Other than that it LGTM, but if, and only if, you can verify that this > does not cause any regression for other cross-compilation targets. > Normally this should not change derivations at all so you don’t even > need to build them. Just run this: > > ./pre-inst-env guix build gcc --target=mips64el-linux-gnu -d > > both before and after the change, and the result should be the same .drv > file name. The derivations are not the same so I will have to build it and see if it works. I will report back on that. Thank you, Manolis --------------5D75DAAD979AFAC02A75CD97 Content-Type: text/x-patch; name="0001-gnu-cross-libc-Cross-build-the-correct-libc-for-GNU-.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-gnu-cross-libc-Cross-build-the-correct-libc-for-GNU-.pa"; filename*1="tch" =46rom f8aedd6fdb1b3f9a93c1786c29f7fc7e40eea7a1 Mon Sep 17 00:00:00 2001 From: Manolis Ragkousis Date: Thu, 16 Jun 2016 16:13:22 +0300 Subject: [PATCH] gnu: cross-libc: Cross build the correct libc for GNU/Hu= rd systems. * guix/build/cross-base.scm: New file. Add cross-mig, cross-kernel-heade= rs and cross-libc-for-target. * gnu/packages/cross-base.scm (cross-libc): Use the new file. Use cross-libc-for-target. [arguments]: Add 'KERNEL/lib' to 'CROSS_LIBRARY_PATH'. [propagated-inputs]: Use "cross-kernel-headers" to determine the correc= t headers. [native-inputs]: Use "cross-mig" when target is GNU/Hurd. * Makefile.am (MODULES): Add it. --- Makefile.am | 1 + gnu/packages/cross-base.scm | 111 +++++++++++------------- guix/build/cross-base.scm | 205 ++++++++++++++++++++++++++++++++++++++= ++++++ 3 files changed, 255 insertions(+), 62 deletions(-) create mode 100644 guix/build/cross-base.scm diff --git a/Makefile.am b/Makefile.am index 50cde52..44838d3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -103,6 +103,7 @@ MODULES =3D \ guix/build/emacs-utils.scm \ guix/build/graft.scm \ guix/build/bournish.scm \ + guix/build/cross-base.scm \ guix/search-paths.scm \ guix/packages.scm \ guix/import/utils.scm \ diff --git a/gnu/packages/cross-base.scm b/gnu/packages/cross-base.scm index 718e56e..be7870a 100644 --- a/gnu/packages/cross-base.scm +++ b/gnu/packages/cross-base.scm @@ -2,6 +2,7 @@ ;;; Copyright =C2=A9 2013, 2014, 2015, 2016 Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2014, 2015 Mark H Weaver ;;; Copyright =C2=A9 2016 Jan Nieuwenhuizen +;;; Copyright =C2=A9 2016 Manolis Fragkiskos Ragkousis ;;; ;;; This file is part of GNU Guix. ;;; @@ -30,9 +31,11 @@ #:use-module (guix utils) #:use-module (guix build-system gnu) #:use-module (guix build-system trivial) + #:use-module (guix build cross-base) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (ice-9 match) + #:use-module (ice-9 regex) #:export (cross-binutils cross-libc cross-gcc)) @@ -290,75 +293,59 @@ GCC that does not target a libc; otherwise, target = that libc." (xbinutils (cross-binutils target))) "Return a libc cross-built for TARGET, a GNU triplet. Use XGCC and XBINUTILS and the cross tool chain." - (define xlinux-headers - (package (inherit linux-libre-headers) - (name (string-append (package-name linux-libre-headers) - "-cross-" target)) + (let ((libc (cross-libc-for-target target))) + (package (inherit libc) + (name (string-append "glibc-cross-" target)) (arguments (substitute-keyword-arguments - `(#:implicit-cross-inputs? #f - ,@(package-arguments linux-libre-headers)) + `(;; Disable stripping (see above.) + #:strip-binaries? #f + + ;; This package is used as a target input, but it should no= t have + ;; the usual cross-compilation inputs since that would incl= ude + ;; itself. + #:implicit-cross-inputs? #f + + ;; We need SRFI 26. + #:modules ((guix build gnu-build-system) + (guix build utils) + (srfi srfi-26)) + + ,@(package-arguments libc)) + ((#:configure-flags flags) + `(cons ,(string-append "--host=3D" target) + ,flags)) ((#:phases phases) - `(alist-replace - 'build - (lambda _ - (setenv "ARCH" ,(system->linux-architecture target)) - (format #t "`ARCH' set to `~a' (cross compiling)~%" (geten= v "ARCH")) - - (and (zero? (system* "make" "defconfig")) - (zero? (system* "make" "mrproper" "headers_check"))))= + `(alist-cons-before + 'configure 'set-cross-kernel-headers-path + (lambda* (#:key inputs #:allow-other-keys) + (let* ((kernel (assoc-ref inputs "kernel-headers")) + (cpath (string-append kernel "/include"))) + (for-each (cut setenv <> cpath) + '("CROSS_C_INCLUDE_PATH" + "CROSS_CPLUS_INCLUDE_PATH" + "CROSS_OBJC_INCLUDE_PATH" + "CROSS_OBJCPLUS_INCLUDE_PATH")) + (setenv "CROSS_LIBRARY_PATH" + (string-append kernel "/lib")) ;for Hurd's libih= ash + #t)) ,phases)))) - (native-inputs `(("cross-gcc" ,xgcc) - ("cross-binutils" ,xbinutils) - ,@(package-native-inputs linux-libre-headers)))))= - - (package (inherit glibc) - (name (string-append "glibc-cross-" target)) - (arguments - (substitute-keyword-arguments - `(;; Disable stripping (see above.) - #:strip-binaries? #f - - ;; This package is used as a target input, but it should not = have - ;; the usual cross-compilation inputs since that would includ= e - ;; itself. - #:implicit-cross-inputs? #f =20 - ;; We need SRFI 26. - #:modules ((guix build gnu-build-system) - (guix build utils) - (srfi srfi-26)) + ;; Shadow the native "kernel-headers" because glibc's recipe expec= ts the + ;; "kernel-headers" input to point to the right thing. + (propagated-inputs `(("kernel-headers" ,(cross-kernel-headers targ= et xgcc xbinutils)))) =20 - ,@(package-arguments glibc)) - ((#:configure-flags flags) - `(cons ,(string-append "--host=3D" target) - ,flags)) - ((#:phases phases) - `(alist-cons-before - 'configure 'set-cross-kernel-headers-path - (lambda* (#:key inputs #:allow-other-keys) - (let* ((kernel (assoc-ref inputs "kernel-headers")) - (cpath (string-append kernel "/include"))) - (for-each (cut setenv <> cpath) - '("CROSS_C_INCLUDE_PATH" - "CROSS_CPLUS_INCLUDE_PATH" - "CROSS_OBJC_INCLUDE_PATH" - "CROSS_OBJCPLUS_INCLUDE_PATH")) - #t)) - ,phases)))) - - ;; Shadow the native "kernel-headers" because glibc's recipe expects= the - ;; "kernel-headers" input to point to the right thing. - (propagated-inputs `(("kernel-headers" ,xlinux-headers))) - - ;; FIXME: 'static-bash' should really be an input, not a native inpu= t, but - ;; to do that will require building an intermediate cross libc. - (inputs '()) + ;; FIXME: 'static-bash' should really be an input, not a native in= put, but + ;; to do that will require building an intermediate cross libc. + (inputs '()) =20 - (native-inputs `(("cross-gcc" ,xgcc) - ("cross-binutils" ,xbinutils) - ,@(package-inputs glibc) ;FIXME: static-bash - ,@(package-native-inputs glibc))))) + (native-inputs `(("cross-gcc" ,xgcc) + ("cross-binutils" ,xbinutils) + ,@(if (string-match "i586-pc-gnu" target) + `(("cross-mig" ,(cross-mig target xgcc xbin= utils))) + '()) + ,@(package-inputs libc) ;FIXME: static-bash + ,@(package-native-inputs libc)))))) =20 =0C ;;; diff --git a/guix/build/cross-base.scm b/guix/build/cross-base.scm new file mode 100644 index 0000000..501a221 --- /dev/null +++ b/guix/build/cross-base.scm @@ -0,0 +1,205 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2016 Manolis Fragkiskos Ragkousis +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (a= t +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix build cross-base) + #:use-module (guix licenses) + #:use-module (gnu packages) + #:use-module (guix packages) + #:use-module (guix build-system gnu) + #:use-module (guix build-system trivial) + #:use-module (guix build utils) + #:use-module (guix utils) + #:use-module (gnu packages base) + #:use-module (gnu packages linux) + #:use-module (gnu packages hurd) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:use-module (ice-9 match) + #:use-module (ice-9 regex) + #:export (cross-mig) + #:export (cross-kernel-headers) + #:export (cross-libc-for-target)) + +(define (cross-mig target xgcc xbinutils) + "Return MiG cross-built for TARGET." + + (define xgnumach-headers + (package (inherit gnumach-headers) + (name (string-append (package-name gnumach-headers) + "-cross-" target)) + + (native-inputs `(("cross-gcc" ,xgcc) + ("cross-binutils" ,xbinutils) + ,@(package-native-inputs gnumach-headers))))) + + (package (inherit mig) + (name (string-append "mig-cross")) + (arguments + `(#:modules ((guix build gnu-build-system) + (guix build utils) + (srfi srfi-26)) + #:phases (alist-cons-before + 'configure 'set-cross-headers-path + (lambda* (#:key inputs #:allow-other-keys) + (let* ((mach (assoc-ref inputs "cross-gnumach-headers= ")) + (cpath (string-append mach "/include"))) + (for-each (cut setenv <> cpath) + '("CROSS_C_INCLUDE_PATH" + "CROSS_CPLUS_INCLUDE_PATH" + "CROSS_OBJC_INCLUDE_PATH" + "CROSS_OBJCPLUS_INCLUDE_PATH")))) + %standard-phases) + #:configure-flags (list ,(string-append "--target=3D" target)) + ,@(package-arguments mig))) + + (propagated-inputs `(("cross-gnumach-headers" ,xgnumach-headers))) + (native-inputs `(("cross-gcc" ,xgcc) + ("cross-binutils" ,xbinutils) + ,@(package-native-inputs mig))))) + + + +(define (cross-kernel-headers target xgcc xbinutils) + "Return headers depending on TARGET." + + (define xlinux-headers + (package (inherit linux-libre-headers) + (name (string-append (package-name linux-libre-headers) + "-cross-" target)) + (arguments + (substitute-keyword-arguments + `(#:implicit-cross-inputs? #f + ,@(package-arguments linux-libre-headers)) + ((#:phases phases) + `(alist-replace + 'build + (lambda _ + (setenv "ARCH" ,(system->linux-architecture target)) + (format #t "`ARCH' set to `~a' (cross compiling)~%" (geten= v "ARCH")) + (and (zero? (system* "make" "defconfig")) + (zero? (system* "make" "mrproper" "headers_check"))))= + ,phases)))) + (native-inputs `(("cross-gcc" ,xgcc) + ("cross-binutils" ,xbinutils) + ,@(package-native-inputs linux-libre-headers)))))= + + (define xgnumach-headers + (package (inherit gnumach-headers) + (name (string-append (package-name gnumach-headers) + "-cross-" target)) + + (native-inputs `(("cross-gcc" ,xgcc) + ("cross-binutils" ,xbinutils) + ,@(package-native-inputs gnumach-headers))))) + + (define xhurd-headers + (package (inherit hurd-headers) + (name (string-append (package-name hurd-headers) + "-cross-" target)) + + (native-inputs `(("cross-gcc" ,xgcc) + ("cross-binutils" ,xbinutils) + ("cross-mig" ,(cross-mig target xgcc xbinutils)) + ,@(alist-delete "mig"(package-native-inputs hurd-= headers)))))) + + (define xglibc/hurd-headers + (package (inherit glibc/hurd-headers) + (name (string-append (package-name glibc/hurd-headers) + "-cross-" target)) + + (arguments + (substitute-keyword-arguments + `(#:modules ((guix build gnu-build-system) + (guix build utils) + (srfi srfi-26)) + ,@(package-arguments glibc/hurd-headers)) + ((#:phases phases) + `(alist-cons-before + 'pre-configure 'set-cross-headers-path + (lambda* (#:key inputs #:allow-other-keys) + (let* ((mach (assoc-ref inputs "gnumach-headers")) + (hurd (assoc-ref inputs "hurd-headers")) + (cpath (string-append mach "/include:" + hurd "/include"))) + (for-each (cut setenv <> cpath) + '("CROSS_C_INCLUDE_PATH" + "CROSS_CPLUS_INCLUDE_PATH" + "CROSS_OBJC_INCLUDE_PATH" + "CROSS_OBJCPLUS_INCLUDE_PATH")))) + ,phases)))) + + (propagated-inputs `(("gnumach-headers" ,xgnumach-headers) + ("hurd-headers" ,xhurd-headers))) + + (native-inputs `(("cross-gcc" ,xgcc) + ("cross-binutils" ,xbinutils) + ("cross-mig" ,(cross-mig target xgcc xbinutils)) + ,@(alist-delete "mig"(package-native-inputs glibc= /hurd-headers)))))) + + (define xhurd-minimal + (package (inherit hurd-minimal) + (name (string-append (package-name hurd-minimal) + "-cross-" target)) + (arguments + (substitute-keyword-arguments + `(#:modules ((guix build gnu-build-system) + (guix build utils) + (srfi srfi-26)) + ,@(package-arguments hurd-minimal)) + ((#:phases phases) + `(alist-cons-before + 'configure 'set-cross-headers-path + (lambda* (#:key inputs #:allow-other-keys) + (let* ((glibc-headers (assoc-ref inputs "cross-glibc-hurd-= headers")) + (cpath (string-append glibc-headers "/include"))) + (for-each (cut setenv <> cpath) + '("CROSS_C_INCLUDE_PATH" + "CROSS_CPLUS_INCLUDE_PATH" + "CROSS_OBJC_INCLUDE_PATH" + "CROSS_OBJCPLUS_INCLUDE_PATH")))) + ,phases)))) + + (inputs `(("cross-glibc-hurd-headers" ,xglibc/hurd-headers))) + + (native-inputs `(("cross-gcc" ,xgcc) + ("cross-binutils" ,xbinutils) + ("cross-mig" ,(cross-mig target xgcc xbinutils)) + ,@(alist-delete "mig"(package-native-inputs hurd-= minimal)))))) + + (define xhurd-core-headers + (package (inherit hurd-core-headers) + (name (string-append (package-name hurd-core-headers) + "-cross-" target)) + + (inputs `(("gnumach-headers" ,xgnumach-headers) + ("hurd-headers" ,xhurd-headers) + ("hurd-minimal" ,xhurd-minimal))) + + (native-inputs `(("cross-gcc" ,xgcc) + ("cross-binutils" ,xbinutils) + ,@(package-native-inputs hurd-core-headers))))) + + (match target + ((or "i586-pc-gnu" "i586-gnu") xhurd-core-headers) + (_ xlinux-headers))) + +(define (cross-libc-for-target target) + "Return libc depending on TARGET." + (match target + ((or "i586-pc-gnu" "i586-gnu") glibc/hurd) + (_ glibc/linux))) --=20 2.8.3 --------------5D75DAAD979AFAC02A75CD97--