Paste number 324577: WIP rust scratchpad

Index of paste annotations: 1 | 2

Paste number 324577: WIP rust scratchpad
Pasted by: jlicht
When:3 years, 9 months ago
Share:Tweet this! |
Paste contents:
Raw Source | XML | Display As
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 Nils Gillmann <>
;;; 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
;;; 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 (gnu packages rust)
  #:use-module (ice-9 regex)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix utils)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system trivial)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages)
  #:use-module (gnu packages base)
  #:use-module (gnu packages bootstrap)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages elf)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages libffi)
  #:use-module (gnu packages valgrind)
  #:use-module (gnu packages version-control)
  #:use-module (gnu packages curl)
  #:use-module (gnu packages python)
  #:use-module (gnu packages llvm)
  #:use-module (gnu packages jemalloc))

;; For a true bootstrap:
;; (But that would take about 319 iterative bootstrapped compiler builds)
;; It could eventually work once the rust team has a more structured approach for bootstrapping

;; XXX: 
;; patch-shebang: ./src/llvm/utils/llvm-compilers-check: warning: no binary for interpreter `python3' found in $PATH
;; patch-shebang: ./src/llvm/utils/makellvm: warning: no binary for interpreter `csh' found in $PATH
;; x86_64-unknown-linux-gnu/stage0/bin/rustc:
;; /gnu/store/b1yqjimbdh5bf9jnizd4h7yf110744j2-bash-4.3.42/bin/bash: x86_64-unknown-linux-gnu/stage0/bin/rustc: No such file or directory
;; /gnu/store/b...-bash-4.3.42/bin/bash: some/dir/rustc: No such file or directory

;; (string-append
;; ""
;; version ".tar.gz")
;;gh "1m2d1dc243s7ym8fq2yag3fr5jvki0q9c39llfwgcpq1gc8jvcn8"))))

;; -> take/recreate patch from

;; PAtch rust-disable-codegen-tests.patch

(define (archive-name version platform checksum)
  (string-append "rust-stage0-" version "-" platform "-" checksum ".tar.bz2"))

(define rust-stage0-bootstrap-x86_64-archive
  (archive-name "2016-02-17-4d3eebf" "linux-x86_64" "d29b7607d13d64078b6324aec82926fb493f59ba"))

(define rust-stage0-bootstrap-x86_64
    (method url-fetch)
     (string-append "" rust-stage0-bootstrap-x86_64-archive))

(define rust-stage0-bootstrap-i386-archive
  (archive-name "2016-02-17-4d3eebf" "linux-i386" "5f194aa7628c0703f0fd48adc4ec7f3cc64b98c7"))

(define rust-stage0-bootstrap-i386
    (method url-fetch)
     (string-append "" rust-stage0-bootstrap-i386-archive))

