gnu: Add Pfff.
[jackhill/guix/guix.git] / gnu / packages / julia.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Ricardo Wurmus <rekado@elephly.net>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (gnu packages julia)
20 #:use-module ((guix licenses) #:prefix license:)
21 #:use-module (guix packages)
22 #:use-module (guix download)
23 #:use-module (guix utils)
24 #:use-module (guix git-download)
25 #:use-module (guix build-system gnu)
26 #:use-module (gnu packages)
27 #:use-module (gnu packages algebra)
28 #:use-module (gnu packages base)
29 #:use-module (gnu packages elf)
30 #:use-module (gnu packages gcc)
31 #:use-module (gnu packages llvm)
32 #:use-module (gnu packages libevent)
33 #:use-module (gnu packages libunwind)
34 #:use-module (gnu packages maths)
35 #:use-module (gnu packages multiprecision) ; mpfr
36 #:use-module (gnu packages pcre)
37 #:use-module (gnu packages perl)
38 #:use-module (gnu packages pkg-config)
39 #:use-module (gnu packages python)
40 #:use-module (gnu packages textutils)
41 #:use-module (gnu packages version-control)
42 #:use-module (gnu packages wget)
43 #:use-module (ice-9 match))
44
45 (define libuv-julia
46 (let ((commit "030481e9d659fd46702ab747caf2cbbe19d537ba")
47 (revision "1"))
48 (package (inherit libuv)
49 (name "libuv-julia")
50 (version (string-append "0.11.26." revision "-" (string-take commit 8)))
51 (source (origin
52 (method git-fetch)
53 (uri (git-reference
54 (url "https://github.com/JuliaLang/libuv.git")
55 (commit commit)))
56 (file-name (string-append name "-" version "-checkout"))
57 (sha256
58 (base32
59 "1ss63wfr2hghc8kb6ciry394gp6x58haz8vaj57l5mp80z04gd54"))))
60 (build-system gnu-build-system)
61 (arguments
62 (substitute-keyword-arguments (package-arguments libuv)
63 ((#:phases phases)
64 `(modify-phases ,phases
65 (delete 'autogen)))))
66 (home-page "https://github.com/JuliaLang/libuv"))))
67
68 (define-public julia
69 (package
70 (name "julia")
71 (version "0.4.2")
72 (source (origin
73 (method url-fetch)
74 (uri (string-append
75 "https://github.com/JuliaLang/julia/releases/download/v"
76 version "/julia-" version "-full.tar.gz"))
77 (sha256
78 (base32
79 "0sikirixvryf8z3d0skig22fpip64jk001qsha98iwsrcfiqpyds"))))
80 (build-system gnu-build-system)
81 (arguments
82 `(#:test-target "test"
83 #:modules ((ice-9 match)
84 (guix build gnu-build-system)
85 (guix build utils))
86
87
88 ;; The DSOs use $ORIGIN to refer to each other, but (guix build
89 ;; gremlin) doesn't support it yet, so skip this phase.
90 #:validate-runpath? #f
91
92 #:phases
93 (modify-phases %standard-phases
94 (delete 'configure)
95 (add-after 'unpack 'hardcode-soname-map
96 ;; ./src/ccall.cpp creates a map from library names to paths using the
97 ;; output of "/sbin/ldconfig -p". Since ldconfig is not used in Guix,
98 ;; we patch ccall.cpp to contain a static map.
99 (lambda* (#:key inputs #:allow-other-keys)
100 (use-modules (ice-9 match))
101 (substitute* "src/ccall.cpp"
102 (("jl_read_sonames.*;")
103 (string-join
104 (map (match-lambda
105 ((input libname soname)
106 (string-append
107 "sonameMap[\"" libname "\"] = "
108 "\"" (assoc-ref inputs input) "/lib/" soname "\";")))
109 '(("libc" "libc" "libc.so.6")
110 ("pcre2" "libpcre2-8" "libpcre2-8.so")
111 ("mpfr" "libmpfr" "libmpfr.so")
112 ("openblas" "libblas" "libopenblas.so")
113 ("arpack-ng" "libarpack" "libarpack.so")
114 ("lapack" "liblapack" "liblapack.so")
115 ("libgit2" "libgit2" "libgit2.so")
116 ("gmp" "libgmp" "libgmp.so")
117 ("openlibm" "libopenlibm" "libopenlibm.so")
118 ("openspecfun" "libopenspecfun" "libopenspecfun.so")
119 ("fftw" "libfftw3" "libfftw3.so")
120 ("fftwf" "libfftw3f" "libfftw3f.so"))))))
121 #t))
122 (add-before 'build 'fix-include-and-link-paths
123 (lambda* (#:key inputs #:allow-other-keys)
124 ;; LIBUTF8PROC is a linker flag, not a build target. It is
125 ;; included in the LIBFILES_* variable which is used as a
126 ;; collection of build targets and a list of libraries to link
127 ;; against.
128 (substitute* "src/flisp/Makefile"
129 (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\): \\$\\(OBJS\\) \\$\\(LIBFILES_release\\)")
130 "$(BUILDDIR)/$(EXENAME): $(OBJS) $(LLT_release)")
131 (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\)-debug: \\$\\(DOBJS\\) \\$\\(LIBFILES_debug\\)")
132 "$(BUILDDIR)/$(EXENAME)-debug: $(DOBJS) $(LLT_debug)"))
133
134 ;; The REPL must be linked with libuv.
135 (substitute* "ui/Makefile"
136 (("JLDFLAGS \\+= ")
137 (string-append "JLDFLAGS += "
138 (assoc-ref %build-inputs "libuv")
139 "/lib/libuv.so ")))
140
141 (substitute* "deps/Makefile"
142 (("/usr/include/double-conversion")
143 (string-append (assoc-ref %build-inputs "double-conversion")
144 "/include/double-conversion")))
145 (substitute* "base/Makefile"
146 (("\\$\\(build_includedir\\)/uv-errno.h")
147 (string-append (assoc-ref inputs "libuv")
148 "/include/uv-errno.h")))
149 #t))
150 (add-before 'build 'replace-default-shell
151 (lambda _
152 (substitute* "base/client.jl"
153 (("/bin/sh") (which "sh")))
154 #t))
155 (add-after 'unpack 'hardcode-paths
156 (lambda _
157 (substitute* "base/interactiveutil.jl"
158 (("`which") (string-append "`" (which "which")))
159 (("`wget") (string-append "`" (which "wget"))))
160 #t))
161 (add-before 'check 'disable-broken-tests
162 (lambda _
163 (substitute* "test/choosetests.jl"
164 ;; These tests time out. See
165 ;; https://github.com/JuliaLang/julia/issues/14374 for ongoing
166 ;; discussion.
167 (("\"replcompletions\",") "")
168 (("\"repl\",") ""))
169 (substitute* "test/repl.jl"
170 ;; This test fails because we cannot escape the build
171 ;; directory.
172 (("@test pwd\\(\\) == homedir\\(\\)") "#"))
173 #t)))
174 #:make-flags
175 (list
176 (string-append "prefix=" (assoc-ref %outputs "out"))
177
178 ;; Passing the MARCH flag is necessary to build binary substitutes for
179 ;; the supported architectures.
180 ,(match (or (%current-target-system)
181 (%current-system))
182 ("x86_64-linux" "MARCH=x86-64")
183 ("i686-linux" "MARCH=pentium4")
184 ;; Prevent errors when querying this package on unsupported
185 ;; platforms, e.g. when running "guix package --search="
186 (_ "MARCH=UNSUPPORTED"))
187
188 "CONFIG_SHELL=bash" ;needed to build bundled libraries
189 "USE_SYSTEM_DSFMT=0" ;not packaged for Guix and upstream has no
190 ;build system for a shared library.
191 "USE_SYSTEM_RMATH=0" ;Julia uses a bundled version of R's math
192 ;library, patched to use the DSFMT RNG.
193
194 "USE_SYSTEM_LAPACK=1"
195 "USE_SYSTEM_BLAS=1"
196 "USE_BLAS64=0" ;needed when USE_SYSTEM_BLAS=1
197
198 "USE_SYSTEM_FFTW=1"
199 "LIBFFTWNAME=libfftw3"
200 "LIBFFTWFNAME=libfftw3f"
201
202 ;; TODO: Suitesparse does not install shared libraries, so we cannot
203 ;; use the suitesparse package.
204 ;; "USE_SYSTEM_SUITESPARSE=1"
205 ;; (string-append "SUITESPARSE_INC=-I "
206 ;; (assoc-ref %build-inputs "suitesparse")
207 ;; "/include")
208
209 "USE_GPL_LIBS=1" ;proudly
210 "USE_SYSTEM_GRISU=1" ;for double-conversion
211 "USE_SYSTEM_UTF8PROC=1"
212 (string-append "UTF8PROC_INC="
213 (assoc-ref %build-inputs "utf8proc")
214 "/include")
215 "USE_SYSTEM_LLVM=1"
216 "USE_SYSTEM_LIBUNWIND=1"
217 "USE_SYSTEM_LIBUV=1"
218 (string-append "LIBUV="
219 (assoc-ref %build-inputs "libuv")
220 "/lib/libuv.so")
221 (string-append "LIBUV_INC="
222 (assoc-ref %build-inputs "libuv")
223 "/include")
224 "USE_SYSTEM_PATCHELF=1"
225 "USE_SYSTEM_PCRE=1"
226 "USE_SYSTEM_OPENLIBM=1"
227 "USE_SYSTEM_GMP=1"
228 "USE_SYSTEM_MPFR=1"
229 "USE_SYSTEM_ARPACK=1"
230 "USE_SYSTEM_LIBGIT2=1"
231 "USE_SYSTEM_OPENSPECFUN=1")))
232 (inputs
233 `(("llvm" ,llvm-3.5)
234 ("arpack-ng" ,arpack-ng)
235 ("coreutils" ,coreutils) ;for bindings to "mkdir" and the like
236 ("lapack" ,lapack)
237 ("openblas" ,openblas) ;Julia does not build with Atlas
238 ("libunwind" ,libunwind)
239 ("openlibm" ,openlibm)
240 ("openspecfun" ,openspecfun)
241 ("double-conversion" ,double-conversion)
242 ("libgit2" ,libgit2)
243 ("fftw" ,fftw)
244 ("fftwf" ,fftwf)
245 ("fortran" ,gfortran)
246 ("libuv" ,libuv-julia)
247 ("pcre2" ,pcre2)
248 ("utf8proc" ,utf8proc)
249 ("mpfr" ,mpfr)
250 ("wget" ,wget)
251 ("which" ,which)
252 ("gmp" ,gmp)))
253 (native-inputs
254 `(("perl" ,perl)
255 ("patchelf" ,patchelf)
256 ("pkg-config" ,pkg-config)
257 ("python" ,python-2)))
258 ;; Julia is not officially released for ARM and MIPS.
259 ;; See https://github.com/JuliaLang/julia/issues/10639
260 (supported-systems '("i686-linux" "x86_64-linux"))
261 (home-page "http://julialang.org/")
262 (synopsis "High-performance dynamic language for technical computing")
263 (description
264 "Julia is a high-level, high-performance dynamic programming language for
265 technical computing, with syntax that is familiar to users of other technical
266 computing environments. It provides a sophisticated compiler, distributed
267 parallel execution, numerical accuracy, and an extensive mathematical function
268 library.")
269 (license license:expat)))