summary refs log tree commit diff
path: root/gnu/packages/rust.scm
diff options
context:
space:
mode:
authorMarius Bakke <mbakke@fastmail.com>2018-09-03 19:20:06 +0200
committerMarius Bakke <mbakke@fastmail.com>2018-09-03 19:20:06 +0200
commit70dc8db8e7a44e0357c6b0582a710a918bd2e353 (patch)
tree083102cf532c523068f018e2b113947ca6a3db02 /gnu/packages/rust.scm
parent279ed3efee9c71116d368163f805fe9494518687 (diff)
parentc702749dfd47ea6983768cd5b8cf828898445af0 (diff)
downloadguix-70dc8db8e7a44e0357c6b0582a710a918bd2e353.tar.gz
Merge branch 'master' into core-updates
Diffstat (limited to 'gnu/packages/rust.scm')
-rw-r--r--gnu/packages/rust.scm335
1 files changed, 227 insertions, 108 deletions
diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
index 0695f8c7d2..631dcfd67c 100644
--- a/gnu/packages/rust.scm
+++ b/gnu/packages/rust.scm
@@ -167,14 +167,120 @@ in turn be used to build the final Rust.")
     (snippet '(begin (delete-file-recursively "src/llvm") #t))
     (patches (map search-patch patches))))
 
