summaryrefslogtreecommitdiff
path: root/gnu/packages/rust.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/packages/rust.scm')
-rw-r--r--gnu/packages/rust.scm171
1 files changed, 61 insertions, 110 deletions
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)