(define-public rust-stage0
    (name "rust-stage0")
    (version "2016-02-17-4d3eebf")
    (build-system trivial-build-system)
     `(#:modules ((guix build utils))
       (let ((out (assoc-ref %outputs "out"))
             (tar (string-append (assoc-ref %build-inputs "tar") "/bin/tar"))
             (bzip2 (string-append (assoc-ref %build-inputs "bzip2") "/bin/bzip2"))
             (patchelf (string-append (assoc-ref %build-inputs "patchelf") "/bin/patchelf"))
             (tarball (assoc-ref %build-inputs "rust-bootstrap"))
             (ld-so (string-append (assoc-ref %build-inputs "libc")
             (libc-libs (string-append (assoc-ref %build-inputs "libc") "/lib/"))
             (gcc:lib (assoc-ref %build-inputs "gcc:lib")))
         (use-modules (guix build utils))
         (mkdir out)
         (copy-file tarball "bootstrap.tar.bz2")
         (display "yolo")

         ;;--interpreter "${stdenv.glibc.out}/lib/${}" \
         ;;--set-rpath "${}/lib/:${}/lib64/" 
         (let ((builddir (getcwd)))
           (with-directory-excursion out
             (and (zero? (system* bzip2 "-d"
                                  (string-append builddir "/bootstrap.tar.bz2")))
                  (zero? (system* tar "xvf"
                                  (string-append builddir "/bootstrap.tar")))
                  ;(display (string-append "--set-interpreter" ld-so "rust-stage0/bin/rustc"))
                  ;(display (string-append "--set-rpath" (string-append gcc:lib "/lib/" ":" gcc:lib "/lib64/") "rust-stage0/bin/rustc"))
                  (zero? (system* patchelf "--set-interpreter" ld-so "rust-stage0/bin/rustc"))
                  (zero? (system* patchelf "--set-rpath" (string-append gcc:lib "/lib/" ":" libc-libs) "rust-stage0/bin/rustc")))
              (copy-recursively "rust-stage0" "." )
              (delete-file-recursively "rust-stage0"))))))
     `(("tar" ,tar)
       ("bzip2" ,bzip2)
       ;("libc" ,glibc)
       ("gcc:lib" ,gcc "lib")
        ,(if (string-match "x86_64" (or (%current-target-system) (%current-system)))
       ("patchelf" ,patchelf))
    (source #f)
    (synopsis "todo")
    (description "todo")
    (license license:gpl3+)
    (home-page "none")
    ));; XXX: rewrite/fix. Maybe inherit?

;; ;p ++ [ "--default-linker=${}/bin/cc" "--default-ar=${binutils.out}/bin/ar

(define-public rust
    (name "rust")
    (version "1.8.0")
    (source (origin
              (method url-fetch)
              (uri "")
              (file-name (string-append name "-" version ".tar.gz"))
               (search-patches "rust-disable-codegen-tests.patch"
    (build-system gnu-build-system)
    ;; XXX: rust should probably run on everything
    (supported-systems '("i686-linux" "x86_64-linux"))
     `(;#:make-flags (list "CC=gcc") ;; XXX: stil not enough
       #:parallel-build? #f
       ;; XXX: commit a3fdde7
       ;;#:configure-flags "--disable-codegen-tests"
       ;; (setenv "PATH" (string-append (getenv "PATH") ":" out "/bin")))) <- awesome path setting
       ;; #!$SHELL
       ;; exec gcc "$@"
        'configure 'patch-sources
        (lambda* (#:key outputs #:allow-other-keys)
          ;; XXX Cannot use snippet because zip files are not supported
          (substitute* "mk/cfg/" ; <- check this
            (("^CC_x86_64-unknown-linux-gnu=.*(CC)$") "CC_x86_64-unknown-linux-gnu=gcc"))
          (substitute* "mk/cfg/" ; <- check this
            (("^CC_i686-unknown-linux-gnu=.*(CC)$") "CC_i686-unknown-linux-gnu=gcc"))
          (substitute* "src/librustc_back/target/" ; <- check this
            (("^.*linker: option_env!(\"CFG_DEFAULT_LINKER\").unwrap_or(\"cc\").to_string(),$")
             "            linker: option_env!(\"CFG_DEFAULT_LINKER\").unwrap_or(\"gcc\").to_string(),"))
          (let ((wrapper-dir (string-append (getcwd) "/" "cc-wrapper")))
            (mkdir wrapper-dir)
            (with-output-to-file (string-append wrapper-dir "/cc")
              (lambda ()
                  "#!" (which "bash") "\n"
                  "exec gcc \"$@\""))))
            (chmod (string-append wrapper-dir "/cc") #o755)
            (setenv "PATH"
                    (string-append (getenv "PATH")
                                   ":" wrapper-dir))))
        (modify-phases (alist-replace
                        (lambda* (#:key inputs outputs #:allow-other-keys)
                          ;; This old `configure' script doesn't support
                          ;; variables passed as arguments.
                          (let ((out (assoc-ref outputs "out"))
                                (llvm (assoc-ref inputs "llvm"))
                                (ar (string-append (assoc-ref inputs "binutils") "/bin/ar"))
                                (jemalloc (assoc-ref inputs "jemalloc"))
                                (mygcc (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
                                (rust-stage0 (assoc-ref inputs "rust-stage0")))
                            (setenv "CONFIG_SHELL" (which "bash"))
                            ;;(setenv "RUST_LOG" "info")
                            (setenv "CC" mygcc)
                                        ;(setenv "CC" (string-append (assoc-ref %build-inputs "gcc") "/bin/gcc"))
                             (system* "./configure"
                                      (string-append "--default-ar=" ar)
                                      (string-append "--default-linker=" mygcc) ;; XXX; why oh why rust do you not heed this argument XD
                                      (string-append "--prefix=" out)
                                      (string-append "--llvm-root=" llvm)
                                      (string-append "--jemalloc-root=" jemalloc "/lib")
                                      (string-append "--local-rust-root=" rust-stage0)))))
     `(("python-2" ,python-2)
       ("curl" ,curl)
       ("git" ,git)
       ("valgrind" ,valgrind)
       ("libffi" ,libffi)
       ("perl" ,perl)
       ("llvm" ,llvm)
       ("jemalloc" ,jemalloc)))
     `(("patchelf" ,patchelf)
       ("gcc" ,gcc)
       ("procps" ,procps) ; for tests, we need ps
       ;("ar" ,ar)
       ("which" ,which)
       ("rust-stage0" ,rust-stage0)))
    (home-page "")
     "The Rust Programming Language")
    (license license:gpl3+)))

Annotations for this paste:

Annotation number 1: codegen patch
Pasted by: jlicht
When:3 years, 9 months ago
Share:Tweet this! |
Paste contents:
Raw Source | Display As
From a3fdde7453d82870868a1bf8db448afcf966fb34 Mon Sep 17 00:00:00 2001
From: Alex Crichton <>
Date: Wed, 9 Mar 2016 19:11:02 -0800
Subject: [PATCH] mk: Add configure option for disabling codegen tests

Our `codegen` test suite requires the LLVM `FileCheck` utility but unfortunately
this isn't always available in all custom LLVM roots (e.g. those specified via
`--llvm-root`). This commit adds a `./configure` option called
`--disable-codegen-tests` which will manually disable running these tests. In
the case that this option is passed we can forgo the need for the `FileCheck`
executable. Note that we still require `FileCheck` by default as we will attempt
to run these tests.

Closes #28667
 configure   | 5 ++++-
 mk/ | 8 ++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 2a18bee..da5468a 100755
--- a/configure
+++ b/configure
@@ -608,6 +608,7 @@ opt dist-host-only 0 "only install bins for the host architecture"
 opt inject-std-version 1 "inject the current compiler version of libstd into pro
 opt llvm-version-check 1 "check if the LLVM version is supported, build anyway"
 opt rustbuild 0 "use the rust and cargo based build system"
+opt codegen-tests 1 "run the src/test/codegen tests"
 # Optimization and debugging options. These may be overridden by the release channel, etc.
 opt_nosave optimize 1 "build optimized rust code"
@@ -1497,7 +1498,9 @@ do
         # Check that LLVm FileCheck is available. Needed for the tests
-        need_cmd $LLVM_INST_DIR/bin/FileCheck
+        if [ -z "$CFG_DISABLE_CODEGEN_TESTS" ]; then
+            need_cmd $LLVM_INST_DIR/bin/FileCheck
+        fi
     if [ ${do_reconfigure} -ne 0 ]
diff --git a/mk/ b/mk/
index 50c060c..1a02b5c 100644
--- a/mk/
+++ b/mk/
@@ -305,11 +305,15 @@ check-stage$(1)-T-$(2)-H-$(3)-exec: \
 	check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec \
 	check-stage$(1)-T-$(2)-H-$(3)-debuginfo-gdb-exec \
 	check-stage$(1)-T-$(2)-H-$(3)-debuginfo-lldb-exec \
-	check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
-	check-stage$(1)-T-$(2)-H-$(3)-codegen-units-exec \
 	check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
+check-stage$(1)-T-$(2)-H-$(3)-exec: \
+	check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
+	check-stage$(1)-T-$(2)-H-$(3)-codegen-units-exec
 # Only test the compiler-dependent crates when the target is
 # able to build a compiler (when the target triple is in the set of host triples)
 ifneq ($$(findstring $(2),$$(CFG_HOST)),)

Annotation number 2: env-workaround patch
Pasted by: jlicht
When:3 years, 9 months ago
Share:Tweet this! |
Paste contents:
Raw Source | Display As
C--- ../../nix-build-rust-1.8.0.drv-11/rust-1.8.0/configure	1970-01-01 01:00:00.000000000 +0100
+++ ./configure	2016-04-30 22:48:35.887392561 +0200
@@ -536,10 +536,14 @@
             warn "Cannot check if the userland is i686 or x86_64"
+            warn "Assuming 64 bit userland on 64 bit linux system"
+            CFG_CPUTYPE=x86_64
+            SKIP_PROBE_CHECK=1
     file -L "$BIN_TO_PROBE" | grep -q "x86[_-]64"
-    if [ $? != 0 ]; then
+    if [ $? != 0 ] && [ $SKIP_PROBE_CHECK != 1 ]; then
         msg "i686 userland on x86_64 Linux kernel"

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.