summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnu/local.mk2
-rw-r--r--gnu/packages/patches/mrustc-patches.patch19
-rw-r--r--gnu/packages/patches/rustc-1.54.0-src.patch304
-rw-r--r--gnu/packages/rust.scm171
4 files changed, 81 insertions, 415 deletions
diff --git a/gnu/local.mk b/gnu/local.mk
index f118fe44420..f7412d055f6 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1849,6 +1849,7 @@ dist_patch_DATA = \
1849 %D%/packages/patches/mono-mcs-patches-from-5.10.0.patch \ 1849 %D%/packages/patches/mono-mcs-patches-from-5.10.0.patch \
1850 %D%/packages/patches/mosaicatcher-unbundle-htslib.patch \ 1850 %D%/packages/patches/mosaicatcher-unbundle-htslib.patch \
1851 %D%/packages/patches/mrrescue-support-love-11.patch \ 1851 %D%/packages/patches/mrrescue-support-love-11.patch \
1852 %D%/packages/patches/mrustc-patches.patch \
1852 %D%/packages/patches/mtools-mformat-uninitialized.patch \ 1853 %D%/packages/patches/mtools-mformat-uninitialized.patch \
1853 %D%/packages/patches/mupen64plus-ui-console-notice.patch \ 1854 %D%/packages/patches/mupen64plus-ui-console-notice.patch \
1854 %D%/packages/patches/musl-cross-locale.patch \ 1855 %D%/packages/patches/musl-cross-locale.patch \
@@ -2177,7 +2178,6 @@ dist_patch_DATA = \
2177 %D%/packages/patches/ruby-mustache-1.1.1-fix-race-condition-tests.patch \ 2178 %D%/packages/patches/ruby-mustache-1.1.1-fix-race-condition-tests.patch \
2178 %D%/packages/patches/ruby-nokogiri.patch \ 2179 %D%/packages/patches/ruby-nokogiri.patch \
2179 %D%/packages/patches/ruby-x25519-automatic-fallback-non-x86_64.patch \ 2180 %D%/packages/patches/ruby-x25519-automatic-fallback-non-x86_64.patch \
2180 %D%/packages/patches/rustc-1.54.0-src.patch \
2181 %D%/packages/patches/rust-1.64-fix-riscv64-bootstrap.patch \ 2181 %D%/packages/patches/rust-1.64-fix-riscv64-bootstrap.patch \
2182 %D%/packages/patches/rust-1.70-fix-rustix-build.patch \ 2182 %D%/packages/patches/rust-1.70-fix-rustix-build.patch \
2183 %D%/packages/patches/rust-1.78-unwinding-fix.patch \ 2183 %D%/packages/patches/rust-1.78-unwinding-fix.patch \
diff --git a/gnu/packages/patches/mrustc-patches.patch b/gnu/packages/patches/mrustc-patches.patch
new file mode 100644
index 00000000000..626945e2a12
--- /dev/null
+++ b/gnu/packages/patches/mrustc-patches.patch
@@ -0,0 +1,19 @@
1diff --git a/rustc-1.54.0-src.patch b/rustc-1.54.0-src.patch
2index 088c723a..d322fd0d 100644
3--- a/rustc-1.54.0-src.patch
4+++ b/rustc-1.54.0-src.patch
5@@ -302,14 +302,3 @@
6 use self::generic as arch;
7
8 pub use self::arch::{vec128_storage, vec256_storage, vec512_storage};
9-
10---- src/llvm-project/llvm/include/llvm/Support/Signals.h
11-+++ src/llvm-project/llvm/include/llvm/Support/Signals.h
12-@@ -14,6 +14,7 @@
13- #ifndef LLVM_SUPPORT_SIGNALS_H
14- #define LLVM_SUPPORT_SIGNALS_H
15-
16-+#include <cstdint>
17- #include <string>
18-
19- namespace llvm {
diff --git a/gnu/packages/patches/rustc-1.54.0-src.patch b/gnu/packages/patches/rustc-1.54.0-src.patch
deleted file mode 100644
index d322fd0d499..00000000000
--- a/gnu/packages/patches/rustc-1.54.0-src.patch
+++ /dev/null
@@ -1,304 +0,0 @@
1# mrustc is much better at enum packing, so causes almost all of these to be smaller by one pointer
2--- compiler/rustc_ast/src/ast.rs
3+++ compiler/rustc_ast/src/ast.rs
4@@ -1075,7 +1075,7 @@ pub struct Expr {
5 }
6
7 // `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
8-#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
9+#[cfg(all(not(rust_compiler = "mrustc"), target_arch = "x86_64", target_pointer_width = "64"))]
10 rustc_data_structures::static_assert_size!(Expr, 104);
11
12 impl Expr {
13@@ -2779,7 +2779,7 @@ pub enum AssocItemKind {
14 MacCall(MacCall),
15 }
16
17-#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
18+#[cfg(all(not(rust_compiler = "mrustc"), target_arch = "x86_64", target_pointer_width = "64"))]
19 rustc_data_structures::static_assert_size!(AssocItemKind, 72);
20
21 impl AssocItemKind {
22@@ -2831,7 +2831,7 @@ pub enum ForeignItemKind {
23 MacCall(MacCall),
24 }
25
26-#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
27+#[cfg(all(not(rust_compiler="mrustc"),target_arch = "x86_64", target_pointer_width = "64"))]
28 rustc_data_structures::static_assert_size!(ForeignItemKind, 72);
29
30 impl From<ForeignItemKind> for ItemKind {
31
32--- compiler/rustc_hir/src/hir.rs
33+++ compiler/rustc_hir/src/hir.rs
34@@ -3048,7 +3048,7 @@ impl<'hir> Node<'hir> {
35 }
36
37 // Some nodes are used a lot. Make sure they don't unintentionally get bigger.
38-#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
39+#[cfg(all(not(rust_compiler="mrustc"),target_arch = "x86_64", target_pointer_width = "64"))]
40 mod size_asserts {
41 rustc_data_structures::static_assert_size!(super::Block<'static>, 48);
42 rustc_data_structures::static_assert_size!(super::Expr<'static>, 64);
43
44--- compiler/rustc_middle/src/mir/interpret/error.rs
45+++ compiler/rustc_middle/src/mir/interpret/error.rs
46@@ -449,7 +449,7 @@ impl dyn MachineStopType {
47 }
48 }
49
50-#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
51+#[cfg(all(not(rust_compiler="mrustc"), target_arch = "x86_64", target_pointer_width = "64"))]
52 static_assert_size!(InterpError<'_>, 64);
53
54 pub enum InterpError<'tcx> {
55
56--- compiler/rustc_middle/src/mir/mod.rs
57+++ compiler/rustc_middle/src/mir/mod.rs
58@@ -2200,7 +2200,7 @@ pub enum AggregateKind<'tcx> {
59 Generator(DefId, SubstsRef<'tcx>, hir::Movability),
60 }
61
62-#[cfg(target_arch = "x86_64")]
63+#[cfg(all(not(rust_compiler="mrustc"), target_arch = "x86_64"))]
64 static_assert_size!(AggregateKind<'_>, 48);
65
66 #[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
67
68--- compiler/rustc_middle/src/thir.rs
69+++ compiler/rustc_middle/src/thir.rs
70@@ -144,7 +144,7 @@ pub enum StmtKind<'tcx> {
71 }
72
73 // `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
74-#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
75+#[cfg(all(not(rust_compiler="mrustc"), target_arch = "x86_64", target_pointer_width = "64"))]
76 rustc_data_structures::static_assert_size!(Expr<'_>, 144);
77
78 /// The Thir trait implementor lowers their expressions (`&'tcx H::Expr`)
79
80--- compiler/rustc_mir/src/interpret/operand.rs
81+++ compiler/rustc_mir/src/interpret/operand.rs
82@@ -32,7 +32,7 @@ pub enum Immediate<Tag = ()> {
83 ScalarPair(ScalarMaybeUninit<Tag>, ScalarMaybeUninit<Tag>),
84 }
85
86-#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
87+#[cfg(all(not(rust_compiler = "mrustc"), target_arch = "x86_64", target_pointer_width = "64"))]
88 rustc_data_structures::static_assert_size!(Immediate, 56);
89
90 impl<Tag> From<ScalarMaybeUninit<Tag>> for Immediate<Tag> {
91@@ -87,7 +87,7 @@ pub struct ImmTy<'tcx, Tag = ()> {
92 pub layout: TyAndLayout<'tcx>,
93 }
94
95-#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
96+#[cfg(all(not(rust_compiler = "mrustc"), target_arch = "x86_64", target_pointer_width = "64"))]
97 rustc_data_structures::static_assert_size!(ImmTy<'_>, 72);
98
99 impl<Tag: Copy> std::fmt::Display for ImmTy<'tcx, Tag> {
100
101--- compiler/rustc_mir/src/interpret/place.rs
102+++ compiler/rustc_mir/src/interpret/place.rs
103@@ -88,7 +88,7 @@ pub enum Place<Tag = ()> {
104 Local { frame: usize, local: mir::Local },
105 }
106
107-#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
108+#[cfg(all(not(rust_compiler = "mrustc"), target_arch = "x86_64", target_pointer_width = "64"))]
109 rustc_data_structures::static_assert_size!(Place, 64);
110
111 #[derive(Copy, Clone, Debug)]
112@@ -97,7 +97,7 @@ pub struct PlaceTy<'tcx, Tag = ()> {
113 pub layout: TyAndLayout<'tcx>,
114 }
115
116-#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
117+#[cfg(all(not(rust_compiler = "mrustc"), target_arch = "x86_64", target_pointer_width = "64"))]
118 rustc_data_structures::static_assert_size!(PlaceTy<'_>, 80);
119
120 impl<'tcx, Tag> std::ops::Deref for PlaceTy<'tcx, Tag> {
121
122#
123# Disable std_detect's detection logic (use the same logic as miri)
124#
125--- library/stdarch/crates/std_detect/src/detect/mod.rs
126+++ library/stdarch/crates/std_detect/src/detect/mod.rs
127@@ -86,7 +86,7 @@ mod bit;
128 mod cache;
129
130 cfg_if! {
131- if #[cfg(miri)] {
132+ if #[cfg(any(miri, rust_compiler = "mrustc"))] {
133 // When running under miri all target-features that are not enabled at
134 // compile-time are reported as disabled at run-time.
135 //
136
137#
138# Disable crc32fast's use of stdarch
139#
140--- vendor/crc32fast/src/specialized/mod.rs
141+++ vendor/crc32fast/src/specialized/mod.rs
142@@ -1,5 +1,6 @@
143 cfg_if! {
144 if #[cfg(all(
145+ not(rust_compiler = "mrustc"),
146 crc32fast_stdarchx86,
147 any(target_arch = "x86", target_arch = "x86_64")
148 ))] {
149
150#
151# Backport which is required to support arm64 on macOS 12
152# See: https://github.com/alexcrichton/curl-rust/commit/0aea09c428b9bc2bcf46da0fc33959fe3f03c74a
153#
154--- vendor/curl/src/lib.rs
155+++ vendor/curl/src/lib.rs
156@@ -82,6 +82,9 @@ pub mod easy;
157 pub mod multi;
158 mod panic;
159
160+#[cfg(test)]
161+static INITIALIZED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
162+
163 /// Initializes the underlying libcurl library.
164 ///
165 /// The underlying libcurl library must be initialized before use, and must be
166@@ -102,46 +105,62 @@ pub fn init() {
167 /// Used to prevent concurrent or duplicate initialization.
168 static INIT: Once = Once::new();
169
170- /// An exported constructor function. On supported platforms, this will be
171- /// invoked automatically before the program's `main` is called.
172- #[cfg_attr(
173- any(target_os = "linux", target_os = "freebsd", target_os = "android"),
174- link_section = ".init_array"
175- )]
176- #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
177- #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
178- static INIT_CTOR: extern "C" fn() = init_inner;
179+ INIT.call_once(|| {
180+ #[cfg(need_openssl_init)]
181+ openssl_probe::init_ssl_cert_env_vars();
182+ #[cfg(need_openssl_init)]
183+ openssl_sys::init();
184+
185+ unsafe {
186+ assert_eq!(curl_sys::curl_global_init(curl_sys::CURL_GLOBAL_ALL), 0);
187+ }
188+
189+ #[cfg(test)]
190+ {
191+ INITIALIZED.store(true, std::sync::atomic::Ordering::SeqCst);
192+ }
193+
194+ // Note that we explicitly don't schedule a call to
195+ // `curl_global_cleanup`. The documentation for that function says
196+ //
197+ // > You must not call it when any other thread in the program (i.e. a
198+ // > thread sharing the same memory) is running. This doesn't just mean
199+ // > no other thread that is using libcurl.
200+ //
201+ // We can't ever be sure of that, so unfortunately we can't call the
202+ // function.
203+ });
204+}
205
206+/// An exported constructor function. On supported platforms, this will be
207+/// invoked automatically before the program's `main` is called. This is done
208+/// for the convenience of library users since otherwise the thread-safety rules
209+/// around initialization can be difficult to fulfill.
210+///
211+/// This is a hidden public item to ensure the symbol isn't optimized away by a
212+/// rustc/LLVM bug: https://github.com/rust-lang/rust/issues/47384. As long as
213+/// any item in this module is used by the final binary (which `init` will be)
214+/// then this symbol should be preserved.
215+#[used]
216+#[doc(hidden)]
217+#[cfg_attr(
218+ any(target_os = "linux", target_os = "freebsd", target_os = "android"),
219+ link_section = ".init_array"
220+)]
221+#[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
222+#[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
223+pub static INIT_CTOR: extern "C" fn() = {
224 /// This is the body of our constructor function.
225 #[cfg_attr(
226 any(target_os = "linux", target_os = "android"),
227 link_section = ".text.startup"
228 )]
229- extern "C" fn init_inner() {
230- INIT.call_once(|| {
231- #[cfg(need_openssl_init)]
232- openssl_sys::init();
233-
234- unsafe {
235- assert_eq!(curl_sys::curl_global_init(curl_sys::CURL_GLOBAL_ALL), 0);
236- }
237-
238- // Note that we explicitly don't schedule a call to
239- // `curl_global_cleanup`. The documentation for that function says
240- //
241- // > You must not call it when any other thread in the program (i.e.
242- // > a thread sharing the same memory) is running. This doesn't just
243- // > mean no other thread that is using libcurl.
244- //
245- // We can't ever be sure of that, so unfortunately we can't call the
246- // function.
247- });
248+ extern "C" fn init_ctor() {
249+ init();
250 }
251
252- // We invoke our init function through our static to ensure the symbol isn't
253- // optimized away by a bug: https://github.com/rust-lang/rust/issues/47384
254- INIT_CTOR();
255-}
256+ init_ctor
257+};
258
259 unsafe fn opt_str<'a>(ptr: *const libc::c_char) -> Option<&'a str> {
260 if ptr.is_null() {
261@@ -158,3 +177,20 @@ fn cvt(r: curl_sys::CURLcode) -> Result<(), Error> {
262 Err(Error::new(r))
263 }
264 }
265+
266+#[cfg(test)]
267+mod tests {
268+ use super::*;
269+
270+ #[test]
271+ #[cfg(any(
272+ target_os = "linux",
273+ target_os = "macos",
274+ target_os = "windows",
275+ target_os = "freebsd",
276+ target_os = "android"
277+ ))]
278+ fn is_initialized_before_main() {
279+ assert!(INITIALIZED.load(std::sync::atomic::Ordering::SeqCst));
280+ }
281+}
282
283# PPV-Lite also needs to know that we're pretending to be miri
284--- vendor/ppv-lite86/src/lib.rs
285+++ vendor/ppv-lite86/src/lib.rs
286@@ -9,14 +9,14 @@ mod soft;
287 mod types;
288 pub use self::types::*;
289
290-#[cfg(all(feature = "simd", target_arch = "x86_64", not(miri)))]
291+#[cfg(all(feature = "simd", target_arch = "x86_64", not(miri), not(rust_compiler = "mrustc")))]
292 pub mod x86_64;
293-#[cfg(all(feature = "simd", target_arch = "x86_64", not(miri)))]
294+#[cfg(all(feature = "simd", target_arch = "x86_64", not(miri), not(rust_compiler = "mrustc")))]
295 use self::x86_64 as arch;
296
297-#[cfg(any(miri, not(all(feature = "simd", any(target_arch = "x86_64")))))]
298+#[cfg(any(miri, rust_compiler = "mrustc", not(all(feature = "simd", any(target_arch = "x86_64")))))]
299 pub mod generic;
300-#[cfg(any(miri, not(all(feature = "simd", any(target_arch = "x86_64")))))]
301+#[cfg(any(miri, rust_compiler = "mrustc", not(all(feature = "simd", any(target_arch = "x86_64")))))]
302 use self::generic as arch;
303
304 pub use self::arch::{vec128_storage, vec256_storage, vec512_storage};
diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
index d5da35b5afc..e55b91b1fe4 100644
--- a/gnu/packages/rust.scm
+++ b/gnu/packages/rust.scm
@@ -128,9 +128,9 @@
128 128
129;;; Note: mrustc's only purpose is to be able to bootstap Rust; it's designed 129;;; Note: mrustc's only purpose is to be able to bootstap Rust; it's designed
130;;; to be used in source form. 130;;; to be used in source form.
131(define %mrustc-commit "b6754f574f8846eb842feba4ccbeeecb10bdfacc") 131(define %mrustc-commit "5e01a76097265f4bb27b18885b9af3f2778180f9")
132(define %mrustc-source 132(define %mrustc-source
133 (let* ((version "0.10.1") 133 (let* ((version "0.11.0")
134 (commit %mrustc-commit) 134 (commit %mrustc-commit)
135 (revision "1") 135 (revision "1")
136 (name "mrustc")) 136 (name "mrustc"))
@@ -138,11 +138,11 @@
138 (method git-fetch) 138 (method git-fetch)
139 (uri (git-reference 139 (uri (git-reference
140 (url "https://github.com/thepowersgang/mrustc") 140 (url "https://github.com/thepowersgang/mrustc")
141 (commit (string-append "v" version)))) 141 (commit %mrustc-commit)))
142 (file-name (git-file-name name version)) 142 (file-name (git-file-name name (git-version version revision commit)))
143 (sha256 143 (sha256
144 (base32 144 (base32 "1yyjfl1z6d5r9sv7zl90kqyjw1lqd2cqzwh2syi7yvrpslhihrhy"))
145 "0rqiif7rb5hg6ik3i1flldj311f014q4n9z8wb50cs8kspjz32di")) 145 (patches (search-patches "mrustc-patches.patch"))
146 (modules '((guix build utils))) 146 (modules '((guix build utils)))
147 (snippet 147 (snippet
148 '(begin 148 '(begin
@@ -150,7 +150,10 @@
150 ;; by disabling debug by default. 150 ;; by disabling debug by default.
151 (substitute* (find-files "." "Makefile") 151 (substitute* (find-files "." "Makefile")
152 (("LINKFLAGS := -g") "LINKFLAGS :=") 152 (("LINKFLAGS := -g") "LINKFLAGS :=")
153 (("-g ") ""))))))) 153 (("-g ") ""))
154 ;; Don't use the vendored openssl sources.
155 (substitute* "minicargo.mk"
156 (("--features vendored-openssl") "")))))))
154 157
155;;; Rust 1.54 is special in that it is built with mrustc, which shortens the 158;;; Rust 1.54 is special in that it is built with mrustc, which shortens the
156;;; bootstrap path. 159;;; bootstrap path.
@@ -177,26 +180,24 @@
177 ;; Also remove the bundled (mostly Windows) libraries. 180 ;; Also remove the bundled (mostly Windows) libraries.
178 ;; find vendor -not -type d -exec file {} \+ | grep PE32 181 ;; find vendor -not -type d -exec file {} \+ | grep PE32
179 (for-each delete-file 182 (for-each delete-file
180 (find-files "vendor" "\\.(a|dll|exe|lib)$")))) 183 (find-files "vendor" "\\.(a|dll|exe|lib)$"))
181 (patches (search-patches "rustc-1.54.0-src.patch")) 184 ;; Adjust some sources for llvm-13, see llvm commit
182 (patch-flags '("-p0")))) ;default is -p1 185 ;; acce401068e78a8c5dc9e06802111ffad3da763f
186 (substitute* (find-files "." "powerpc64le_unknown_linux_gnu.rs")
187 (("e-m:e-i64:64-n32:64-v256:256:256-v512:512:512")
188 "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512"))))))
183 (outputs '("out" "cargo")) 189 (outputs '("out" "cargo"))
184 (properties '((hidden? . #t) 190 (properties '((hidden? . #t)
185 (timeout . 129600) ;36 hours 191 (timeout . 129600) ;36 hours
186 (max-silent-time . 18000))) ;5 hours (for armel) 192 (max-silent-time . 18000))) ;5 hours (for armel)
187 (build-system gnu-build-system) 193 (build-system gnu-build-system)
188 (inputs 194 (inputs
189 `(("bash-minimal" ,bash-minimal) 195 (list bash-minimal
190 ,@(if (or (target-ppc64le?) 196 llvm-13
191 (target-riscv64?)) 197 openssl-1.1
192 `(("clang" ,clang-13)) 198 zlib))
193 `())
194 ("llvm" ,llvm-13)
195 ("openssl" ,openssl-1.1)
196 ("zlib" ,zlib)))
197 (native-inputs 199 (native-inputs
198 `(("pkg-config" ,pkg-config) 200 `(("pkg-config" ,pkg-config)
199 ;; Required for the libstd sources.
200 ("mrustc-source" ,%mrustc-source))) 201 ("mrustc-source" ,%mrustc-source)))
201 (arguments 202 (arguments
202 `(#:imported-modules ,%cargo-utils-modules ;for `generate-all-checksums' 203 `(#:imported-modules ,%cargo-utils-modules ;for `generate-all-checksums'
@@ -207,85 +208,49 @@
207 ;; Rust's own .so library files are not found in any RUNPATH, but 208 ;; Rust's own .so library files are not found in any RUNPATH, but
208 ;; that doesn't seem to cause issues. 209 ;; that doesn't seem to cause issues.
209 #:validate-runpath? #f 210 #:validate-runpath? #f
210 ;; We currently see race conditions between various dependant crates.
211 ;; TODO: Re-evaluate after moving to a more recent mrustc.
212 #:parallel-build? #f
213 #:make-flags 211 #:make-flags
214 (list ,(string-append "RUSTC_TARGET=" 212 ,#~(let ((source #$(package-source this-package)))
215 (platform-rust-target 213 (list (string-append "RUSTC_TARGET="
216 (lookup-platform-by-target-or-system 214 #$(platform-rust-target
217 (or (%current-target-system) 215 (lookup-platform-by-target-or-system
218 (%current-system))))) 216 (or (%current-target-system)
219 ,(string-append "RUSTC_VERSION=" version) 217 (%current-system)))))
220 ,(string-append "MRUSTC_TARGET_VER=" 218 (string-append "RUSTC_VERSION=" #$version)
221 (version-major+minor version)) 219 (string-append "MRUSTC_TARGET_VER="
222 ;; mrustc expects a C11 compatible compiler. Use the default 220 #$(version-major+minor version))
223 ;; C language dialect from the GCC-10 compiler. 221 (string-append "RUSTC_SRC_TARBALL=" source)
224 ;; This is necessary for some architectures. 222 "OUTDIR_SUF=")) ;do not add version suffix to output dir
225 "CFLAGS=-std=gnu11"
226 "OUTDIR_SUF=") ;do not add version suffix to output dir
227 #:phases 223 #:phases
228 (modify-phases %standard-phases 224 (modify-phases %standard-phases
229 ,@(if (target-ppc64le?) 225 (replace 'unpack
230 `((add-after 'unpack 'patch-sources-for-newer-llvm 226 (lambda* (#:key source inputs #:allow-other-keys)
231 (lambda _ 227 ((assoc-ref %standard-phases 'unpack)
232 ;; Adjust some sources for llvm-13, see llvm commit 228 #:source (assoc-ref inputs "mrustc-source"))))
233 ;; acce401068e78a8c5dc9e06802111ffad3da763f 229 (add-after 'unpack 'patch-makefiles
234 (substitute* (find-files "." "powerpc64le_unknown_linux_gnu.rs")
235 (("e-m:e-i64:64-n32:64-v256:256:256-v512:512:512")
236 "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512")))))
237 '())
238 (add-after 'unpack 'setup-mrustc-sources
239 (lambda* (#:key inputs #:allow-other-keys)
240 (copy-recursively (assoc-ref inputs "mrustc-source") "../mrustc")
241 ;; The Makefile of mrustc expects the sources directory of rustc
242 ;; to be at this location, and it simplifies things to make it
243 ;; so.
244 (symlink (getcwd)
245 (string-append "../mrustc/rustc-" ,version "-src"))
246 (with-output-to-file "dl-version"
247 (lambda _
248 (format #t "~a~%"
249 ,version)))))
250 (add-after 'setup-mrustc-sources 'patch-makefiles
251 ;; This disables building the (unbundled) LLVM. 230 ;; This disables building the (unbundled) LLVM.
252 (lambda* (#:key inputs parallel-build? #:allow-other-keys) 231 (lambda* (#:key inputs #:allow-other-keys)
253 (let ((llvm (assoc-ref inputs "llvm"))) 232 (substitute* '("minicargo.mk"
254 (with-directory-excursion "../mrustc" 233 "run_rustc/Makefile")
255 (substitute* '("minicargo.mk" 234 ;; Use the system-provided LLVM.
256 "run_rustc/Makefile") 235 (("LLVM_CONFIG [:|?]= .*")
257 ;; Use the system-provided LLVM. 236 (string-append "LLVM_CONFIG := "
258 (("LLVM_CONFIG [:|?]= .*") 237 (search-input-file inputs "/bin/llvm-config") "\n")))
259 (string-append "LLVM_CONFIG := " llvm "/bin/llvm-config\n"))) 238 (substitute* "Makefile"
260 (substitute* "minicargo.mk" 239 ;; Patch date and git obtained version information.
261 ;; Do not try to fetch sources from the Internet. 240 ((" -D VERSION_GIT_FULLHASH=.*")
262 (("@curl.*") "") 241 (string-append
263 (("\\$\\(MINICARGO\\) \\$\\(RUSTC_SRC_DL\\)") 242 " -D VERSION_GIT_FULLHASH=\\\"" ,%mrustc-commit "\\\""
264 "$(MINICARGO)")) 243 " -D VERSION_GIT_BRANCH=\\\"master\\\""
265 (substitute* "Makefile" 244 " -D VERSION_GIT_SHORTHASH=\\\""
266 ;; Patch date and git obtained version information. 245 ,(string-take %mrustc-commit 7) "\\\""
267 ((" -D VERSION_GIT_FULLHASH=.*") 246 " -D VERSION_BUILDTIME="
268 (string-append 247 "\"\\\"Thu, 01 Jan 1970 00:00:01 +0000\\\"\""
269 " -D VERSION_GIT_FULLHASH=\\\"" ,%mrustc-commit "\\\"" 248 " -D VERSION_GIT_ISDIRTY=0\n")))
270 " -D VERSION_GIT_BRANCH=\\\"master\\\"" 249 (substitute* '("run_rustc/Makefile"
271 " -D VERSION_GIT_SHORTHASH=\\\"" 250 "run_rustc/rustc_proxy.sh")
272 ,(string-take %mrustc-commit 7) "\\\"" 251 ;; Patch the shebang of a generated wrapper for rustc
273 " -D VERSION_BUILDTIME=" 252 (("#!/bin/sh")
274 "\"\\\"Thu, 01 Jan 1970 00:00:01 +0000\\\"\"" 253 (string-append "#!" (which "sh"))))))
275 " -D VERSION_GIT_ISDIRTY=0\n")))
276 (substitute* "run_rustc/Makefile"
277 ;; Patch the shebang of a generated wrapper for rustc
278 (("#!/bin/sh")
279 (string-append "#!" (which "sh"))))
280 (substitute* "run_rustc/rustc_proxy.sh"
281 (("#!/bin/sh")
282 (string-append "#!" (which "sh"))))))))
283 (add-after 'patch-generated-file-shebangs 'patch-cargo-checksums
284 (lambda _
285 (substitute* "Cargo.lock"
286 (("(checksum = )\".*\"" all name)
287 (string-append name "\"" ,%cargo-reference-hash "\"")))
288 (generate-all-checksums "vendor")))
289 (add-before 'configure 'configure-cargo-home 254 (add-before 'configure 'configure-cargo-home
290 (lambda _ 255 (lambda _
291 (let ((cargo-home (string-append (getcwd) "/.cargo"))) 256 (let ((cargo-home (string-append (getcwd) "/.cargo")))
@@ -293,12 +258,8 @@
293 (setenv "CARGO_HOME" cargo-home)))) 258 (setenv "CARGO_HOME" cargo-home))))
294 (replace 'configure 259 (replace 'configure
295 (lambda _ 260 (lambda _
296 ,@(if (or (target-ppc64le?) 261 (setenv "CC" "gcc")
297 (target-riscv64?)) 262 (setenv "CXX" "g++")
298 `((setenv "CC" "clang")
299 (setenv "CXX" "clang++"))
300 `((setenv "CC" "gcc")
301 (setenv "CXX" "g++")))
302 ;; The Guix LLVM package installs only shared libraries. 263 ;; The Guix LLVM package installs only shared libraries.
303 (setenv "LLVM_LINK_SHARED" "1") 264 (setenv "LLVM_LINK_SHARED" "1")
304 ;; rustc still insists on having 'cc' on PATH in some places 265 ;; rustc still insists on having 'cc' on PATH in some places
@@ -314,7 +275,6 @@
314 1))) 275 1)))
315 ;; Adapted from: 276 ;; Adapted from:
316 ;; https://github.com/dtolnay/bootstrap/blob/master/build-1.54.0.sh. 277 ;; https://github.com/dtolnay/bootstrap/blob/master/build-1.54.0.sh.
317 (chdir "../mrustc")
318 ;; Use PARLEVEL since both minicargo and mrustc use it 278 ;; Use PARLEVEL since both minicargo and mrustc use it
319 ;; to set the level of parallelism. 279 ;; to set the level of parallelism.
320 (setenv "PARLEVEL" (number->string job-count)) 280 (setenv "PARLEVEL" (number->string job-count))
@@ -335,15 +295,6 @@
335 (apply invoke "make" "-f" "minicargo.mk" "output/rustc" 295 (apply invoke "make" "-f" "minicargo.mk" "output/rustc"
336 make-flags) 296 make-flags)
337 297
338 ;; We can to continue the build with gcc after building rustc.
339 ;; librustc_driver.so undefined reference to
340 ;; `llvm::cfg::Update<llvm::BasicBlock*>::dump() const'
341 ,@(if (or (target-ppc64le?)
342 (target-riscv64?))
343 `((setenv "CC" "gcc")
344 (setenv "CXX" "g++"))
345 `())
346
347 (display "Building cargo...\n") 298 (display "Building cargo...\n")
348 (apply invoke "make" "-f" "minicargo.mk" "output/cargo" 299 (apply invoke "make" "-f" "minicargo.mk" "output/cargo"
349 make-flags) 300 make-flags)