gnu: igt-gpu-tools: Don't use NAME in source URI.
[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 Efraim Flashner <efraim@flashner.co.il>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 (define-module (gnu packages julia)
21 #:use-module ((guix licenses) #:prefix license:)
22 #:use-module (guix packages)
23 #:use-module (guix download)
24 #:use-module (guix utils)
25 #:use-module (guix git-download)
26 #:use-module (guix build-system gnu)
27 #:use-module (gnu packages)
28 #:use-module (gnu packages algebra)
29 #:use-module (gnu packages base)
30 #:use-module (gnu packages compression)
31 #:use-module (gnu packages elf)
32 #:use-module (gnu packages gcc)
33 #:use-module (gnu packages llvm)
34 #:use-module (gnu packages libevent)
35 #:use-module (gnu packages libunwind)
36 #:use-module (gnu packages maths)
37 #:use-module (gnu packages multiprecision) ; mpfr
38 #:use-module (gnu packages pcre)
39 #:use-module (gnu packages perl)
40 #:use-module (gnu packages pkg-config)
41 #:use-module (gnu packages python)
42 #:use-module (gnu packages python-xyz)
43 #:use-module (gnu packages textutils)
44 #:use-module (gnu packages tls)
45 #:use-module (gnu packages version-control)
46 #:use-module (gnu packages wget)
47 #:use-module (ice-9 match))
48
49 (define libuv-julia
50 (let ((commit "52d72a52cc7ccd570929990f010ed16e2ec604c8")
51 (revision "5"))
52 (package (inherit libuv)
53 (name "libuv-julia")
54 (version (string-append "1.9.0-" revision "." (string-take commit 8)))
55 (source (origin
56 (method git-fetch)
57 (uri (git-reference
58 (url "https://github.com/JuliaLang/libuv.git")
59 (commit commit)))
60 (file-name (string-append name "-" version "-checkout"))
61 (sha256
62 (base32
63 "1daxh6ci6q7znxxajr3bm16dd53ragm0d681wf4kzg542qnjq3lh"))))
64 (build-system gnu-build-system)
65 (arguments
66 (substitute-keyword-arguments (package-arguments libuv)
67 ((#:phases phases)
68 `(modify-phases ,phases
69 (delete 'autogen)))))
70 (home-page "https://github.com/JuliaLang/libuv"))))
71
72 (define libunwind-for-julia
73 (package
74 (inherit libunwind)
75 (version "1.1-julia2")
76 (source (origin
77 (method url-fetch)
78 (uri (string-append "https://s3.amazonaws.com/julialang/src/"
79 "libunwind-" version ".tar.gz"))
80 (sha256
81 (base32
82 "0499x7sg2v18a6cry6l8y713cgmic0adnjph8i0xr1db9p7n8qyv"))))))
83
84 (define-public julia
85 (package
86 (name "julia")
87 (version "0.6.0")
88 (source (origin
89 (method url-fetch)
90 (uri (string-append
91 "https://github.com/JuliaLang/julia/releases/download/v"
92 version "/julia-" version ".tar.gz"))
93 (sha256
94 (base32
95 "0rd6lcc9sic10q1j3c6f9qr901i1c4554m93n2sz5b3mh37byqhw"))))
96 (build-system gnu-build-system)
97 (arguments
98 `(#:test-target "test"
99 #:modules ((ice-9 match)
100 (guix build gnu-build-system)
101 (guix build utils))
102
103 ;; Do not strip binaries to keep support for full backtraces.
104 ;; See https://github.com/JuliaLang/julia/issues/17831
105 #:strip-binaries? #f
106
107 ;; The DSOs use $ORIGIN to refer to each other, but (guix build
108 ;; gremlin) doesn't support it yet, so skip this phase.
109 #:validate-runpath? #f
110
111 #:phases
112 (modify-phases %standard-phases
113 (delete 'configure)
114 (add-after 'unpack 'prepare-deps
115 (lambda* (#:key inputs #:allow-other-keys)
116 (mkdir "deps/srccache")
117 (copy-file (assoc-ref inputs "dsfmt")
118 "deps/srccache/dsfmt-2.2.3.tar.gz")
119 (copy-file (assoc-ref inputs "objconv")
120 "deps/srccache/objconv.zip")
121 (copy-file (assoc-ref inputs "suitesparse")
122 "deps/srccache/SuiteSparse-4.4.5.tar.gz")
123 (copy-file (string-append (assoc-ref inputs "virtualenv")
124 "/bin/virtualenv")
125 "julia-env")
126 (copy-file (assoc-ref inputs "unicode-data")
127 "doc/UnicodeData.txt")
128 #t))
129 ;; FIXME: Building the documentation requires Julia packages that
130 ;; would be downloaded from the Internet. We should build them in a
131 ;; separate build phase.
132 (add-after 'unpack 'disable-documentation
133 (lambda _
134 (substitute* "Makefile"
135 (("(install: .*) \\$\\(BUILDROOT\\)/doc/_build/html/en/index.html" _ line)
136 (string-append line "\n"))
137 (("src ui doc deps")
138 "src ui deps"))
139 #t))
140 (add-before 'check 'set-home
141 ;; Some tests require a home directory to be set.
142 (lambda _ (setenv "HOME" "/tmp") #t))
143 (add-after 'unpack 'hardcode-soname-map
144 ;; ./src/runtime_ccall.cpp creates a map from library names to paths
145 ;; using the output of "/sbin/ldconfig -p". Since ldconfig is not
146 ;; used in Guix, we patch runtime_ccall.cpp to contain a static map.
147 (lambda* (#:key inputs #:allow-other-keys)
148 (use-modules (ice-9 match))
149 (substitute* "src/runtime_ccall.cpp"
150 ;; Patch out invocations of '/sbin/ldconfig' to avoid getting
151 ;; error messages about missing '/sbin/ldconfig' on GuixSD.
152 (("popen\\(.*ldconfig.*\\);")
153 "NULL;\n")
154
155 ;; Populate 'sonameMap'.
156 (("jl_read_sonames.*;")
157 (string-join
158 (map (match-lambda
159 ((input libname soname)
160 (string-append
161 "sonameMap[\"" libname "\"] = "
162 "\"" (assoc-ref inputs input) "/lib/" soname "\";")))
163 '(("libc" "libc" "libc.so.6")
164 ("pcre2" "libpcre2-8" "libpcre2-8.so")
165 ("mpfr" "libmpfr" "libmpfr.so")
166 ("openblas" "libblas" "libopenblas.so")
167 ("arpack-ng" "libarpack" "libarpack.so")
168 ("lapack" "liblapack" "liblapack.so")
169 ("libgit2" "libgit2" "libgit2.so")
170 ("gmp" "libgmp" "libgmp.so")
171 ("openlibm" "libopenlibm" "libopenlibm.so")
172 ("openspecfun" "libopenspecfun" "libopenspecfun.so")
173 ("fftw" "libfftw3" "libfftw3_threads.so")
174 ("fftwf" "libfftw3f" "libfftw3f_threads.so"))))))
175 (substitute* "base/fft/FFTW.jl"
176 (("const libfftw = Base.libfftw_name")
177 (string-append "const libfftw = \""
178 (assoc-ref inputs "fftw") "/lib/libfftw3_threads.so"
179 "\""))
180 (("const libfftwf = Base.libfftwf_name")
181 (string-append "const libfftwf = \""
182 (assoc-ref inputs "fftwf") "/lib/libfftw3f_threads.so"
183 "\"")))
184 (substitute* "base/math.jl"
185 (("const libm = Base.libm_name")
186 (string-append "const libm = \""
187 (assoc-ref inputs "openlibm")
188 "/lib/libopenlibm.so"
189 "\""))
190 (("const openspecfun = \"libopenspecfun\"")
191 (string-append "const openspecfun = \""
192 (assoc-ref inputs "openspecfun")
193 "/lib/libopenspecfun.so"
194 "\"")))
195 (substitute* "base/pcre.jl"
196 (("const PCRE_LIB = \"libpcre2-8\"")
197 (string-append "const PCRE_LIB = \""
198 (assoc-ref inputs "pcre2")
199 "/lib/libpcre2-8.so" "\"")))
200 #t))
201 (add-before 'build 'fix-include-and-link-paths
202 (lambda* (#:key inputs #:allow-other-keys)
203 ;; LIBUTF8PROC is a linker flag, not a build target. It is
204 ;; included in the LIBFILES_* variable which is used as a
205 ;; collection of build targets and a list of libraries to link
206 ;; against.
207 (substitute* "src/flisp/Makefile"
208 (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\): \\$\\(OBJS\\) \\$\\(LIBFILES_release\\)")
209 "$(BUILDDIR)/$(EXENAME): $(OBJS) $(LLT_release)")
210 (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\)-debug: \\$\\(DOBJS\\) \\$\\(LIBFILES_debug\\)")
211 "$(BUILDDIR)/$(EXENAME)-debug: $(DOBJS) $(LLT_debug)"))
212
213 ;; The REPL must be linked with libuv.
214 (substitute* "ui/Makefile"
215 (("JLDFLAGS \\+= ")
216 (string-append "JLDFLAGS += "
217 (assoc-ref %build-inputs "libuv")
218 "/lib/libuv.so ")))
219
220 (substitute* "base/Makefile"
221 (("\\$\\(build_includedir\\)/uv-errno.h")
222 (string-append (assoc-ref inputs "libuv")
223 "/include/uv-errno.h")))
224 #t))
225 (add-before 'build 'replace-default-shell
226 (lambda _
227 (substitute* "base/client.jl"
228 (("/bin/sh") (which "sh")))
229 #t))
230 (add-after 'unpack 'hardcode-paths
231 (lambda _
232 (substitute* "base/interactiveutil.jl"
233 (("`which") (string-append "`" (which "which")))
234 (("`wget") (string-append "`" (which "wget"))))
235 #t))
236 (add-before 'check 'disable-broken-tests
237 (lambda _
238 ;; Adjust expected error messages to match what current libgit2
239 ;; provides.
240 (substitute* "test/libgit2.jl"
241 (("Invalid Content-Type") "invalid Content-Type")
242 (("Failed to resolve path") "failed to resolve path"))
243
244 (substitute* "test/choosetests.jl"
245 ;; These tests fail, probably because some of the input
246 ;; binaries have been stripped and thus backtraces don't look
247 ;; as expected.
248 (("\"backtrace\",") "")
249 (("\"compile\",") "")
250 (("\"replutil\",") "")
251 (("\"cmdlineargs\",") "")
252 ;; FIXME: This test fails with the following error:
253 ;; Error in testset file:
254 ;; Test Failed
255 ;; Expression: download("ba\0d", "good")
256 ;; Expected: ArgumentError
257 ;; Thrown: Base.UVError
258 (("\"file\",") ""))
259 #t)))
260 #:make-flags
261 (list
262 (string-append "prefix=" (assoc-ref %outputs "out"))
263
264 ;; Passing the MARCH flag is necessary to build binary substitutes for
265 ;; the supported architectures.
266 ,(match (or (%current-target-system)
267 (%current-system))
268 ("x86_64-linux" "MARCH=x86-64")
269 ("i686-linux" "MARCH=pentium4")
270 ("aarch64-linux" "MARCH=armv8-a")
271 ;; Prevent errors when querying this package on unsupported
272 ;; platforms, e.g. when running "guix package --search="
273 (_ "MARCH=UNSUPPORTED"))
274
275 "CONFIG_SHELL=bash" ;needed to build bundled libraries
276 "USE_SYSTEM_DSFMT=0" ;not packaged for Guix and upstream has no
277 ;build system for a shared library.
278 "USE_SYSTEM_LAPACK=1"
279 "USE_SYSTEM_BLAS=1"
280 "USE_BLAS64=0" ;needed when USE_SYSTEM_BLAS=1
281
282 "USE_SYSTEM_FFTW=1"
283 "LIBFFTWNAME=libfftw3"
284 "LIBFFTWFNAME=libfftw3f"
285
286 ;; TODO: Suitesparse does not install shared libraries, so we cannot
287 ;; use the suitesparse package.
288 ;; "USE_SYSTEM_SUITESPARSE=1"
289 ;; (string-append "SUITESPARSE_INC=-I "
290 ;; (assoc-ref %build-inputs "suitesparse")
291 ;; "/include")
292
293 "USE_GPL_LIBS=1" ;proudly
294 "USE_SYSTEM_UTF8PROC=1"
295 (string-append "UTF8PROC_INC="
296 (assoc-ref %build-inputs "utf8proc")
297 "/include")
298 "USE_SYSTEM_LLVM=1"
299 "USE_LLVM_SHLIB=0" ; FIXME: fails when set to 1
300
301 "USE_SYSTEM_LIBUNWIND=1"
302 "USE_SYSTEM_LIBUV=1"
303 (string-append "LIBUV="
304 (assoc-ref %build-inputs "libuv")
305 "/lib/libuv.so")
306 (string-append "LIBUV_INC="
307 (assoc-ref %build-inputs "libuv")
308 "/include")
309 "USE_SYSTEM_PATCHELF=1"
310 "USE_SYSTEM_PCRE=1"
311 "USE_SYSTEM_OPENLIBM=1"
312 "USE_SYSTEM_GMP=1"
313 "USE_SYSTEM_MPFR=1"
314 "USE_SYSTEM_ARPACK=1"
315 "USE_SYSTEM_LIBGIT2=1"
316 "USE_SYSTEM_OPENSPECFUN=1")))
317 (inputs
318 `(("llvm" ,llvm-3.9.1)
319
320 ;; The bundled version is 3.3.0 so stick to that version. With other
321 ;; versions, we get test failures in 'linalg/arnoldi' as described in
322 ;; <https://bugs.gnu.org/30282>.
323 ("arpack-ng" ,arpack-ng-3.3.0)
324
325 ("coreutils" ,coreutils) ;for bindings to "mkdir" and the like
326 ("lapack" ,lapack)
327 ("openblas" ,openblas) ;Julia does not build with Atlas
328 ("libunwind" ,libunwind-for-julia)
329 ("openlibm" ,openlibm)
330 ("openspecfun" ,openspecfun)
331 ("libgit2" ,libgit2)
332 ("fftw" ,fftw)
333 ("fftwf" ,fftwf)
334 ("fortran" ,gfortran)
335 ("libuv" ,libuv-julia)
336 ("pcre2" ,pcre2)
337 ("utf8proc" ,utf8proc)
338 ("mpfr" ,mpfr)
339 ("wget" ,wget)
340 ("which" ,which)
341 ("zlib" ,zlib)
342 ("gmp" ,gmp)
343 ("virtualenv" ,python2-virtualenv)
344 ;; FIXME: The following inputs are downloaded from upstream to allow us
345 ;; to use the lightweight Julia release tarball. Ideally, these inputs
346 ;; would eventually be replaced with proper Guix packages.
347
348 ;; TODO: run "make -f contrib/repackage_system_suitesparse4.make" to copy static lib
349 ("suitesparse"
350 ,(origin
351 (method url-fetch)
352 (uri "http://faculty.cse.tamu.edu/davis/SuiteSparse/SuiteSparse-4.4.5.tar.gz")
353 (sha256
354 (base32
355 "1jcbxb8jx5wlcixzf6n5dca2rcfx6mlcms1k2rl5gp67ay3bix43"))))
356 ("objconv"
357 ,(origin
358 (method url-fetch)
359 ;; No versioned URL, see <https://www.agner.org/optimize/> for updates.
360 (uri "https://www.agner.org/optimize/objconv.zip")
361 (file-name "objconv-2018-10-07.zip")
362 (sha256
363 (base32
364 "0wp6ld9vk11f4nnkn56627zmlv9k5vafi99qa3yyn1pgcd61zcfs"))))
365 ("dsfmt"
366 ,(origin
367 (method url-fetch)
368 (uri (string-append
369 "http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/"
370 "SFMT/dSFMT-src-2.2.3.tar.gz"))
371 (sha256
372 (base32
373 "03kaqbjbi6viz0n33dk5jlf6ayxqlsq4804n7kwkndiga9s4hd42"))))))
374 (native-inputs
375 `(("openssl" ,openssl)
376 ("perl" ,perl)
377 ("patchelf" ,patchelf)
378 ("pkg-config" ,pkg-config)
379 ("python" ,python-2)
380 ("unicode-data"
381 ,(origin
382 (method url-fetch)
383 (uri "http://www.unicode.org/Public/9.0.0/ucd/UnicodeData.txt")
384 (sha256
385 (base32
386 "13zfannnr6sa6s27ggvcvzmh133ndi38pfyxsssvjmw2s8ac9pv8"))))))
387 ;; Julia is not officially released for ARM and MIPS.
388 ;; See https://github.com/JuliaLang/julia/issues/10639
389 (supported-systems '("i686-linux" "x86_64-linux" "aarch64-linux"))
390 (home-page "https://julialang.org/")
391 (synopsis "High-performance dynamic language for technical computing")
392 (description
393 "Julia is a high-level, high-performance dynamic programming language for
394 technical computing, with syntax that is familiar to users of other technical
395 computing environments. It provides a sophisticated compiler, distributed
396 parallel execution, numerical accuracy, and an extensive mathematical function
397 library.")
398 (license license:expat)))