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