diff options
author | Danny Milosavljevic <dannym@scratchpost.org> | 2018-09-01 19:31:45 +0200 |
---|---|---|
committer | Danny Milosavljevic <dannym@scratchpost.org> | 2018-09-02 00:09:34 +0200 |
commit | 3159ef7c99c646b78b04cedb1bd3525c301ef978 (patch) | |
tree | 0834188aec24a4efcb4a76cb7cf013bac79d6ba6 /gnu/packages | |
parent | a0a273c1eec438c80cf0c716987514e551b3b8f4 (diff) |
gnu: rust: Bootstrap (only) Rust 1.19.0 by mrustc.
* gnu/packages/patches/rust-1.19-mrustc.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/rust.scm (rust-1.19)[source]: Add patch
"rust-1.19-mrustc.patch".
[arguments]<#:modules>: New field.
<#:phases>[patch-cargo-tomls]: New phase.
<#:phases>[build]: Modify.
<#:phases>[install]: Modify.
[native-inputs]: Replace rust-bootstrap by mrustc.
(rust-1.23)[native-inputs]: New field.
[arguments]<#:phases>: Delete phase "patch-cargo-tomls".
Diffstat (limited to 'gnu/packages')
-rw-r--r-- | gnu/packages/patches/rust-1.19-mrustc.patch | 28 | ||||
-rw-r--r-- | gnu/packages/rust.scm | 127 |
2 files changed, 151 insertions, 4 deletions
diff --git a/gnu/packages/patches/rust-1.19-mrustc.patch b/gnu/packages/patches/rust-1.19-mrustc.patch new file mode 100644 index 0000000000..261162172e --- /dev/null +++ b/gnu/packages/patches/rust-1.19-mrustc.patch @@ -0,0 +1,28 @@ +See https://github.com/thepowersgang/mrustc/archive/v0.8.0.tar.gz + +--- rustc-1.19.0-src-orig/src/libcore/intrinsics.rs ++++ rustc-1.19.0-src/src/libcore/intrinsics.rs +@@ -678,5 +678,9 @@ + pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize; + ++ /// Obtain the length of a slice pointer ++ #[cfg(rust_compiler="mrustc")] ++ pub fn mrustc_slice_len<T>(pointer: *const [T]) -> usize; ++ + /// Gets a static string slice containing the name of a type. + pub fn type_name<T: ?Sized>() -> &'static str; + +--- rustc-1.19.0-src-orig/src/libcore/slice/mod.rs ++++ rustc-1.19.0-src/src/libcore/slice/mod.rs +@@ -413,6 +413,8 @@ + #[inline] + fn len(&self) -> usize { +- unsafe { +- mem::transmute::<&[T], Repr<T>>(self).len +- } ++ #[cfg(not(rust_compiler="mrustc"))] ++ let rv = unsafe { mem::transmute::<&[T], Repr<T>>(self).len }; ++ #[cfg(rust_compiler="mrustc")] ++ let rv = unsafe { ::intrinsics::mrustc_slice_len(self) }; ++ rv + } diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm index 0695f8c7d2..41195c0e10 100644 --- a/gnu/packages/rust.scm +++ b/gnu/packages/rust.scm @@ -171,10 +171,12 @@ in turn be used to build the final Rust.") (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 +189,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 +263,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 +363,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 @@ -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" |