gnu: python-pandas: Fix build on 32-bit.
[jackhill/guix/guix.git] / gnu / packages / julia.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016 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 "8d5131b6c1595920dd30644cd1435b4f344b46c8")
50 (revision "4"))
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 "1fq0vhiprdryw8iisxxwyld3xdr5za6y8458p22ff56al98h22fv"))))
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.5.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 "0bhickil88lalp9jdj1kmf4is70zinhx8ha9rng0g3z50r4a2qmv"))))
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 #t))
126 (add-after 'unpack 'fix-llvm-flag
127 (lambda _
128 (substitute* "src/Makefile"
129 (("-lLLVM-\\$\\(shell \\$\\(LLVM_CONFIG_HOST\\) --version\\)")
130 "$(shell $(LLVM_CONFIG_HOST) --libs)"))
131 #t))
132 (add-before 'check 'set-home
133 ;; Some tests require a home directory to be set.
134 (lambda _ (setenv "HOME" "/tmp") #t))
135 (add-after 'unpack 'hardcode-soname-map
136 ;; ./src/runtime_ccall.cpp creates a map from library names to paths
137 ;; using the output of "/sbin/ldconfig -p". Since ldconfig is not
138 ;; used in Guix, we patch runtime_ccall.cpp to contain a static map.
139 (lambda* (#:key inputs #:allow-other-keys)
140 (use-modules (ice-9 match))
141 (substitute* "src/runtime_ccall.cpp"
142 (("jl_read_sonames.*;")
143 (string-join
144 (map (match-lambda
145 ((input libname soname)
146 (string-append
147 "sonameMap[\"" libname "\"] = "
148 "\"" (assoc-ref inputs input) "/lib/" soname "\";")))
149 '(("libc" "libc" "libc.so.6")
150 ("pcre2" "libpcre2-8" "libpcre2-8.so")
151 ("mpfr" "libmpfr" "libmpfr.so")
152 ("openblas" "libblas" "libopenblas.so")
153 ("arpack-ng" "libarpack" "libarpack.so")
154 ("lapack" "liblapack" "liblapack.so")
155 ("libgit2" "libgit2" "libgit2.so")
156 ("gmp" "libgmp" "libgmp.so")
157 ("openlibm" "libopenlibm" "libopenlibm.so")
158 ("openspecfun" "libopenspecfun" "libopenspecfun.so")
159 ("fftw" "libfftw3" "libfftw3.so")
160 ("fftwf" "libfftw3f" "libfftw3f.so"))))))
161 (substitute* "base/fft/FFTW.jl"
162 (("const libfftw = Base.libfftw_name")
163 (string-append "const libfftw = \""
164 (assoc-ref inputs "fftw") "/lib/libfftw3.so"
165 "\""))
166 (("const libfftwf = Base.libfftwf_name")
167 (string-append "const libfftwf = \""
168 (assoc-ref inputs "fftwf") "/lib/libfftw3f.so"
169 "\"")))
170 (substitute* "base/math.jl"
171 (("const libm = Base.libm_name")
172 (string-append "const libm = \""
173 (assoc-ref inputs "openlibm")
174 "/lib/libopenlibm.so"
175 "\""))
176 (("const openspecfun = \"libopenspecfun\"")
177 (string-append "const openspecfun = \""
178 (assoc-ref inputs "openspecfun")
179 "/lib/libopenspecfun.so"
180 "\"")))
181 (substitute* "base/pcre.jl"
182 (("const PCRE_LIB = \"libpcre2-8\"")
183 (string-append "const PCRE_LIB = \""
184 (assoc-ref inputs "pcre2")
185 "/lib/libpcre2-8.so" "\"")))
186 #t))
187 (add-before 'build 'fix-include-and-link-paths
188 (lambda* (#:key inputs #:allow-other-keys)
189 ;; LIBUTF8PROC is a linker flag, not a build target. It is
190 ;; included in the LIBFILES_* variable which is used as a
191 ;; collection of build targets and a list of libraries to link
192 ;; against.
193 (substitute* "src/flisp/Makefile"
194 (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\): \\$\\(OBJS\\) \\$\\(LIBFILES_release\\)")
195 "$(BUILDDIR)/$(EXENAME): $(OBJS) $(LLT_release)")
196 (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\)-debug: \\$\\(DOBJS\\) \\$\\(LIBFILES_debug\\)")
197 "$(BUILDDIR)/$(EXENAME)-debug: $(DOBJS) $(LLT_debug)"))
198
199 ;; The REPL must be linked with libuv.
200 (substitute* "ui/Makefile"
201 (("JLDFLAGS \\+= ")
202 (string-append "JLDFLAGS += "
203 (assoc-ref %build-inputs "libuv")
204 "/lib/libuv.so ")))
205
206 (substitute* "base/Makefile"
207 (("\\$\\(build_includedir\\)/uv-errno.h")
208 (string-append (assoc-ref inputs "libuv")
209 "/include/uv-errno.h")))
210 #t))
211 (add-before 'build 'replace-default-shell
212 (lambda _
213 (substitute* "base/client.jl"
214 (("/bin/sh") (which "sh")))
215 #t))
216 (add-after 'unpack 'hardcode-paths
217 (lambda _
218 (substitute* "base/interactiveutil.jl"
219 (("`which") (string-append "`" (which "which")))
220 (("`wget") (string-append "`" (which "wget"))))
221 #t))
222 (add-before 'check 'disable-broken-tests
223 (lambda _
224 (substitute* "test/choosetests.jl"
225 ;; These tests fail, probably because some of the input
226 ;; binaries have been stripped and thus backtraces don't look
227 ;; as expected.
228 (("\"backtrace\",") "")
229 (("\"compile\",") "")
230 (("\"replutil\",") "")
231 (("\"cmdlineargs\",") ""))
232 #t)))
233 #:make-flags
234 (list
235 (string-append "prefix=" (assoc-ref %outputs "out"))
236
237 ;; Passing the MARCH flag is necessary to build binary substitutes for
238 ;; the supported architectures.
239 ,(match (or (%current-target-system)
240 (%current-system))
241 ("x86_64-linux" "MARCH=x86-64")
242 ("i686-linux" "MARCH=pentium4")
243 ;; Prevent errors when querying this package on unsupported
244 ;; platforms, e.g. when running "guix package --search="
245 (_ "MARCH=UNSUPPORTED"))
246
247 "CONFIG_SHELL=bash" ;needed to build bundled libraries
248 "USE_SYSTEM_DSFMT=0" ;not packaged for Guix and upstream has no
249 ;build system for a shared library.
250 "USE_SYSTEM_LAPACK=1"
251 "USE_SYSTEM_BLAS=1"
252 "USE_BLAS64=0" ;needed when USE_SYSTEM_BLAS=1
253
254 "USE_SYSTEM_FFTW=1"
255 "LIBFFTWNAME=libfftw3"
256 "LIBFFTWFNAME=libfftw3f"
257
258 ;; TODO: Suitesparse does not install shared libraries, so we cannot
259 ;; use the suitesparse package.
260 ;; "USE_SYSTEM_SUITESPARSE=1"
261 ;; (string-append "SUITESPARSE_INC=-I "
262 ;; (assoc-ref %build-inputs "suitesparse")
263 ;; "/include")
264
265 "USE_GPL_LIBS=1" ;proudly
266 "USE_SYSTEM_UTF8PROC=1"
267 (string-append "UTF8PROC_INC="
268 (assoc-ref %build-inputs "utf8proc")
269 "/include")
270 "USE_SYSTEM_LLVM=1"
271 "USE_SYSTEM_LIBUNWIND=1"
272 "USE_SYSTEM_LIBUV=1"
273 (string-append "LIBUV="
274 (assoc-ref %build-inputs "libuv")
275 "/lib/libuv.so")
276 (string-append "LIBUV_INC="
277 (assoc-ref %build-inputs "libuv")
278 "/include")
279 "USE_SYSTEM_PATCHELF=1"
280 "USE_SYSTEM_PCRE=1"
281 "USE_SYSTEM_OPENLIBM=1"
282 "USE_SYSTEM_GMP=1"
283 "USE_SYSTEM_MPFR=1"
284 "USE_SYSTEM_ARPACK=1"
285 "USE_SYSTEM_LIBGIT2=1"
286 "USE_SYSTEM_OPENSPECFUN=1")))
287 (inputs
288 `(("llvm" ,llvm)
289 ("arpack-ng" ,arpack-ng)
290 ("coreutils" ,coreutils) ;for bindings to "mkdir" and the like
291 ("lapack" ,lapack)
292 ("openblas" ,openblas) ;Julia does not build with Atlas
293 ("libunwind" ,libunwind-for-julia)
294 ("openlibm" ,openlibm)
295 ("openspecfun" ,openspecfun)
296 ("libgit2" ,libgit2)
297 ("fftw" ,fftw)
298 ("fftwf" ,fftwf)
299 ("fortran" ,gfortran)
300 ("libuv" ,libuv-julia)
301 ("pcre2" ,pcre2)
302 ("utf8proc" ,utf8proc)
303 ("mpfr" ,mpfr)
304 ("wget" ,wget)
305 ("which" ,which)
306 ("zlib" ,zlib)
307 ("gmp" ,gmp)
308 ("virtualenv" ,python2-virtualenv)
309 ;; FIXME: The following inputs are downloaded from upstream to allow us
310 ;; to use the lightweight Julia release tarball. Ideally, these inputs
311 ;; would eventually be replaced with proper Guix packages.
312
313 ;; TODO: run "make -f contrib/repackage_system_suitesparse4.make" to copy static lib
314 ("suitesparse"
315 ,(origin
316 (method url-fetch)
317 (uri "http://faculty.cse.tamu.edu/davis/SuiteSparse/SuiteSparse-4.4.5.tar.gz")
318 (sha256
319 (base32
320 "1jcbxb8jx5wlcixzf6n5dca2rcfx6mlcms1k2rl5gp67ay3bix43"))))
321 ("objconv"
322 ,(origin
323 (method url-fetch)
324 (uri "http://www.agner.org/optimize/objconv.zip")
325 (sha256
326 (base32
327 "1fi7qa2sd9vb35dvkgripjf0fayzg2qmff215f8agfqfiwd1g8qs"))))
328 ("dsfmt"
329 ,(origin
330 (method url-fetch)
331 (uri (string-append
332 "http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/"
333 "SFMT/dSFMT-src-2.2.3.tar.gz"))
334 (sha256
335 (base32
336 "03kaqbjbi6viz0n33dk5jlf6ayxqlsq4804n7kwkndiga9s4hd42"))))))
337 (native-inputs
338 `(("openssl" ,openssl)
339 ("perl" ,perl)
340 ("patchelf" ,patchelf)
341 ("pkg-config" ,pkg-config)
342 ("python" ,python-2)))
343 ;; Julia is not officially released for ARM and MIPS.
344 ;; See https://github.com/JuliaLang/julia/issues/10639
345 (supported-systems '("i686-linux" "x86_64-linux"))
346 (home-page "http://julialang.org/")
347 (synopsis "High-performance dynamic language for technical computing")
348 (description
349 "Julia is a high-level, high-performance dynamic programming language for
350 technical computing, with syntax that is familiar to users of other technical
351 computing environments. It provides a sophisticated compiler, distributed
352 parallel execution, numerical accuracy, and an extensive mathematical function
353 library.")
354 (license license:expat)))