From ca4bfb0f2de7a2c9997f92574be65fcba4e86d64 Mon Sep 17 00:00:00 2001 From: Efraim Flashner Date: Sun, 10 Jul 2022 20:18:05 +0300 Subject: [PATCH] gnu: rust-bootstrap: Add support for riscv64-linux. * gnu/packages/rust.scm (%mrustc-source): Add patch. (rust-bootstrap)[native-inputs]: On riscv64-linux add gcc@9:lib. [supported-systems]: Add riscv64-linux. Adjust comment. * gnu/packages/patches/mrustc-riscv64-support.patch: New file. * gnu/local.mk (dist_patch_DATA): Register it. --- gnu/local.mk | 1 + .../patches/mrustc-riscv64-support.patch | 48 +++++++++++++++++++ gnu/packages/rust.scm | 13 +++-- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 gnu/packages/patches/mrustc-riscv64-support.patch diff --git a/gnu/local.mk b/gnu/local.mk index be6d37fc26..5a5ec334d9 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1509,6 +1509,7 @@ dist_patch_DATA = \ %D%/packages/patches/mono-mdoc-timestamping.patch \ %D%/packages/patches/mosaicatcher-unbundle-htslib.patch \ %D%/packages/patches/mrrescue-support-love-11.patch \ + %D%/packages/patches/mrustc-riscv64-support.patch \ %D%/packages/patches/mtools-mformat-uninitialized.patch \ %D%/packages/patches/mumps-build-parallelism.patch \ %D%/packages/patches/mumps-shared-libseq.patch \ diff --git a/gnu/packages/patches/mrustc-riscv64-support.patch b/gnu/packages/patches/mrustc-riscv64-support.patch new file mode 100644 index 0000000000..6312116585 --- /dev/null +++ b/gnu/packages/patches/mrustc-riscv64-support.patch @@ -0,0 +1,48 @@ +Patch sent upstream for review: +https://github.com/thepowersgang/mrustc/pull/276 + +diff --git a/src/trans/target.cpp b/src/trans/target.cpp +index 420a2870..4d5eefb3 100644 +--- a/src/trans/target.cpp ++++ b/src/trans/target.cpp +@@ -65,6 +65,13 @@ const TargetArch ARCH_POWERPC64LE = { + { /*atomic(u8)=*/true, true, true, true, true }, + TargetArch::Alignments(2, 4, 8, 16, 4, 8, 8) + }; ++// This is a guess ++const TargetArch ARCH_RISCV64 = { ++ "riscv64", ++ 64, false, ++ { /*atomic(u8)=*/true, true, true, true, true }, ++ TargetArch::Alignments(2, 4, 8, 16, 4, 8, 8) ++}; + TargetSpec g_target; + + +@@ -455,6 +462,13 @@ namespace + ARCH_POWERPC64LE + }; + } ++ else if(target_name == "riscv64-unknown-linux-gnu") ++ { ++ return TargetSpec { ++ "unix", "linux", "gnu", {CodegenMode::Gnu11, false, "riscv64-unknown-linux-gnu", BACKEND_C_OPTS_GNU}, ++ ARCH_RISCV64 ++ }; ++ } + else if(target_name == "i586-pc-windows-gnu") + { + return TargetSpec { +diff --git a/tools/common/target_detect.h b/tools/common/target_detect.h +index a052da6b..42fea91a 100644 +--- a/tools/common/target_detect.h ++++ b/tools/common/target_detect.h +@@ -34,6 +34,8 @@ + # define DEFAULT_TARGET_NAME "powerpc64-unknown-linux-gnu" + # elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) + # define DEFAULT_TARGET_NAME "powerpc64le-unknown-linux-gnu" ++# elif defined(__riscv) && __riscv_xlen == 64 ++# define DEFAULT_TARGET_NAME "riscv64-unknown-linux-gnu" + # else + # warning "Unable to detect a suitable default target (linux-gnu)" + # endif diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm index 38ed83f6bc..2942c5cb1f 100644 --- a/gnu/packages/rust.scm +++ b/gnu/packages/rust.scm @@ -137,7 +137,8 @@ (define %mrustc-source (file-name (git-file-name name (git-version version revision commit))) (sha256 (base32 - "0f7kh4n2663sn0z3xib8gzw0s97qpvwag40g2vs3bfjlrbpgi9z0"))))) + "0f7kh4n2663sn0z3xib8gzw0s97qpvwag40g2vs3bfjlrbpgi9z0")) + (patches (search-patches "mrustc-riscv64-support.patch"))))) ;;; Rust 1.54 is special in that it is built with mrustc, which shortens the ;;; bootstrap path. @@ -172,6 +173,10 @@ (define rust-bootstrap ;; https://github.com/thepowersgang/mrustc/issues/266 ;; https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105860 ("gcc" ,gcc-9) + ;; TODO: STARTFILE_PREFIX_SPEC is fixed on gcc<10 on core-updates. + ,@(if (target-riscv64?) + `(("gcc:lib" ,gcc-9 "lib")) + '()) ("flex" ,flex) ("pkg-config" ,pkg-config) ;; Required for the libstd sources. @@ -338,9 +343,11 @@ (define rust-bootstrap safety and thread safety guarantees.") (home-page "https://github.com/thepowersgang/mrustc") - ;; So far mrustc is (x86_64|aarch64)-only. It may support i686 soon: + ;; The intermediate generated code is known to be inefficient and + ;; therefore the build process needs 8GB of RAM while building. + ;; It may support i686 soon: ;; . - (supported-systems '("x86_64-linux" "aarch64-linux")) + (supported-systems '("x86_64-linux" "aarch64-linux" "riscv64-linux")) ;; Dual licensed. (license (list license:asl2.0 license:expat))))