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>
8 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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))
55 (let ((commit "1fcc6d66f9df74189c74d3d390f02202bb7db953")
57 ;; When upgrading Julia, also upgrade this. Get the commit from
58 ;; https://github.com/JuliaLang/julia/blob/v1.5.2/deps/libuv.version
62 (version (git-version "2.0.0" revision commit))
66 (url "https://github.com/JuliaLang/libuv")
68 (file-name (string-append name "-" version "-checkout"))
71 "040l7f1hk7xyza11sry5cj4fhw05na949865axqqhxnifdvnmfji"))))
72 (build-system gnu-build-system)
74 (substitute-keyword-arguments (package-arguments libuv)
76 `(modify-phases ,phases
78 (home-page "https://github.com/JuliaLang/libuv"))))
80 (define libunwind-julia
81 ;; The Julia projects requires their patched version.
82 ;; Get from https://github.com/JuliaLang/julia/tree/master/deps/patches
85 (name "libunwind-julia")
90 (uri (string-append "mirror://savannah/libunwind/libunwind-"
94 "1y0l08k6ak1mqbfj6accf9s5686kljwgsl4vcqpxzk5n74wpm6a3"))
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/")))
103 (define (julia-patch-url version name)
104 (string-append "https://raw.githubusercontent.com/JuliaLang/julia/v" version
105 "/deps/patches/" name ".patch"))
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))
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
127 (julia-patch name hash)))
129 '("llvm-D27629-AArch64-large_model_6.0.1"
130 "1qrshmlqvnasdyc158vfn3hnbigqph3lsq7acb9w8lwkpnnm2j4z")
131 '("llvm8-D34078-vectorize-fdiv"
132 "19spqc3xsazn1xs9gpcgv9ldadfkv49rmc5khl7sf1dlmhgi4602")
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")
154 "08a43hyg7yyqjq2vmfsmppf34xcz60wq6y9zw5fdyhw2h1mcnmns")
155 '("llvm-julia-tsan-custom-as"
156 "0awh40kf6lm4wn1nsjd1bmhfwq7rqj811szanp2xkpspykw9hg9s")
158 "0vxlr35srvbvihlgrxq15v6dylp90vgi0qahj22j01jgqmdasjkm"))))
159 (patch-flags '("-p1"))))
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"
166 ;; Build a native compiler and the NVPTX backend (NVIDIA) since
167 ;; Julia insists on it, nothing more. This reduces build times and
169 ,(string-append "-DLLVM_TARGETS_TO_BUILD=" (system->llvm-target))
170 "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=NVPTX"
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"))))))
182 (define-public libwhich
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"))
196 "1bpa0fcqpa3ai3hm8mz0p13bf76fsq53wsfcx5qw302zh22108xr"))))
199 (list (string-append "CC=" ,(cc-for-target)))
201 (modify-phases %standard-phases
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")
209 (lambda* (#:key outputs #:allow-other-keys)
210 (let ((out (assoc-ref outputs "out")))
211 (install-file "libwhich" (string-append out "/bin")))
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)))
230 "https://github.com/JuliaLang/julia/releases/download/v"
231 version "/julia-" version ".tar.gz"))
234 "1zmim82x9kkdcgn0cdi01hmzi59zbszy1sqlygb86xq4hc1n66dy"))
236 (search-patches "julia-SOURCE_DATE_EPOCH-mtime.patch"))))
237 (build-system gnu-build-system)
239 `(#:test-target "test"
240 #:modules ((ice-9 match)
241 (guix build gnu-build-system)
244 ;; Do not strip binaries to keep support for full backtraces.
245 ;; See https://github.com/JuliaLang/julia/issues/17831
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
253 (modify-phases %standard-phases
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)
262 '("arpack-ng" "curl" "dsfmt"
266 "openblas" "openlibm" "pcre2"
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
275 (substitute* "Makefile"
276 (("(install: .*) \\$\\(BUILDROOT\\)/doc/_build/html/en/index.html" _ line)
277 (string-append line "\n"))
281 (add-after 'unpack 'use-system-libwhich
282 (lambda* (#:key inputs #:allow-other-keys)
284 (substitute* "deps/Makefile"
285 (("DEP_LIBS \\+= libwhich") ""))
287 (substitute* "base/Makefile"
288 (("\\$\\$\\(build_depsbindir\\)/libwhich")
289 (string-append (assoc-ref inputs "libwhich") "/bin/libwhich")))
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
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)"))
306 ;; The REPL must be linked with libuv.
307 (substitute* "ui/Makefile"
309 (string-append "JLDFLAGS += "
310 (assoc-ref %build-inputs "libuv")
313 (substitute* "base/Makefile"
314 (("\\$\\(build_includedir\\)/uv/errno.h")
315 (string-append (assoc-ref inputs "libuv")
316 "/include/uv/errno.h")))
318 (add-before 'build 'replace-default-shell
320 (substitute* "base/client.jl"
321 (("/bin/sh") (which "sh")))
323 (add-before 'build 'fix-precompile
325 (substitute* "base/loading.jl"
326 (("something(Base.active_project(), \"\")") "\"\""))
328 (add-before 'check 'disable-broken-tests
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\"]),
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"))
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"))
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"))))
372 (string-append "prefix=" (assoc-ref %outputs "out"))
374 ;; Passing the MARCH flag is necessary to build binary substitutes for
375 ;; the supported architectures.
376 ,(match (or (%current-target-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"))
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
390 "USE_SYSTEM_LAPACK=1"
392 "USE_BLAS64=0" ;needed when USE_SYSTEM_BLAS=1
394 "LIBBLASNAME=libopenblas"
396 "USE_SYSTEM_SUITESPARSE=1"
397 (string-append "SUITESPARSE_INC=-I "
398 (assoc-ref %build-inputs "suitesparse")
400 "USE_GPL_LIBS=1" ;proudly
401 "USE_SYSTEM_UTF8PROC=1"
402 (string-append "UTF8PROC_INC="
403 (assoc-ref %build-inputs "utf8proc")
409 "USE_SYSTEM_LIBUNWIND=1"
411 (string-append "LIBUV="
412 (assoc-ref %build-inputs "libuv")
414 (string-append "LIBUV_INC="
415 (assoc-ref %build-inputs "libuv")
417 "USE_SYSTEM_PATCHELF=1"
419 "USE_SYSTEM_OPENLIBM=1"
420 "USE_SYSTEM_MBEDTLS=1"
421 "USE_SYSTEM_LIBSSH2=1"
424 "USE_SYSTEM_ARPACK=1"
425 "USE_SYSTEM_LIBGIT2=1"
426 "USE_SYSTEM_ZLIB=1")))
428 `(("llvm" ,llvm-julia)
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)
435 ("coreutils" ,coreutils) ;for bindings to "mkdir" and the like
437 ("openblas" ,openblas) ;Julia does not build with Atlas
438 ("libunwind" ,libunwind-julia)
439 ("openlibm" ,openlibm)
440 ("mbedtls" ,mbedtls-apache)
442 ("libgit2" ,libgit2-0.28)
444 ("fortran" ,gfortran)
445 ("libuv" ,libuv-julia)
447 ("utf8proc" ,utf8proc)
453 ("suitesparse" ,suitesparse)
454 ;; Find dependencies versions here:
455 ;; https://raw.githubusercontent.com/JuliaLang/julia/v1.3.0/deps/Versions.make
456 ("libwhich" ,libwhich)
459 `(("openssl" ,openssl)
461 ("patchelf" ,patchelf)
462 ("pkg-config" ,pkg-config)
463 ("python" ,python-2)))
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")
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
482 (license license:expat)))