gnu: emacs-svg-icon: Fix grammar.
[jackhill/guix/guix.git] / gnu / packages / julia.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016, 2017 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2016, 2020 Efraim Flashner <efraim@flashner.co.il>
4 ;;; Copyright © 2020 Nicolò Balzarotti <nicolo@nixo.xyz>
5 ;;; Copyright © 2020 Tim Howes <timhowes@lavabit.com>
6 ;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
7 ;;;
8 ;;; This file is part of GNU Guix.
9 ;;;
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
14 ;;;
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23 (define-module (gnu packages julia)
24 #:use-module ((guix licenses) #:prefix license:)
25 #:use-module (guix packages)
26 #:use-module (guix download)
27 #:use-module (guix utils)
28 #:use-module (guix git-download)
29 #:use-module (guix build-system gnu)
30 #:use-module (gnu packages)
31 #:use-module (gnu packages algebra)
32 #:use-module (gnu packages base)
33 #:use-module (gnu packages compression)
34 #:use-module (gnu packages curl)
35 #:use-module (gnu packages elf)
36 #:use-module (gnu packages gcc)
37 #:use-module (gnu packages llvm)
38 #:use-module (gnu packages libevent)
39 #:use-module (gnu packages libunwind)
40 #:use-module (gnu packages maths)
41 #:use-module (gnu packages multiprecision) ; mpfr
42 #:use-module (gnu packages pcre)
43 #:use-module (gnu packages perl)
44 #:use-module (gnu packages pkg-config)
45 #:use-module (gnu packages python)
46 #:use-module (gnu packages python-xyz)
47 #:use-module (gnu packages textutils)
48 #:use-module (gnu packages ssh)
49 #:use-module (gnu packages tls)
50 #:use-module (gnu packages version-control)
51 #:use-module (gnu packages wget)
52 #:use-module (ice-9 match))
53
54 (define libuv-julia
55 (let ((commit "1fcc6d66f9df74189c74d3d390f02202bb7db953")
56 (revision "2"))
57 ;; When upgrading Julia, also upgrade this. Get the commit from
58 ;; https://github.com/JuliaLang/julia/blob/v1.5.2/deps/libuv.version
59 (package
60 (inherit libuv)
61 (name "libuv-julia")
62 (version (git-version "2.0.0" revision commit))
63 (source (origin
64 (method git-fetch)
65 (uri (git-reference
66 (url "https://github.com/JuliaLang/libuv")
67 (commit commit)))
68 (file-name (string-append name "-" version "-checkout"))
69 (sha256
70 (base32
71 "040l7f1hk7xyza11sry5cj4fhw05na949865axqqhxnifdvnmfji"))))
72 (build-system gnu-build-system)
73 (arguments
74 (substitute-keyword-arguments (package-arguments libuv)
75 ((#:phases phases)
76 `(modify-phases ,phases
77 (delete 'autogen)))))
78 (home-page "https://github.com/JuliaLang/libuv"))))
79
80 (define libunwind-julia
81 ;; The Julia projects requires their patched version.
82 ;; Get from https://github.com/JuliaLang/julia/tree/master/deps/patches
83 (package
84 (inherit libunwind)
85 (name "libunwind-julia")
86 (version "1.3.1")
87 (source
88 (origin
89 (method url-fetch)
90 (uri (string-append "mirror://savannah/libunwind/libunwind-"
91 version ".tar.gz"))
92 (sha256
93 (base32
94 "1y0l08k6ak1mqbfj6accf9s5686kljwgsl4vcqpxzk5n74wpm6a3"))
95 (patches
96 (list
97 (julia-patch "libunwind-prefer-extbl"
98 "0lr4dafw8qyfh8sw8hhbwkql1dlhqv8px7k81y2l20hhxfgnh2m1")
99 (julia-patch "libunwind-static-arm"
100 "1jk3bmiw61ypcchqkk1fyg5wh8wpggk574wxyfyaic870zh3lhgq")))))
101 (home-page "https://github.com/JuliaLang/tree/master/deps/")))
102
103 (define (julia-patch-url version name)
104 (string-append "https://raw.githubusercontent.com/JuliaLang/julia/v" version
105 "/deps/patches/" name ".patch"))
106
107 (define (julia-patch name sha)
108 (let ((version "1.5.3"))
109 (origin (method url-fetch)
110 (uri (julia-patch-url version name))
111 (sha256 (base32 sha))
112 (file-name name))))
113
114 (define llvm-julia
115 (package
116 (inherit llvm-9)
117 (name "llvm-julia")
118 (source (origin
119 (inherit (package-source llvm-9))
120 ;; Those patches are inside the Julia source repo.
121 ;; They are _not_ Julia specific (https://github.com/julialang/julia#llvm)
122 ;; but they are required to build Julia.
123 ;; Discussion: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=919628
124 (patches
125 (map (match-lambda
126 ((name hash)
127 (julia-patch name hash)))
128 (list
129 '("llvm-D27629-AArch64-large_model_6.0.1"
130 "1qrshmlqvnasdyc158vfn3hnbigqph3lsq7acb9w8lwkpnnm2j4z")
131 '("llvm8-D34078-vectorize-fdiv"
132 "19spqc3xsazn1xs9gpcgv9ldadfkv49rmc5khl7sf1dlmhgi4602")
133 '("llvm-7.0-D44650"
134 "1h55kkmkiisfj6sk956if2bcj9s0v6n5czn8dxb870vp5nccj3ir")
135 '("llvm9-D50010-VNCoercion-ni"
136 "1s1d3sjsiq4vxg7ncy5cz56zgy5vcq6ls3iqaiqkvr23wyryqmdx")
137 '("llvm-exegesis-mingw"
138 "0ph1cj1j7arvf1xq2xcr7qf9g0cpdl14fincgr67vpi520zvd3vp")
139 '("llvm-test-plugin-mingw"
140 "12z738cnahbf6n381im7i0hxp1m6k9hrnfjlmq9sac46nxly9gnj")
141 '("llvm7-revert-D44485"
142 "0f59kq3p3mpwsbmskypbi4zn01l6ig0x7v2rjp08k2r8z8m6fa8n")
143 '("llvm-8.0-D66657-codegen-degenerate"
144 "1n1ddx19h90bbpimdyd9dh8fsm6gb93xxyqm4ljkxa1k3cx2vm72")
145 '("llvm-8.0-D71495-vectorize-freduce"
146 "1zff08wvji9lnpskk4b3p5zyjsy5hhy23ynxjqlj9dw7jvvfrf0p")
147 '("llvm-D75072-SCEV-add-type"
148 "029a3fywsm233vf48mscina24idd50dc75wr70lmimrhwnw27p0z")
149 '("llvm-9.0-D65174-limit-merge-stores"
150 "04bff1mnblfj9mxfdwr1qdnw3i3szmp60gnhxwas5y68qg33z6j0")
151 '("llvm9-D71443-PPC-MC-redef-symbol"
152 "1c93nv7rgc9jg5mqrnvv08xib1789qvlql94fwggh18mp3b9hbgy")
153 '("llvm-9.0-D78196"
154 "08a43hyg7yyqjq2vmfsmppf34xcz60wq6y9zw5fdyhw2h1mcnmns")
155 '("llvm-julia-tsan-custom-as"
156 "0awh40kf6lm4wn1nsjd1bmhfwq7rqj811szanp2xkpspykw9hg9s")
157 '("llvm-9.0-D85499"
158 "0vxlr35srvbvihlgrxq15v6dylp90vgi0qahj22j01jgqmdasjkm"))))
159 (patch-flags '("-p1"))))
160 (arguments
161 (substitute-keyword-arguments (package-arguments llvm-9)
162 ((#:configure-flags flags)
163 `(list ;; Taken from NixOS. Only way I could get libLLVM-6.0.so
164 "-DCMAKE_BUILD_TYPE=Release"
165
166 ;; Build a native compiler and the NVPTX backend (NVIDIA) since
167 ;; Julia insists on it, nothing more. This reduces build times and
168 ;; disk usage.
169 ,(string-append "-DLLVM_TARGETS_TO_BUILD=" (system->llvm-target))
170 "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=NVPTX"
171
172 "-DLLVM_INSTALL_UTILS=ON"
173 "-DLLVM_BUILD_TESTS=ON"
174 "-DLLVM_ENABLE_FFI=ON"
175 "-DLLVM_ENABLE_RTTI=ON"
176 ;; "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
177 ;; "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}"
178 ;; "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly"
179 "-DLLVM_ENABLE_DUMP=ON"
180 "-DLLVM_LINK_LLVM_DYLIB=ON"))))))
181
182 (define-public libwhich
183 (package
184 (name "libwhich")
185 (version "1.1.0")
186 (source
187 (origin
188 (method git-fetch)
189 (uri (git-reference
190 (url "https://github.com/vtjnash/libwhich")
191 ;; fixes linux-vdso.so related tests
192 (commit "87cffe10080c98e7b5786c5166e420bf1ada1d41")))
193 (file-name (string-append name "-" version "-checkout"))
194 (sha256
195 (base32
196 "1bpa0fcqpa3ai3hm8mz0p13bf76fsq53wsfcx5qw302zh22108xr"))))
197 (arguments
198 `(#:make-flags
199 (list (string-append "CC=" ,(cc-for-target)))
200 #:phases
201 (modify-phases %standard-phases
202 (delete 'configure)
203 (add-before 'check 'set-ld-library-path
204 (lambda* (#:key native-inputs inputs #:allow-other-keys)
205 (setenv "LD_LIBRARY_PATH"
206 (string-append (assoc-ref (or native-inputs inputs) "zlib")
207 "/lib"))))
208 (replace 'install
209 (lambda* (#:key outputs #:allow-other-keys)
210 (let ((out (assoc-ref outputs "out")))
211 (install-file "libwhich" (string-append out "/bin")))
212 #t)))))
213 (native-inputs
214 ;; used for tests
215 `(("zlib" ,zlib)))
216 (build-system gnu-build-system)
217 (home-page "https://github.com/vtjnash/libwhich")
218 (synopsis "Like @code{which}, for dynamic libraries")
219 (description "@code{libwhich} is like @code{which}, but for dynamic
220 libraries. It is also a bit like @code{ldd} and @code{otool -L}.")
221 (license license:expat)))
222
223 (define-public julia
224 (package
225 (name "julia")
226 (version "1.5.3")
227 (source (origin
228 (method url-fetch)
229 (uri (string-append
230 "https://github.com/JuliaLang/julia/releases/download/v"
231 version "/julia-" version ".tar.gz"))
232 (sha256
233 (base32
234 "1zmim82x9kkdcgn0cdi01hmzi59zbszy1sqlygb86xq4hc1n66dy"))
235 (patches
236 (search-patches "julia-SOURCE_DATE_EPOCH-mtime.patch"))))
237 (build-system gnu-build-system)
238 (arguments
239 `(#:test-target "test"
240 #:modules ((ice-9 match)
241 (guix build gnu-build-system)
242 (guix build utils))
243
244 ;; Do not strip binaries to keep support for full backtraces.
245 ;; See https://github.com/JuliaLang/julia/issues/17831
246 #:strip-binaries? #f
247
248 ;; The DSOs use $ORIGIN to refer to each other, but (guix build
249 ;; gremlin) doesn't support it yet, so skip this phase.
250 #:validate-runpath? #f
251
252 #:phases
253 (modify-phases %standard-phases
254 (delete 'configure)
255 (add-after 'unpack 'prepare-deps
256 (lambda* (#:key inputs #:allow-other-keys)
257 ;; needed by libwhich
258 (setenv "LD_LIBRARY_PATH"
259 (string-join (map (lambda (pkg)
260 (string-append (assoc-ref inputs pkg)
261 "/lib"))
262 '("arpack-ng" "curl" "dsfmt"
263 "gmp" "lapack"
264 "libssh2" "libgit2"
265 "mbedtls" "mpfr"
266 "openblas" "openlibm" "pcre2"
267 "suitesparse"))
268 ":"))
269 #t))
270 ;; FIXME: Building the documentation requires Julia packages that
271 ;; would be downloaded from the Internet. We should build them in a
272 ;; separate build phase.
273 (add-after 'unpack 'disable-documentation
274 (lambda _
275 (substitute* "Makefile"
276 (("(install: .*) \\$\\(BUILDROOT\\)/doc/_build/html/en/index.html" _ line)
277 (string-append line "\n"))
278 (("src ui doc deps")
279 "src ui deps"))
280 #t))
281 (add-after 'unpack 'use-system-libwhich
282 (lambda* (#:key inputs #:allow-other-keys)
283 ;; don't build it
284 (substitute* "deps/Makefile"
285 (("DEP_LIBS \\+= libwhich") ""))
286 ;; call our version
287 (substitute* "base/Makefile"
288 (("\\$\\$\\(build_depsbindir\\)/libwhich")
289 (string-append (assoc-ref inputs "libwhich") "/bin/libwhich")))
290 #t))
291 (add-before 'check 'set-home
292 ;; Some tests require a home directory to be set.
293 (lambda _ (setenv "HOME" "/tmp") #t))
294 (add-before 'build 'fix-include-and-link-paths
295 (lambda* (#:key inputs #:allow-other-keys)
296 ;; LIBUTF8PROC is a linker flag, not a build target. It is
297 ;; included in the LIBFILES_* variable which is used as a
298 ;; collection of build targets and a list of libraries to link
299 ;; against.
300 (substitute* "src/flisp/Makefile"
301 (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\)\\$\\(EXE\\): \\$\\(OBJS\\) \\$\\(LIBFILES_release\\)")
302 "$(BUILDDIR)/$(EXENAME)$(EXE): $(OBJS) $(LLT_release)")
303 (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\)-debug$(EXE): \\$\\(DOBJS\\) \\$\\(LIBFILES_debug\\)")
304 "$(BUILDDIR)/$(EXENAME)-debug\\$\\(EXE\\): $(DOBJS) $(LLT_debug)"))
305
306 ;; The REPL must be linked with libuv.
307 (substitute* "ui/Makefile"
308 (("JLDFLAGS \\+= ")
309 (string-append "JLDFLAGS += "
310 (assoc-ref %build-inputs "libuv")
311 "/lib/libuv.so ")))
312
313 (substitute* "base/Makefile"
314 (("\\$\\(build_includedir\\)/uv/errno.h")
315 (string-append (assoc-ref inputs "libuv")
316 "/include/uv/errno.h")))
317 #t))
318 (add-before 'build 'replace-default-shell
319 (lambda _
320 (substitute* "base/client.jl"
321 (("/bin/sh") (which "sh")))
322 #t))
323 (add-before 'build 'fix-precompile
324 (lambda _
325 (substitute* "base/loading.jl"
326 (("something(Base.active_project(), \"\")") "\"\""))
327 #t))
328 (add-before 'check 'disable-broken-tests
329 (lambda _
330 (substitute* "test/choosetests.jl"
331 (("tests = testnames")
332 ;; Those failings are not deterministic. They depends on the
333 ;; running order. I think it depends on the number of
334 ;; runners, disabling it for now
335 ;; https://github.com/JuliaLang/julia/issues/34330
336 "tests = filter(e->!in(e,[\"backtrace\",\"exceptions\",\"precompile\",
337 \"client\",\"stacktraces\"]),
338 testnames)"))
339 ;; Marking the test as broken as it's a known bug:
340 ;; https://github.com/JuliaLang/julia/issues/32377
341 (substitute* "stdlib/REPL/test/replcompletions.jl"
342 (("@test count") "@test_broken count"))
343 ;; Dates has a similar bug:
344 ;; https://github.com/JuliaLang/julia/issues/34655
345 (substitute* "stdlib/Dates/test/io.jl"
346 (("\"Dates.Date") "\"Date")
347 (("\"Dates.Time") "\"Time"))
348 ;; Upstream bug I found when packaging
349 ;; https://github.com/JuliaLang/julia/issues/35785
350 (substitute* "test/file.jl"
351 (("@test dirname\\(t\\) == d") "@test_broken dirname(t) == d"))
352 ;; Deprecation test fails with --depwarn=no
353 ;; https://github.com/JuliaLang/julia/issues/37673
354 (substitute* "test/Makefile"
355 (("./runtests.jl") "--depwarn=error ./runtests.jl"))
356 #t))
357 (add-after 'install 'make-wrapper
358 (lambda* (#:key inputs outputs #:allow-other-keys)
359 (let* ((out (assoc-ref outputs "out"))
360 (bin (string-append out "/bin"))
361 (program "julia"))
362 (with-directory-excursion bin
363 (wrap-program program
364 `("JULIA_LOAD_PATH" ":" prefix
365 ("" "$JULIA_LOAD_PATH")))
366 (wrap-program program
367 `("JULIA_DEPOT_PATH" ":" prefix
368 ("" "$JULIA_DEPOT_PATH"))))
369 #t))))
370 #:make-flags
371 (list
372 (string-append "prefix=" (assoc-ref %outputs "out"))
373
374 ;; Passing the MARCH flag is necessary to build binary substitutes for
375 ;; the supported architectures.
376 ,(match (or (%current-target-system)
377 (%current-system))
378 ("x86_64-linux" "MARCH=x86-64")
379 ("i686-linux" "MARCH=pentium4")
380 ("aarch64-linux" "MARCH=armv8-a")
381 ;; Prevent errors when querying this package on unsupported
382 ;; platforms, e.g. when running "guix package --search="
383 (_ "MARCH=UNSUPPORTED"))
384
385 "CONFIG_SHELL=bash" ;needed to build bundled libraries
386 ;; list of "USE_SYSTEM_*" is here:
387 ;; https://github.com/JuliaLang/julia/blob/v1.3.1/Make.inc
388 "USE_SYSTEM_DSFMT=1"
389 "USE_SYSTEM_P7ZIP=1"
390 "USE_SYSTEM_LAPACK=1"
391 "USE_SYSTEM_BLAS=1"
392 "USE_BLAS64=0" ;needed when USE_SYSTEM_BLAS=1
393 "LIBBLAS=-lopenblas"
394 "LIBBLASNAME=libopenblas"
395
396 "USE_SYSTEM_SUITESPARSE=1"
397 (string-append "SUITESPARSE_INC=-I "
398 (assoc-ref %build-inputs "suitesparse")
399 "/include")
400 "USE_GPL_LIBS=1" ;proudly
401 "USE_SYSTEM_UTF8PROC=1"
402 (string-append "UTF8PROC_INC="
403 (assoc-ref %build-inputs "utf8proc")
404 "/include")
405 "USE_SYSTEM_LLVM=1"
406 "LLVM_VER=9.0.1"
407
408 "USE_LLVM_SHLIB=1"
409 "USE_SYSTEM_LIBUNWIND=1"
410 "USE_SYSTEM_LIBUV=1"
411 (string-append "LIBUV="
412 (assoc-ref %build-inputs "libuv")
413 "/lib/libuv.so")
414 (string-append "LIBUV_INC="
415 (assoc-ref %build-inputs "libuv")
416 "/include")
417 "USE_SYSTEM_PATCHELF=1"
418 "USE_SYSTEM_PCRE=1"
419 "USE_SYSTEM_OPENLIBM=1"
420 "USE_SYSTEM_MBEDTLS=1"
421 "USE_SYSTEM_LIBSSH2=1"
422 "USE_SYSTEM_GMP=1"
423 "USE_SYSTEM_MPFR=1"
424 "USE_SYSTEM_ARPACK=1"
425 "USE_SYSTEM_LIBGIT2=1"
426 "USE_SYSTEM_ZLIB=1")))
427 (inputs
428 `(("llvm" ,llvm-julia)
429 ("p7zip" ,p7zip)
430 ;; The bundled version is 3.3.0 so stick to that version. With other
431 ;; versions, we get test failures in 'linalg/arnoldi' as described in
432 ;; <https://bugs.gnu.org/30282>.
433 ("arpack-ng" ,arpack-ng-3.3.0)
434
435 ("coreutils" ,coreutils) ;for bindings to "mkdir" and the like
436 ("lapack" ,lapack)
437 ("openblas" ,openblas) ;Julia does not build with Atlas
438 ("libunwind" ,libunwind-julia)
439 ("openlibm" ,openlibm)
440 ("mbedtls" ,mbedtls-apache)
441 ("curl" ,curl)
442 ("libgit2" ,libgit2-0.28)
443 ("libssh2" ,libssh2)
444 ("fortran" ,gfortran)
445 ("libuv" ,libuv-julia)
446 ("pcre2" ,pcre2)
447 ("utf8proc" ,utf8proc)
448 ("mpfr" ,mpfr)
449 ("wget" ,wget)
450 ("which" ,which)
451 ("zlib" ,zlib)
452 ("gmp" ,gmp)
453 ("suitesparse" ,suitesparse)
454 ;; Find dependencies versions here:
455 ;; https://raw.githubusercontent.com/JuliaLang/julia/v1.3.0/deps/Versions.make
456 ("libwhich" ,libwhich)
457 ("dsfmt" ,dsfmt)))
458 (native-inputs
459 `(("openssl" ,openssl)
460 ("perl" ,perl)
461 ("patchelf" ,patchelf)
462 ("pkg-config" ,pkg-config)
463 ("python" ,python-2)))
464 (native-search-paths
465 (list (search-path-specification
466 (variable "JULIA_LOAD_PATH")
467 (files (list "share/julia/packages/")))
468 (search-path-specification
469 (variable "JULIA_DEPOT_PATH")
470 (files (list "share/julia/")))))
471 ;; Julia is not officially released for ARM and MIPS.
472 ;; See https://github.com/JuliaLang/julia/issues/10639
473 (supported-systems '("i686-linux" "x86_64-linux" "aarch64-linux"))
474 (home-page "https://julialang.org/")
475 (synopsis "High-performance dynamic language for technical computing")
476 (description
477 "Julia is a high-level, high-performance dynamic programming language for
478 technical computing, with syntax that is familiar to users of other technical
479 computing environments. It provides a sophisticated compiler, distributed
480 parallel execution, numerical accuracy, and an extensive mathematical function
481 library.")
482 (license license:expat)))