+(define* (rust-bootstrapped-package base-rust version checksum
+                                    #:key (patches '()))
+  "Bootstrap rust VERSION with source checksum CHECKSUM patched with PATCHES using BASE-RUST."
+  (package
+    (inherit base-rust)
+    (version version)
+    (source
+     (rust-source version checksum #:patches patches))
+    (native-inputs
+     (alist-replace "cargo-bootstrap" (list base-rust "cargo")
+                    (alist-replace "rustc-bootstrap" (list base-rust)
+                                   (package-native-inputs base-rust))))))
+
+(define-public mrustc
+  (let ((rustc-version "1.19.0"))
+    (package
+      (name "mrustc")
+      (version "0.8.0")
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/thepowersgang/mrustc.git")
+                      (commit (string-append "v" version))))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32
+                  "0a7v8ccyzp1sdkwni8h1698hxpfz2sxhcpx42n6l2pbm0rbjp08i"))))
+      (outputs '("out" "cargo"))
+      (build-system gnu-build-system)
+      (inputs
+       `(("llvm" ,llvm-3.9.1)))
+      (native-inputs
+       `(("bison" ,bison)
+         ("flex" ,flex)
+         ;; Required for the libstd sources.
+         ("rustc"
+          ,(rust-source "1.19.0" "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"))))
+      (arguments
+       `(#:tests? #f
+         #:make-flags (list (string-append "LLVM_CONFIG="
+                                           (assoc-ref %build-inputs "llvm")
+                                           "/bin/llvm-config"))
+         #:phases
+         (modify-phases %standard-phases
+          (add-after 'unpack 'patch-date
+            (lambda _
+              (substitute* "Makefile"
+               (("shell date") "shell date -d @1"))
+              #t))
+           (add-after 'patch-date 'unpack-target-compiler
+             (lambda* (#:key inputs outputs #:allow-other-keys)
+               (substitute* "minicargo.mk"
+                 ;; Don't try to build LLVM.
+                 (("^[$][(]LLVM_CONFIG[)]:") "xxx:")
+                 ;; Build for the correct target architecture.
+                 (("^RUSTC_TARGET := x86_64-unknown-linux-gnu")
+                  (string-append "RUSTC_TARGET := "
+                                 ,(or (%current-target-system)
+                                      (nix-system->gnu-triplet-for-rust)))))
+               (invoke "tar" "xf" (assoc-ref inputs "rustc"))
+               (chdir "rustc-1.19.0-src")
+               (invoke "patch" "-p0" "../rust_src.patch")
+               (chdir "..")
+               #t))
+           (replace 'configure
+             (lambda* (#:key inputs #:allow-other-keys)
+               (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
+               #t))
+           (add-after 'build 'build-minicargo
+             (lambda _
+               (for-each (lambda (target)
+                           (invoke "make" "-f" "minicargo.mk" target))
+                         '("output/libstd.hir" "output/libpanic_unwind.hir"
+                           "output/libproc_macro.hir" "output/libtest.hir"))
+               ;; Technically the above already does it - but we want to be clear.
+               (invoke "make" "-C" "tools/minicargo")))
+           (replace 'install
+             (lambda* (#:key inputs outputs #:allow-other-keys)
+               (let* ((out (assoc-ref outputs "out"))
+                      (bin (string-append out "/bin"))
+                      (tools-bin (string-append out "/tools/bin"))
+                      (cargo-out (assoc-ref outputs "cargo"))
+                      (cargo-bin (string-append cargo-out "/bin"))
+                      (lib (string-append out "/lib"))
+                      (lib/rust (string-append lib "/mrust"))
+                      (gcc (assoc-ref inputs "gcc")))
+                 ;; These files are not reproducible.
+                 (for-each delete-file (find-files "output" "\\.txt$"))
+                 (mkdir-p lib)
+                 (copy-recursively "output" lib/rust)
+                 (mkdir-p bin)
+                 (mkdir-p tools-bin)
+                 (install-file "bin/mrustc" bin)
+                 ;; minicargo uses relative paths to resolve mrustc.
+                 (install-file "tools/bin/minicargo" tools-bin)
+                 (install-file "tools/bin/minicargo" cargo-bin)
+                 #t))))))
+      (synopsis "Compiler for the Rust progamming language")
+      (description "Rust is a systems programming language that provides memory
+safety and thread safety guarantees.")
+      (home-page "https://github.com/thepowersgang/mrustc")
+      ;; Dual licensed.
+      (license (list license:asl2.0 license:expat)))))
+
 (define rust-1.19
   (package
     (name "rust")
     (version "1.19.0")
-    (source (rust-source version "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"))
+    (source (rust-source version "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"
+            #:patches '("rust-1.19-mrustc.patch")))
     (outputs '("out" "cargo"))
     (arguments
      `(#:imported-modules ,%cargo-build-system-modules ;for `generate-checksums'
+       #:modules ((guix build utils) (ice-9 match) (guix build gnu-build-system))
        #:phases
        (modify-phases %standard-phases
          (add-after 'unpack 'set-env
@@ -187,6 +293,24 @@ in turn be used to build the final Rust.")
              ;; guix llvm-3.9.1 package installs only shared libraries
              (setenv "LLVM_LINK_SHARED" "1")
              #t))
+         (add-after 'unpack 'patch-cargo-tomls
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (substitute* "src/librustc_errors/Cargo.toml"
+               (("[[]dependencies[]]") "
+[dependencies]
+term = \"0.4.4\"
+"))
+             (substitute* "src/librustc/Cargo.toml"
+               (("[[]dependencies[]]") "
+[dependencies]
+getopts = { path = \"../libgetopts\" }
+"))
+             (substitute* "src/librustdoc/Cargo.toml"
+               (("[[]dependencies[]]") "
+[dependencies]
+test = { path = \"../libtest\" }
+"))
+             #t))
          (add-after 'unpack 'patch-tests
            (lambda* (#:key inputs #:allow-other-keys)
              (let ((bash (assoc-ref inputs "bash")))
@@ -243,12 +367,97 @@ in turn be used to build the final Rust.")
                   (generate-checksums dir ,%cargo-reference-project-file)))
               (find-files "src/vendor" ".cargo-checksum.json"))
              #t))
+         ;; This phase is overridden by newer versions.
          (replace 'configure
            (const #t))
+         ;; This phase is overridden by newer versions.
+         (replace 'build
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let ((rustc-bootstrap (assoc-ref inputs "rustc-bootstrap")))
+               (setenv "CFG_COMPILER_HOST_TRIPLE"
+                ,(nix-system->gnu-triplet (%current-system)))
+               (setenv "CFG_RELEASE" "")
+               (setenv "CFG_RELEASE_CHANNEL" "stable")
+               (setenv "CFG_LIBDIR_RELATIVE" "lib")
+               (setenv "CFG_VERSION" "1.19.0-stable-mrustc")
+               ; bad: (setenv "CFG_PREFIX" "mrustc") ; FIXME output path.
+               (mkdir-p "output")
+               (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
+                       "src/rustc" "--vendor-dir" "src/vendor"
+                       "--output-dir" "output/rustc-build"
+                       "-L" (string-append rustc-bootstrap "/lib/mrust")
+                       "-j" "1")
+               (install-file "output/rustc-build/rustc" "output") ; FIXME: Remove?
+               (setenv "CFG_COMPILER_HOST_TRIPLE" #f)
+               (setenv "CFG_RELEASE" #f)
+               (setenv "CFG_RELEASE_CHANNEL" #f)
+               (setenv "CFG_VERSION" #f)
+               (setenv "CFG_PREFIX" #f)
+               (setenv "CFG_LIBDIR_RELATIVE" #f)
+               (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
+                       "src/tools/cargo" "--vendor-dir" "src/vendor"
+                       "--output-dir" "output/cargo-build"
+                       "-L" "output/"
+                       "-L" (string-append rustc-bootstrap "/lib/mrust")
+                       "-j" "1")
+               ;; Now use the newly-built rustc to build the libraries.
+               ;; One day that could be replaced by:
+               ;; (invoke "output/cargo-build/cargo" "build"
+               ;;         "--manifest-path" "src/bootstrap/Cargo.toml"
+               ;;         "--verbose") ; "--locked" "--frozen"
+               ;; but right now, Cargo has problems with libstd's circular
+               ;; dependencies.
+               (mkdir-p "output/target-libs")
+               (for-each ((@ (ice-9 match) match-lambda)
+                          ((name . flags)
+                            (write name)
+                            (newline)
+                            (apply invoke
+                                   "output/rustc-build/rustc"
+                                   "-C" (string-append "linker="
+                                                       (getenv "CC"))
+                                   "-L" "output/target-libs"
+                                   (string-append "src/" name "/lib.rs")
+                                   "-o"
+                                   (string-append "output/target-libs/"
+                                                  (car (string-split name #\/))
+                                                  ".rlib")
+                                   flags)))
+                         '(("libcore")
+                           ("libstd_unicode")
+                           ("liballoc")
+                           ("libcollections")
+                           ("librand")
+                           ("liblibc/src" "--cfg" "stdbuild")
+                           ("libunwind" "-l" "gcc_s")
+                           ("libcompiler_builtins")
+                           ("liballoc_system")
+                           ("libpanic_unwind")
+                           ;; Uses "cc" to link.
+                           ("libstd" "-l" "dl" "-l" "rt" "-l" "pthread")
+                           ("libarena")))
+               #t)))
+         ;; This phase is overridden by newer versions.
          (replace 'check
            (const #t))
+         ;; This phase is overridden by newer versions.
          (replace 'install
-           (const #t)))))
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (target-system ,(or (%current-target-system)
+                                        (nix-system->gnu-triplet
+                                         (%current-system))))
+                    (out-libs (string-append out "/lib/rustlib/"
+                                             target-system "/lib")))
+                                        ;(setenv "CFG_PREFIX" out)
+               (mkdir-p out-libs)
+               (copy-recursively "output/target-libs" out-libs)
+               (install-file "output/rustc-build/rustc"
+                             (string-append out "/bin"))
+               (install-file "output/cargo-build/cargo"
+                             (string-append (assoc-ref outputs "cargo")
+                                            "/bin")))
+             #t)))))
     (build-system gnu-build-system)
     (native-inputs
      `(("bison" ,bison) ; For the tests
@@ -258,8 +467,8 @@ in turn be used to build the final Rust.")
        ("git" ,git)
        ("procps" ,procps) ; For the tests
        ("python-2" ,python-2)
-       ("rustc-bootstrap" ,rust-bootstrap)
-       ("cargo-bootstrap" ,rust-bootstrap "cargo")
+       ("rustc-bootstrap" ,mrustc)
+       ("cargo-bootstrap" ,mrustc "cargo")
        ("pkg-config" ,pkg-config) ; For "cargo"
        ("which" ,which)))
     (inputs
@@ -289,110 +498,6 @@ safety and thread safety guarantees.")
     ;; Dual licensed.
     (license (list license:asl2.0 license:expat))))
 
-(define* (rust-bootstrapped-package base-rust version checksum
-                                    #:key (patches '()))
-  "Bootstrap rust VERSION with source checksum CHECKSUM patched with PATCHES using BASE-RUST."
-  (package
-    (inherit base-rust)
-    (version version)
-    (source
-     (rust-source version checksum #:patches patches))
-    (native-inputs
-     (alist-replace "cargo-bootstrap" (list base-rust "cargo")
-                    (alist-replace "rustc-bootstrap" (list base-rust)
-                                   (package-native-inputs base-rust))))))
-
-(define-public mrustc
-  (let ((rustc-version "1.19.0"))
-    (package
-      (name "mrustc")
-      (version "0.8.0")
-      (source (origin
-                (method git-fetch)
-                (uri (git-reference
-                      (url "https://github.com/thepowersgang/mrustc.git")
-                      (commit (string-append "v" version))))
-                (file-name (git-file-name name version))
-                (sha256
-                 (base32
-                  "0a7v8ccyzp1sdkwni8h1698hxpfz2sxhcpx42n6l2pbm0rbjp08i"))))
-      (outputs '("out" "cargo"))
-      (build-system gnu-build-system)
-      (inputs
-       `(("llvm" ,llvm-3.9.1)))
-      (native-inputs
-       `(("bison" ,bison)
-         ("flex" ,flex)
-         ;; Required for the libstd sources.
-         ("rustc"
-          ,(rust-source "1.19.0" "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"))))
-      (arguments
-       `(#:tests? #f
-         #:make-flags (list (string-append "LLVM_CONFIG="
-                                           (assoc-ref %build-inputs "llvm")
-                                           "/bin/llvm-config"))
-         #:phases
-         (modify-phases %standard-phases
-          (add-after 'unpack 'patch-date
-            (lambda _
-              (substitute* "Makefile"
-               (("shell date") "shell date -d @1"))
-              #t))
-           (add-after 'patch-date 'unpack-target-compiler
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (substitute* "minicargo.mk"
-                 ;; Don't try to build LLVM.
-                 (("^[$][(]LLVM_CONFIG[)]:") "xxx:")
-                 ;; Build for the correct target architecture.
-                 (("^RUSTC_TARGET := x86_64-unknown-linux-gnu")
-                  (string-append "RUSTC_TARGET := "
-                                 ,(or (%current-target-system)
-                                      (nix-system->gnu-triplet-for-rust)))))
-               (invoke "tar" "xf" (assoc-ref inputs "rustc"))
-               (chdir "rustc-1.19.0-src")
-               (invoke "patch" "-p0" "../rust_src.patch")
-               (chdir "..")
-               #t))
-           (replace 'configure
-             (lambda* (#:key inputs #:allow-other-keys)
-               (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
-               #t))
-           (add-after 'build 'build-minicargo
-             (lambda _
-               (for-each (lambda (target)
-                           (invoke "make" "-f" "minicargo.mk" target))
-                         '("output/libstd.hir" "output/libpanic_unwind.hir"
-                           "output/libproc_macro.hir" "output/libtest.hir"))
-               ;; Technically the above already does it - but we want to be clear.
-               (invoke "make" "-C" "tools/minicargo")))
-           (replace 'install
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (let* ((out (assoc-ref outputs "out"))
-                      (bin (string-append out "/bin"))
-                      (tools-bin (string-append out "/tools/bin"))
-                      (cargo-out (assoc-ref outputs "cargo"))
-                      (cargo-bin (string-append cargo-out "/bin"))
-                      (lib (string-append out "/lib"))
-                      (lib/rust (string-append lib "/mrust"))
-                      (gcc (assoc-ref inputs "gcc")))
-                 ;; These files are not reproducible.
-                 (for-each delete-file (find-files "output" "\\.txt$"))
-                 (mkdir-p lib)
-                 (copy-recursively "output" lib/rust)
-                 (mkdir-p bin)
-                 (mkdir-p tools-bin)
-                 (install-file "bin/mrustc" bin)
-                 ;; minicargo uses relative paths to resolve mrustc.
-                 (install-file "tools/bin/minicargo" tools-bin)
-                 (install-file "tools/bin/minicargo" cargo-bin)
-                 #t))))))
-      (synopsis "Compiler for the Rust progamming language")
-      (description "Rust is a systems programming language that provides memory
-safety and thread safety guarantees.")
-      (home-page "https://github.com/thepowersgang/mrustc")
-      ;; Dual licensed.
-      (license (list license:asl2.0 license:expat)))))
-
 (define-public rust-1.23
   (package
     (inherit rust-1.19)
@@ -400,6 +505,18 @@ safety and thread safety guarantees.")
     (version "1.23.0")
     (source (rust-source version "14fb8vhjzsxlbi6yrn1r6fl5dlbdd1m92dn5zj5gmzfwf4w9ar3l"))
     (outputs '("out" "doc" "cargo"))
+    (native-inputs
+     `(("bison" ,bison) ; For the tests
+       ("cmake" ,cmake)
+       ("flex" ,flex) ; For the tests
+       ("gdb" ,gdb)   ; For the tests
+       ("git" ,git)
+       ("procps" ,procps) ; For the tests
+       ("python-2" ,python-2)
+       ("rustc-bootstrap" ,rust-bootstrap)
+       ("cargo-bootstrap" ,rust-bootstrap "cargo")
+       ("pkg-config" ,pkg-config) ; For "cargo"
+       ("which" ,which)))
     (arguments
      (substitute-keyword-arguments (package-arguments rust-1.19)
        ((#:phases phases)
@@ -410,6 +527,8 @@ safety and thread safety guarantees.")
                (substitute* "src/binaryen/CMakeLists.txt"
                  (("ADD_COMPILE_FLAG\\(\\\"-march=native\\\"\\)") ""))
                #t))
+           ;; TODO: Revisit this and find out whether that's needed after all.
+           (delete 'patch-cargo-tomls)
            (add-after 'patch-tests 'patch-cargo-tests
              (lambda _
                (substitute* "src/tools/cargo/tests/build.rs"