diff mbox

gnu: cross-libc: Cross build the correct libc for GNU/Hurd systems.

Message ID 6bf591cf-2ea4-01fc-bd13-23ae60864714@gmail.com
State New
Headers show

Commit Message

Manolis Ragkousis June 16, 2016, 4:32 p.m. UTC
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

Comments

Manolis Ragkousis June 16, 2016, 6:44 p.m. UTC | #1
Hello again,

On 06/16/16 19:32, Manolis Ragkousis wrote:
>> 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.
> 

Cross building gcc 6.1.0 for mips fails with or without my patch on the
latest core-updates.

Other packages build without an issue.

Manolis
Ludovic Courtès June 26, 2016, 9:31 p.m. UTC | #2
Hi!

Manolis Ragkousis <manolis837@gmail.com> skribis:

> 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.

The (guix build …) name space is meant for “build-side” code (info
"(guix) G-Expressions"), whereas this is clearly “host” code since it
manipulates packages.  So I think it should remain in (gnu packages
cross-base), only moved to the top-level instead of inner definitions.

Sorry if I wasn’t clear!

>> 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

Bah, I was wrong: it’s expected that derivations are not the same since
there are changes like adding KERNEL/lib to CROSS_LIBRARY_PATH.
Apologies for the confusion.

> so I will have to build it and see if it works. I will report back on
> that.

GCC 6 currently fails to cross build.  For a known-good compiler, try
4.9, which currently cross-builds successfully (on master):

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix build gcc@4 --target=mips64el-linux-gnu -n --no-grafts
guix build: warning: ambiguous package specification `gcc@4'
guix build: warning: choosing gcc-4.9.3 from gnu/packages/gcc.scm:334:2
La jenaj derivoj estus elŝutataj:
   /gnu/store/v2rglm6dp21c33lhbcvdzqfsxlxya9qp-gcc-4.9.3-debug
   /gnu/store/aarlmyjnd5hrd3gvi6qwmlsajvvvfnxw-gcc-4.9.3-lib
   /gnu/store/56cl18prjn8rhvjp1y7agwn5gis27h87-gcc-4.9.3
   /gnu/store/1j8pbr9xlzkjx93xvv12z2zflnbw86bg-gmp-6.1.0
   /gnu/store/3m8pj7dc10a9m6ds6gwn198a3d7zjr2a-zlib-1.2.8
   /gnu/store/5cr66jcq6m4qm5nqah6lplby8vli6h2b-isl-0.11.1
   /gnu/store/6kkhcyj1i1bg83h8zx7mrvkp1bfnh8l9-gcc-cross-mips64el-linux-gnu-4.9.3
   /gnu/store/9szbxfc2pizaznklqmas7r8qghqidci6-mpc-1.0.3
   /gnu/store/ac5yx4spq4i78085yy9sxhzr9zrsvhic-glibc-cross-mips64el-linux-gnu-2.22
   /gnu/store/mfn9wr2yl3yq02b87zf1b9vg6n7g9bfw-mpfr-3.1.3
   /gnu/store/n2pc3fzq1fwpbmb83g7kmsj80fa1nld9-cloog-0.18.0
   /gnu/store/7y12yppfwy0ll99faazp2qsank4nmd3j-gcc-cross-sans-libc-mips64el-linux-gnu-4.9.3
$ git describe
v0.10.0-1526-g9dd674d
--8<---------------cut here---------------end--------------->8---

Could you send an updated patch?

Sorry for the delay and all again!

Ludo’.
diff mbox

Patch

From f8aedd6fdb1b3f9a93c1786c29f7fc7e40eea7a1 Mon Sep 17 00:00:00 2001
From: Manolis Ragkousis <manolis837@gmail.com>
Date: Thu, 16 Jun 2016 16:13:22 +0300
Subject: [PATCH] gnu: cross-libc: Cross build the correct libc for GNU/Hurd
 systems.

* guix/build/cross-base.scm: New file.  Add cross-mig, cross-kernel-headers
  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 correct 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 =					\
   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 © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2016 Manolis Fragkiskos Ragkousis <manolis837@gmail.com>
 ;;;
 ;;; 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 not have
+             ;; the usual cross-compilation inputs since that would include
+             ;; 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=" target)
+                 ,flags))
          ((#:phases phases)
-          `(alist-replace
-            'build
-            (lambda _
-              (setenv "ARCH" ,(system->linux-architecture target))
-              (format #t "`ARCH' set to `~a' (cross compiling)~%" (getenv "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 libihash
+                #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 include
-           ;; itself.
-           #:implicit-cross-inputs? #f
 
-           ;; 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 expects the
+      ;; "kernel-headers" input to point to the right thing.
+      (propagated-inputs `(("kernel-headers" ,(cross-kernel-headers target xgcc xbinutils))))
 
-           ,@(package-arguments glibc))
-       ((#:configure-flags flags)
-        `(cons ,(string-append "--host=" 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 input, but
-    ;; to do that will require building an intermediate cross libc.
-    (inputs '())
+      ;; FIXME: 'static-bash' should really be an input, not a native input, but
+      ;; to do that will require building an intermediate cross libc.
+      (inputs '())
 
-    (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 xbinutils)))
+                             '())
+                       ,@(package-inputs libc)     ;FIXME: static-bash
+                       ,@(package-native-inputs libc))))))
 
 
 ;;;
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 © 2016 Manolis Fragkiskos Ragkousis <manolis837@gmail.com>
+;;;
+;;; 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 (at
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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=" 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)~%" (getenv "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)))
-- 
2.8.3