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