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>
6 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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))
53 (let ((commit "35b1504507a7a4168caae3d78db54d1121b121e1")
55 ;; When upgrading Julia, also upgrade this. Get the commit from
56 ;; https://github.com/JuliaLang/julia/blob/v1.3.1/deps/libuv.version
60 (version (git-version "2.0.0" revision commit))
64 (url "https://github.com/JuliaLang/libuv.git")
66 (file-name (string-append name "-" version "-checkout"))
69 "0dn3v6fdp1z382pqg3nhjzk60l61ky9b65mfgaj29fv2da95rwjs"))))
70 (build-system gnu-build-system)
72 (substitute-keyword-arguments (package-arguments libuv)
74 `(modify-phases ,phases
76 (home-page "https://github.com/JuliaLang/libuv"))))
78 (define libunwind-julia
79 ;; The Julia projects requires their patched version.
80 ;; Get from https://github.com/JuliaLang/julia/tree/master/deps/patches
83 (name "libunwind-julia")
88 (uri (string-append "mirror://savannah/libunwind/libunwind-"
92 "1y0l08k6ak1mqbfj6accf9s5686kljwgsl4vcqpxzk5n74wpm6a3"))
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/")))
101 (define (julia-patch-url version name)
102 (string-append "https://raw.githubusercontent.com/JuliaLang/julia/v" version
103 "/deps/patches/" name))
105 (define (julia-patch name sha)
106 (let ((version "1.3.1"))
107 (origin (method url-fetch)
108 (uri (julia-patch-url version name))
109 (sha256 (base32 sha))
117 (inherit (package-source llvm-6))
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
125 (julia-patch name hash)))
128 "1336q4vqayr94wdcnlmcxh90mjdh34dzw9x2cbiqjnx9b1j8fxyb")
129 '("llvm-6.0-DISABLE_ABI_CHECKS"
130 "014fawd1ba7yckalypfld22zgic87x9nx3cim42zrwygywd36pyg")
131 '("llvm-6.0-NVPTX-addrspaces"
132 "1qdi2zmrjsrj0h84zv2vyly2hjcn4f67mfy0s1q353g4v4jkscqc")
133 '("llvm-6.0.0_D27296-libssp"
134 "0s5hi2r1j63i8m6ig1346crx2aiv9f7rgb3mg80kw1wx5y7pdpfh")
135 '("llvm-D27629-AArch64-large_model_6.0.1"
136 "1qrshmlqvnasdyc158vfn3hnbigqph3lsq7acb9w8lwkpnnm2j4z")
137 '("llvm-D34078-vectorize-fdiv"
138 "1696hg84a0jxcnggvqsc2cdp271hf9a44p4qsd078qm1mfawkaay")
139 '("llvm-D42262-jumpthreading-not-i1"
140 "1c8w210gwidbnkkw8anp17dk5pnxws2fl3mb2qxh7y9wzfpixgaq")
141 '("llvm-D44892-Perf-integration"
142 "0r37jd0ssh2k1pndkfd5blgpg9z90im4vlzprhb0n0wwz45g4b05")
144 "1miqgswdc0qvbaf4571c2xkxyp9ais06b1bcpa83sq22vr4hbsfb")
145 '("llvm-D49832-SCEVPred"
146 "0v5c88hgqj6dymv3j86ca5mhpqab5fbnrvjiw1nvnrnya9l4dlbn")
147 '("llvm-D50010-VNCoercion-ni"
148 "0iblb3q1xixwrb12jpb89h3ywmqmzdp6aqp416j4ncwakyjhhfkp")
149 '("llvm-D50167-scev-umin"
150 "1f2rakcnnyhr7w10k7gqg0k0491pyvx5ijplivw557f714ys3q6v")
151 '("llvm-OProfile-line-num"
152 "1jvbbmwyags0xfwamb13qrf3rgcz9i1r03m9lava7swag8xb78c7")
153 '("llvm-PPC-addrspaces"
154 "1f23nhsxh2s3jskbgs7da9nwg3s1hrkbk5aahl08x41wi3mny01p")
155 '("llvm-rL323946-LSRTy"
156 "10cz3vy1yw0w643z7xx021wa4kymx9fcm3bjg61s6vzdqd6d9fns")
157 '("llvm-rL326967-aligned-load"
158 "04jxnv32yj5x17hqhi8g2p8rhgp38gmjzr871w7z8s44pq10v9v4")
160 "15ah49gbsll23z28kpyahi5vl0fh3fkxcgd1zmxxdcl96s3x8bnq"))))))
162 (substitute-keyword-arguments (package-arguments llvm-6)
163 ((#:configure-flags flags)
164 `(list ;; Taken from NixOS. Only way I could get libLLVM-6.0.so
165 "-DCMAKE_BUILD_TYPE=Release"
167 ;; Build a native compiler and the NVPTX backend (NVIDIA) since
168 ;; Julia insists on it, nothing more. This reduces build times and
170 ,(string-append "-DLLVM_TARGETS_TO_BUILD=" (system->llvm-target))
171 "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=NVPTX"
173 "-DLLVM_INSTALL_UTILS=ON"
174 "-DLLVM_BUILD_TESTS=ON"
175 "-DLLVM_ENABLE_FFI=ON"
176 "-DLLVM_ENABLE_RTTI=ON"
177 ;; "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
178 ;; "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}"
179 ;; "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly"
180 "-DLLVM_ENABLE_DUMP=ON"
181 "-DLLVM_LINK_LLVM_DYLIB=ON"))))))
190 "https://github.com/JuliaLang/julia/releases/download/v"
191 version "/julia-" version ".tar.gz"))
194 "1nwkmr9j55g1zkxdchnid1h022s0is52vx23niksshgvh793g41x"))
196 (search-patches "julia-SOURCE_DATE_EPOCH-mtime.patch"))))
197 (build-system gnu-build-system)
199 `(#:test-target "test"
200 #:modules ((ice-9 match)
201 (guix build gnu-build-system)
204 ;; Do not strip binaries to keep support for full backtraces.
205 ;; See https://github.com/JuliaLang/julia/issues/17831
208 ;; The DSOs use $ORIGIN to refer to each other, but (guix build
209 ;; gremlin) doesn't support it yet, so skip this phase.
210 #:validate-runpath? #f
213 (modify-phases %standard-phases
215 (add-after 'unpack 'prepare-deps
216 (lambda* (#:key inputs #:allow-other-keys)
217 (mkdir "deps/srccache")
218 ;; no USE_SYSTEM_{OBJCONV/LIBWHICH} option
219 (copy-file (assoc-ref inputs "objconv")
220 "deps/srccache/objconv.zip")
221 (copy-file (assoc-ref inputs "libwhich")
222 (string-append "deps/srccache/libwhich-"
223 "81e9723c0273d78493dc8c8ed570f68d9ce7e89e"
226 ;; needed by libwhich
227 (setenv "LD_LIBRARY_PATH"
228 (string-join (map (lambda (pkg)
229 (string-append (assoc-ref inputs pkg)
231 '("arpack-ng" "curl" "dsfmt"
235 "openblas" "openlibm" "pcre2"
239 ;; FIXME: Building the documentation requires Julia packages that
240 ;; would be downloaded from the Internet. We should build them in a
241 ;; separate build phase.
242 (add-after 'unpack 'disable-documentation
244 (substitute* "Makefile"
245 (("(install: .*) \\$\\(BUILDROOT\\)/doc/_build/html/en/index.html" _ line)
246 (string-append line "\n"))
250 (add-before 'check 'set-home
251 ;; Some tests require a home directory to be set.
252 (lambda _ (setenv "HOME" "/tmp") #t))
253 (add-after 'unpack 'hardcode-soname-map
254 ;; ./src/runtime_ccall.cpp creates a map from library names to paths
255 ;; using the output of "/sbin/ldconfig -p". Since ldconfig is not
256 ;; used in Guix, we patch runtime_ccall.cpp to contain a static map.
257 (lambda* (#:key inputs #:allow-other-keys)
258 (substitute* "base/math.jl"
259 (("const libm = Base.libm_name")
260 (string-append "const libm = \""
261 (assoc-ref inputs "openlibm")
262 "/lib/libopenlibm.so"
265 (add-before 'build 'fix-include-and-link-paths
266 (lambda* (#:key inputs #:allow-other-keys)
267 ;; LIBUTF8PROC is a linker flag, not a build target. It is
268 ;; included in the LIBFILES_* variable which is used as a
269 ;; collection of build targets and a list of libraries to link
271 (substitute* "src/flisp/Makefile"
272 (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\)\\$\\(EXE\\): \\$\\(OBJS\\) \\$\\(LIBFILES_release\\)")
273 "$(BUILDDIR)/$(EXENAME)$(EXE): $(OBJS) $(LLT_release)")
274 (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\)-debug$(EXE): \\$\\(DOBJS\\) \\$\\(LIBFILES_debug\\)")
275 "$(BUILDDIR)/$(EXENAME)-debug\\$\\(EXE\\): $(DOBJS) $(LLT_debug)"))
277 ;; The REPL must be linked with libuv.
278 (substitute* "ui/Makefile"
280 (string-append "JLDFLAGS += "
281 (assoc-ref %build-inputs "libuv")
284 (substitute* "base/Makefile"
285 (("\\$\\(build_includedir\\)/uv/errno.h")
286 (string-append (assoc-ref inputs "libuv")
287 "/include/uv/errno.h")))
289 (add-before 'build 'replace-default-shell
291 (substitute* "base/client.jl"
292 (("/bin/sh") (which "sh")))
294 (add-before 'build 'fix-precompile
296 (substitute* "base/loading.jl"
297 (("something(Base.active_project(), \"\")") "\"\""))
299 (add-before 'check 'disable-broken-tests
301 (substitute* "test/choosetests.jl"
302 (("tests = testnames")
303 ;; Those failings are not deterministic. They depends on the
304 ;; running order. I think it depends on the number of
305 ;; runners, disabling it for now
306 ;; https://github.com/JuliaLang/julia/issues/34330
307 "tests = filter(e->!in(e,[\"backtrace\",\"exceptions\",
308 \"stress\",\"precompile\",
309 \"client\",\"stacktraces\"]),
311 ;; When HOME is not set, julia calls uv_os_homedir, which in
312 ;; turns call getpwuid_r. Add the HOME env variable to the
313 ;; external julia call to fix this
314 (substitute* "test/cmdlineargs.jl"
315 (("\"JULIA_PROJECT\"") "\"HOME\"=>\"/tmp\", \"JULIA_PROJECT\""))
316 ;; Marking the test as broken as it's a known bug:
317 ;; https://github.com/JuliaLang/julia/issues/32377
318 (substitute* "stdlib/REPL/test/replcompletions.jl"
319 (("@test count") "@test_broken count"))
321 (add-after 'install 'make-wrapper
322 (lambda* (#:key inputs outputs #:allow-other-keys)
323 (let* ((out (assoc-ref outputs "out"))
324 (bin (string-append out "/bin"))
326 (with-directory-excursion bin
327 (wrap-program program
328 `("JULIA_LOAD_PATH" ":" prefix
329 ("" "$JULIA_LOAD_PATH")))
330 (wrap-program program
331 `("JULIA_DEPOT_PATH" ":" prefix
332 ("" "$JULIA_DEPOT_PATH"))))
336 (string-append "prefix=" (assoc-ref %outputs "out"))
337 (string-append "PREFIX=" (assoc-ref %outputs "out"))
339 ;; Passing the MARCH flag is necessary to build binary substitutes for
340 ;; the supported architectures.
341 ,(match (or (%current-target-system)
343 ("x86_64-linux" "MARCH=x86-64")
344 ("i686-linux" "MARCH=pentium4")
345 ("aarch64-linux" "MARCH=armv8-a")
346 ;; Prevent errors when querying this package on unsupported
347 ;; platforms, e.g. when running "guix package --search="
348 (_ "MARCH=UNSUPPORTED"))
350 "CONFIG_SHELL=bash" ;needed to build bundled libraries
351 ;; list of "USE_SYSTEM_*" is here:
352 ;; https://github.com/JuliaLang/julia/blob/v1.3.1/Make.inc
355 "USE_SYSTEM_LAPACK=1"
357 "USE_BLAS64=0" ;needed when USE_SYSTEM_BLAS=1
359 "LIBBLASNAME=libopenblas"
361 "USE_SYSTEM_SUITESPARSE=1"
362 (string-append "SUITESPARSE_INC=-I "
363 (assoc-ref %build-inputs "suitesparse")
365 "USE_GPL_LIBS=1" ;proudly
366 "USE_SYSTEM_UTF8PROC=1"
367 (string-append "UTF8PROC_INC="
368 (assoc-ref %build-inputs "utf8proc")
374 "USE_SYSTEM_LIBUNWIND=1"
376 (string-append "LIBUV="
377 (assoc-ref %build-inputs "libuv")
379 (string-append "LIBUV_INC="
380 (assoc-ref %build-inputs "libuv")
382 "USE_SYSTEM_PATCHELF=1"
384 "USE_SYSTEM_OPENLIBM=1"
388 "USE_SYSTEM_ARPACK=1"
389 "USE_SYSTEM_LIBGIT2=1"
390 (string-append "LIBUV="
391 (assoc-ref %build-inputs "libuv")
393 (string-append "LIBUV_INC="
394 (assoc-ref %build-inputs "libuv")
396 "USE_SYSTEM_ZLIB=1")))
398 `(("llvm" ,llvm-julia)
400 ;; The bundled version is 3.3.0 so stick to that version. With other
401 ;; versions, we get test failures in 'linalg/arnoldi' as described in
402 ;; <https://bugs.gnu.org/30282>.
403 ("arpack-ng" ,arpack-ng-3.3.0)
405 ("coreutils" ,coreutils) ;for bindings to "mkdir" and the like
407 ("openblas" ,openblas) ;Julia does not build with Atlas
408 ("libunwind" ,libunwind-julia)
409 ("openlibm" ,openlibm)
410 ("mbedtls" ,mbedtls-apache)
414 ("fortran" ,gfortran)
415 ("libuv" ,libuv-julia)
417 ("utf8proc" ,utf8proc)
423 ("suitesparse" ,suitesparse)
424 ;; Find dependencies versions here:
425 ;; https://raw.githubusercontent.com/JuliaLang/julia/v1.3.0/deps/Versions.make
429 ;; No versioned URL, see <https://www.agner.org/optimize/> for updates.
430 (uri "https://www.agner.org/optimize/objconv.zip")
431 (file-name "objconv-2018-10-07.zip")
434 "0wp6ld9vk11f4nnkn56627zmlv9k5vafi99qa3yyn1pgcd61zcfs"))))
436 ,(let ((commit "81e9723c0273d78493dc8c8ed570f68d9ce7e89e"))
438 ;; Note: We use a /tarball URL, but that's because Julia's build
439 ;; system checks the hash of that tarball; thus we can't use
443 "https://api.github.com/repos/vtjnash/libwhich/tarball/"
445 (file-name (string-append "libwhich-" (string-take commit 7)
449 "1p7zg31kpmpbmh1znrk1xrbd074agx13b9q4dcw8n2zrwwdlbz3b")))))
452 `(("openssl" ,openssl)
454 ("patchelf" ,patchelf)
455 ("pkg-config" ,pkg-config)
456 ("python" ,python-2)))
458 (list (search-path-specification
459 (variable "JULIA_LOAD_PATH")
460 (files (list "share/julia/packages/")))
461 (search-path-specification
462 (variable "JULIA_DEPOT_PATH")
463 (files (list "share/julia/")))))
464 ;; Julia is not officially released for ARM and MIPS.
465 ;; See https://github.com/JuliaLang/julia/issues/10639
466 (supported-systems '("i686-linux" "x86_64-linux" "aarch64-linux"))
467 (home-page "https://julialang.org/")
468 (synopsis "High-performance dynamic language for technical computing")
470 "Julia is a high-level, high-performance dynamic programming language for
471 technical computing, with syntax that is familiar to users of other technical
472 computing environments. It provides a sophisticated compiler, distributed
473 parallel execution, numerical accuracy, and an extensive mathematical function
475 (license license:expat)))