diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm index 70140579b..ceb3510fc 100644 --- a/gnu/packages/rust.scm +++ b/gnu/packages/rust.scm @@ -46,6 +46,7 @@ #:use-module (guix build-system gnu) #:use-module (guix build-system trivial) #:use-module (guix download) + #:use-module (guix git-download) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix packages) #:use-module ((guix build utils) #:select (alist-replace)) @@ -148,7 +149,87 @@ in turn be used to build the final Rust.") "rustc-" version "-src.tar.gz")) (sha256 (base32 hash)) (modules '((guix build utils))) - (snippet '(begin (delete-file-recursively "src/llvm") #t)))) + ; FIXME (snippet '(begin (delete-file-recursively "src/llvm") #t)) + )) + +(define-public mrustc + (let ((commit "e49cd3b71a5b5458ecd3f3937c04d1a35871a190") + (revision "0") + (rustc-version "1.19.0")) + (package + (name "mrustc") + (version (git-version "0.0.0" revision commit)) + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/thepowersgang/mrustc.git") + (commit commit))) + (file-name (git-file-name name version)) + (sha256 + (base32 + "02r012cqj0h92rz90n2limbp58102kyak54lgi7a0pnd6pmgygzp")))) + (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 'unpack-target + (lambda* (#:key inputs outputs #:allow-other-keys) + (substitute* "minicargo.mk" ; source + (("^[$][(]LLVM_CONFIG[)]:") "xxx:")) + (invoke "tar" "xf" (assoc-ref inputs "rustc")) + (chdir "rustc-1.19.0-src") + (delete-file-recursively "src/llvm") + (setenv "LLVM_LINK_SHARED" "1") ; FIXME move? + (invoke "patch" "-p0" "../rust_src.patch") + (chdir "..") + #t)) + (delete 'configure) + (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")) + ;; 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 (string-append (assoc-ref outputs "out"))) + (bin (string-append out "/bin")) + (tools-bin (string-append out "/tools/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 "tools/bin/minicargo" tools-bin) + (install-file "bin/mrustc" bin) + ;; Rust requires a C toolchain for linking, as "cc". + (symlink (string-append gcc "/bin/gcc") + (string-append out "/bin/cc")) + #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") +;;; TODO: Add env vars: CFG_COMPILER_HOST_TRIPLE=x86_64-unknown-linux-gnu LLVM_CONFIG CFG_RELEASE= CFG_RELEASE_CHANNEL=stable CFG_VERSION=$(RUSTC_VERSION=1.19.0)-$(RUSTC_CHANNEL)-mrustc CFG_PREFIX=mrustc CFG_LIBDIR_RELATIVE=lib + (license license:expat)))) (define-public rust-1.23 (package @@ -199,7 +280,9 @@ in turn be used to build the final Rust.") "#[ignore]\nfn connect_timeout_unroutable")) ;; (substitute* "src/libstd/sys/unix/process/process_common.rs" - (("fn test_process_mask") "#[ignore]\nfn test_process_mask")) + (("#\\[cfg_attr\\(target_arch = \"arm\", ignore\\)\\] + fn test_process_mask") "#[ignore] + fn test_process_mask")) ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH. ;; (delete-file-recursively "src/test/run-make/linker-output-non-utf8") @@ -318,6 +401,57 @@ safety and thread safety guarantees.") ;; Dual licensed. (license (list license:asl2.0 license:expat)))) +(define-public rust-1.19.0 + (package (inherit rust-1.23) + (name "rust") + (version "1.19.0") + (source (rust-source version "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm")) + (arguments + (substitute-keyword-arguments + (package-arguments rust-1.23) + ((#:phases phases) + `(modify-phases ,phases + (replace 'build + (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\" } +")) + + (setenv "CFG_COMPILER_HOST_TRIPLE" "x86_64-unknown-linux-gnu") + ;(setenv "LLVM_CONFIG") + (setenv "CFG_RELEASE" "") + (setenv "CFG_RELEASE_CHANNEL" "stable") + (setenv "CFG_VERSION" "1.19.0-stable-mrustc") + (setenv "CFG_PREFIX" "mrustc") + (setenv "CFG_LIBDIR_RELATIVE" "lib") + ;; Make Rust find "gcc". + ;(setenv "PATH" (string-append (assoc-ref inputs "gcc") "/bin:" (getenv "PATH"))) + (invoke (string-append (assoc-ref inputs "rustc-bootstrap") "/tools/bin/minicargo") + "src/rustc" "--vendor-dir" "src/vendor" ;"-j" "3" + "-L" (string-append (assoc-ref inputs "rustc-bootstrap") "/lib/mrust")) + ; "--output-dir" "b/build" -L "b" + (setenv "CFG_COMPILER_HOST_TRIPLE" #f) + ;(setenv "LLVM_CONFIG") + (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 (assoc-ref inputs "rustc-bootstrap") "/tools/bin/minicargo") + "src/tools/cargo" "--vendor-dir" "src/vendor" + "-L" (string-append (assoc-ref inputs "rustc-bootstrap") "/lib/mrust")) + #t)))))) + (native-inputs + (alist-replace "rustc-bootstrap" (list mrustc) + (package-native-inputs rust-1.23))))) + (define-public rust (let ((base-rust rust-1.23)) (package