Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / packages / lua.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com>
3 ;;; Copyright © 2014 Raimon Grau <raimonster@gmail.com>
4 ;;; Copyright © 2014 Mark H Weaver <mhw@netris.org>
5 ;;; Copyright © 2014 Andreas Enge <andreas@enge.fr>
6 ;;; Copyright © 2016, 2017 Efraim Flashner <efraim@flashner.co.il>
7 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
8 ;;; Copyright © 2016 doncatnip <gnopap@gmail.com>
9 ;;; Copyright © 2016, 2017 Clément Lassieur <clement@lassieur.org>
10 ;;; Copyright © 2016 José Miguel Sánchez García <jmi2k@openmailbox.org>
11 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
12 ;;; Copyright © 2018 Fis Trivial <ybbs.daans@hotmail.com>
13 ;;;
14 ;;; This file is part of GNU Guix.
15 ;;;
16 ;;; GNU Guix is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
20 ;;;
21 ;;; GNU Guix is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
25 ;;;
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
28
29 (define-module (gnu packages lua)
30 #:use-module ((guix licenses) #:prefix license:)
31 #:use-module (guix packages)
32 #:use-module (guix download)
33 #:use-module (guix git-download)
34 #:use-module (guix utils)
35 #:use-module (guix build utils)
36 #:use-module (guix build-system gnu)
37 #:use-module (guix build-system cmake)
38 #:use-module (gnu packages)
39 #:use-module (gnu packages readline)
40 #:use-module (gnu packages tls)
41 #:use-module (gnu packages xml)
42 #:use-module (gnu packages glib)
43 #:use-module (gnu packages libffi)
44 #:use-module (gnu packages pkg-config)
45 #:use-module (gnu packages xorg)
46 #:use-module (gnu packages gtk))
47
48 (define-public lua
49 (package
50 (name "lua")
51 (version "5.3.4")
52 (source (origin
53 (method url-fetch)
54 (uri (string-append "https://www.lua.org/ftp/lua-"
55 version ".tar.gz"))
56 (sha256
57 (base32 "0320a8dg3aci4hxla380dx1ifkw8gj4gbw5c4dz41g1kh98sm0gn"))
58 (patches (search-patches "lua-pkgconfig.patch"
59 "lua-liblua-so.patch"))))
60 (build-system gnu-build-system)
61 (inputs `(("readline" ,readline)))
62 (arguments
63 '(#:modules ((guix build gnu-build-system)
64 (guix build utils)
65 (srfi srfi-1))
66 #:test-target "test"
67 #:make-flags
68 '("MYCFLAGS=-fPIC -DLUA_DL_DLOPEN"
69 "linux")
70 #:phases
71 (modify-phases %standard-phases
72 (delete 'configure)
73 (replace 'install
74 (lambda* (#:key outputs #:allow-other-keys)
75 (let ((out (assoc-ref outputs "out")))
76 (invoke "make" "install"
77 (string-append "INSTALL_TOP=" out)
78 (string-append "INSTALL_MAN=" out
79 "/share/man/man1"))))))))
80 (home-page "https://www.lua.org/")
81 (synopsis "Embeddable scripting language")
82 (description
83 "Lua is a powerful, fast, lightweight, embeddable scripting language. Lua
84 combines simple procedural syntax with powerful data description constructs
85 based on associative arrays and extensible semantics. Lua is dynamically typed,
86 runs by interpreting bytecode for a register-based virtual machine, and has
87 automatic memory management with incremental garbage collection, making it ideal
88 for configuration, scripting, and rapid prototyping.")
89 (license license:x11)))
90
91 (define-public lua-5.2
92 (package (inherit lua)
93 (version "5.2.4")
94 (source
95 (origin
96 (method url-fetch)
97 (uri (string-append "https://www.lua.org/ftp/lua-"
98 version ".tar.gz"))
99 (sha256
100 (base32 "0jwznq0l8qg9wh5grwg07b5cy3lzngvl5m2nl1ikp6vqssmf9qmr"))
101 (patches (search-patches "lua-pkgconfig.patch"
102 "lua-liblua-so.patch"))))))
103
104 (define-public lua-5.1
105 (package (inherit lua)
106 (version "5.1.5")
107 (source (origin
108 (method url-fetch)
109 (uri (string-append "https://www.lua.org/ftp/lua-"
110 version ".tar.gz"))
111 (sha256
112 (base32 "0cskd4w0g6rdm2q8q3i4n1h3j8kylhs3rq8mxwl9vwlmlxbgqh16"))
113 (patches (search-patches "lua51-liblua-so.patch"
114 "lua-CVE-2014-5461.patch"
115 "lua51-pkgconfig.patch"))))))
116
117 (define-public luajit
118 (package
119 (name "luajit")
120 (version "2.1.0-beta3")
121 (source (origin
122 (method url-fetch)
123 (uri (string-append "http://luajit.org/download/LuaJIT-"
124 version ".tar.gz"))
125 (sha256
126 (base32 "1hyrhpkwjqsv54hnnx4cl8vk44h9d6c9w0fz1jfjz00w255y7lhs"))
127 (patches (search-patches "luajit-no_ldconfig.patch"))))
128 (build-system gnu-build-system)
129 (arguments
130 `(#:tests? #f ; luajit is distributed without tests
131 #:phases
132 (modify-phases %standard-phases
133 (delete 'configure) ; no configure script
134 (add-after 'install 'create-luajit-symlink
135 (lambda* (#:key outputs #:allow-other-keys)
136 (let* ((out (assoc-ref outputs "out"))
137 (bin (string-append out "/bin")))
138 (with-directory-excursion bin
139 (symlink ,(string-append name "-" version)
140 ,name)
141 #t)))))
142 #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out")))))
143 (home-page "https://www.luajit.org/")
144 (synopsis "Just in time compiler for Lua programming language version 5.1")
145 (description
146 "LuaJIT is a Just-In-Time Compiler (JIT) for the Lua
147 programming language. Lua is a powerful, dynamic and light-weight programming
148 language. It may be embedded or used as a general-purpose, stand-alone
149 language.")
150 (license license:x11)))
151
152 (define-public lua5.1-expat
153 (package
154 (name "lua5.1-expat")
155 (version "1.3.0")
156 (source (origin
157 (method url-fetch)
158 (uri (string-append "https://matthewwild.co.uk/projects/"
159 "luaexpat/luaexpat-" version ".tar.gz"))
160 (sha256
161 (base32
162 "1hvxqngn0wf5642i5p3vcyhg3pmp102k63s9ry4jqyyqc1wkjq6h"))))
163 (build-system gnu-build-system)
164 (arguments
165 `(#:make-flags
166 (let ((out (assoc-ref %outputs "out")))
167 (list "CC=gcc"
168 (string-append "LUA_LDIR=" out "/share/lua/$(LUA_V)")
169 (string-append "LUA_CDIR=" out "/lib/lua/$(LUA_V)")))
170 #:phases
171 (modify-phases %standard-phases
172 (delete 'configure)
173 (replace 'check
174 (lambda _
175 (setenv "LUA_CPATH" "src/?.so;;")
176 (setenv "LUA_PATH" "src/?.lua;;")
177 (invoke "lua" "tests/test.lua")
178 (invoke "lua" "tests/test-lom.lua"))))))
179 (inputs
180 `(("lua" ,lua-5.1)
181 ("expat" ,expat)))
182 (home-page "http://matthewwild.co.uk/projects/luaexpat/")
183 (synopsis "SAX XML parser based on the Expat library")
184 (description "LuaExpat is a SAX XML parser based on the Expat library.")
185 (license (package-license lua-5.1))))
186
187 (define-public lua5.1-socket
188 (package
189 (name "lua5.1-socket")
190 (version "3.0-rc1")
191 (source (origin
192 (method url-fetch)
193 (uri (string-append
194 "https://github.com/diegonehab/luasocket/archive/v"
195 version ".tar.gz"))
196 (file-name (string-append name "-" version ".tar.gz"))
197 (sha256
198 (base32
199 "0j8jx8bjicvp9khs26xjya8c495wrpb7parxfnabdqa5nnsxjrwb"))))
200 (build-system gnu-build-system)
201 (arguments
202 `(#:make-flags
203 (let ((out (assoc-ref %outputs "out")))
204 (list (string-append "INSTALL_TOP=" out)))
205 #:phases
206 (modify-phases %standard-phases
207 (delete 'configure)
208 (replace 'check
209 (lambda _
210 (setenv "LUA_CPATH" (string-append "src/?.so." ,version ";;"))
211 (setenv "LUA_PATH" "src/?.lua;;")
212 (when (zero? (primitive-fork))
213 (invoke "lua" "test/testsrvr.lua"))
214 (invoke "lua" "test/testclnt.lua"))))))
215 (inputs
216 `(("lua" ,lua-5.1)))
217 (home-page "http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/")
218 (synopsis "Socket library for Lua")
219 (description "LuaSocket is a Lua extension library that is composed by two
220 parts: a C core that provides support for the TCP and UDP transport layers,
221 and a set of Lua modules that add support for functionality commonly needed by
222 applications that deal with the Internet.
223
224 Among the supported modules, the most commonly used implement the
225 SMTP (sending e-mails), HTTP (WWW access) and FTP (uploading and downloading
226 files) client protocols. These provide a very natural and generic interface
227 to the functionality defined by each protocol. In addition, you will find
228 that the MIME (common encodings), URL (anything you could possible want to do
229 with one) and LTN12 (filters, sinks, sources and pumps) modules can be very
230 handy.")
231 (license (package-license lua-5.1))))
232
233 (define-public lua5.1-filesystem
234 (package
235 (name "lua5.1-filesystem")
236 (version "1.6.3")
237 (source (origin
238 (method url-fetch)
239 (uri (string-append "https://github.com/keplerproject/"
240 "luafilesystem/archive/v_"
241 "1_6_3" ".tar.gz"))
242 (file-name (string-append name "-" version ".tar.gz"))
243 (sha256
244 (base32
245 "0s10ckxin0bysd6gaywqhxkpw3ybjhprr8m655b8cx3pxjwd49am"))))
246 (build-system gnu-build-system)
247 (arguments
248 `(#:make-flags
249 (list (string-append "PREFIX=" (assoc-ref %outputs "out")))
250 #:test-target "test"
251 #:phases
252 (modify-phases %standard-phases
253 (delete 'configure))))
254 (inputs
255 `(("lua" ,lua-5.1)))
256 (home-page "https://keplerproject.github.io/luafilesystem/index.html")
257 (synopsis "File system library for Lua")
258 (description "LuaFileSystem is a Lua library developed to complement the
259 set of functions related to file systems offered by the standard Lua
260 distribution. LuaFileSystem offers a portable way to access the underlying
261 directory structure and file attributes.")
262 (license (package-license lua-5.1))))
263
264 (define-public lua5.1-sec
265 (package
266 (name "lua5.1-sec")
267 (version "0.6")
268 (source (origin
269 (method url-fetch)
270 (uri (string-append "https://github.com/brunoos/luasec/archive/"
271 "luasec-" version ".tar.gz"))
272 (sha256
273 (base32
274 "0pgd1anzznl4s0h16wg8dlw9mgdb9h52drlcki6sbf5y31fa7wyf"))))
275 (build-system gnu-build-system)
276 (arguments
277 `(#:make-flags
278 (let ((out (assoc-ref %outputs "out")))
279 (list "linux"
280 "CC=gcc"
281 "LD=gcc"
282 (string-append "LUAPATH=" out "/share/lua/5.1")
283 (string-append "LUACPATH=" out "/lib/lua/5.1")))
284 #:tests? #f ; no tests included
285 #:phases
286 (modify-phases %standard-phases
287 (delete 'configure))))
288 (inputs
289 `(("lua" ,lua-5.1)
290 ("openssl" ,openssl)))
291 (propagated-inputs
292 `(("lua-socket" ,lua5.1-socket)))
293 (home-page "https://github.com/brunoos/luasec/wiki")
294 (synopsis "OpenSSL bindings for Lua")
295 (description "LuaSec is a binding for OpenSSL library to provide TLS/SSL
296 communication. It takes an already established TCP connection and creates a
297 secure session between the peers.")
298 (license (package-license lua-5.1))))
299
300 (define-public lua-lgi
301 (package
302 (name "lua-lgi")
303 (version "0.9.2")
304 (source
305 (origin
306 (method url-fetch)
307 (uri (string-append
308 "https://github.com/pavouk/lgi/archive/"
309 version ".tar.gz"))
310 (file-name (string-append name "-" version ".tar.gz"))
311 (sha256
312 (base32
313 "0kwcaj3ahi9gxfyp0lr5zgr6vi1mgsg9sz0980x0nwxlh9a11i6g"))))
314 (build-system gnu-build-system)
315 (arguments
316 '(#:make-flags (list "CC=gcc"
317 (string-append "PREFIX=" (assoc-ref %outputs "out")))
318 #:phases
319 (modify-phases %standard-phases
320 (delete 'configure) ; no configure script
321 (add-before 'build 'set-env
322 (lambda* (#:key inputs #:allow-other-keys)
323 ;; we need to load cairo dynamically
324 (let* ((cairo (string-append
325 (assoc-ref inputs "cairo") "/lib" )))
326 (setenv "LD_LIBRARY_PATH" cairo)
327 #t)))
328 (add-before 'build 'set-lua-version
329 (lambda _
330 ;; lua version and therefore install directories are hardcoded
331 ;; FIXME: This breaks when we update lua to >=5.3
332 (substitute* "./lgi/Makefile"
333 (("LUA_VERSION=5.1") "LUA_VERSION=5.2"))
334 #t))
335 (add-before 'check 'skip-test-gtk
336 (lambda _
337 ;; FIXME: Skip GTK tests:
338 ;; gtk3 - can't get it to run with the xorg-server config below
339 ;; and some non-gtk tests will also fail
340 ;; gtk2 - lots of functions aren't implemented
341 ;; We choose gtk2 as the lesser evil and simply skip the test.
342 ;; Currently, awesome is the only package that uses lua-lgi but
343 ;; it doesn't need or interact with GTK using lua-lgi.
344 (substitute* "./tests/test.lua"
345 (("'gtk.lua',") "-- 'gtk.lua',"))
346 #t))
347 (add-before 'check 'start-xserver-instance
348 (lambda* (#:key inputs #:allow-other-keys)
349 ;; There must be a running X server during tests.
350 (system (format #f "~a/bin/Xvfb :1 &"
351 (assoc-ref inputs "xorg-server")))
352 (setenv "DISPLAY" ":1")
353 #t)))))
354 (inputs
355 `(("gobject-introspection" ,gobject-introspection)
356 ("glib" ,glib)
357 ("pango" ,pango)
358 ("gtk" ,gtk+-2)
359 ("lua" ,lua)
360 ("cairo" ,cairo)
361 ("libffi" ,libffi)
362 ("xorg-server" ,xorg-server)))
363 (native-inputs
364 `(("pkg-config" ,pkg-config)
365 ("dbus" ,dbus))) ;tests use 'dbus-run-session'
366 (home-page "https://github.com/pavouk/lgi/")
367 (synopsis "Lua bridge to GObject based libraries")
368 (description
369 "LGI is gobject-introspection based dynamic Lua binding to GObject
370 based libraries. It allows using GObject-based libraries directly from Lua.
371 Notable examples are GTK+, GStreamer and Webkit.")
372 (license license:expat)))
373
374 (define (make-lua-lpeg name lua)
375 (package
376 (name name)
377 (version "1.0.1")
378 (source (origin
379 (method url-fetch)
380 (uri (string-append "http://www.inf.puc-rio.br/~roberto/lpeg/lpeg-"
381 version ".tar.gz"))
382 (sha256
383 (base32 "0sq25z3r324a324ky73izgq9mbf66j2xvjp0fxf227rwxalzgnb2"))))
384 (build-system gnu-build-system)
385 (arguments
386 `(#:phases
387 (modify-phases %standard-phases
388 (delete 'configure)
389 ;; `make install` isn't available, so we have to do it manually
390 (replace 'install
391 (lambda* (#:key outputs #:allow-other-keys)
392 (let ((out (assoc-ref outputs "out"))
393 (lua-version ,(version-major+minor (package-version lua))))
394 (install-file "lpeg.so"
395 (string-append out "/lib/lua/" lua-version))
396 (install-file "re.lua"
397 (string-append out "/share/lua/" lua-version))
398 #t))))
399 #:test-target "test"))
400 (inputs `(("lua" ,lua)))
401 (synopsis "Pattern-matching library for Lua")
402 (description
403 "LPeg is a pattern-matching library for Lua, based on Parsing Expression
404 Grammars (PEGs).")
405 (home-page "http://www.inf.puc-rio.br/~roberto/lpeg")
406 (license license:expat)))
407
408 (define-public lua-lpeg
409 (make-lua-lpeg "lua-lpeg" lua))
410
411 (define-public lua5.2-lpeg
412 (make-lua-lpeg "lua5.2-lpeg" lua-5.2))
413
414 ;; Lua 5.3 is not supported.
415 (define (make-lua-bitop name lua)
416 (package
417 (name name)
418 (version "1.0.2")
419 (source (origin
420 (method url-fetch)
421 (uri (string-append "http://bitop.luajit.org/download/"
422 "LuaBitOp-" version ".tar.gz"))
423 (sha256
424 (base32
425 "16fffbrgfcw40kskh2bn9q7m3gajffwd2f35rafynlnd7llwj1qj"))))
426 (build-system gnu-build-system)
427 (arguments
428 `(#:test-target "test"
429 #:make-flags
430 (list "INSTALL=install -pD"
431 (string-append "INSTALLPATH=printf "
432 (assoc-ref %outputs "out")
433 "/lib/lua/"
434 ,(version-major+minor (package-version lua))
435 "/bit/bit.so"))
436 #:phases
437 (modify-phases %standard-phases
438 (delete 'configure))))
439 (inputs `(("lua" ,lua)))
440 (home-page "https://bitop.luajit.org/index.html")
441 (synopsis "Bitwise operations on numbers for Lua")
442 (description
443 "Lua BitOp is a C extension module for Lua which adds bitwise operations
444 on numbers.")
445 (license license:expat)))
446
447 (define-public lua5.2-bitop
448 (make-lua-bitop "lua5.2-bitop" lua-5.2))
449
450 (define-public lua5.1-bitop
451 (make-lua-bitop "lua5.1-bitop" lua-5.1))
452
453 (define-public selene
454 (package
455 (name "selene")
456 (version "2017.08.25")
457 (source (origin
458 (method git-fetch)
459 (uri (git-reference
460 (url "https://github.com/jeremyong/Selene.git")
461 ;; The release is quite old.
462 (commit "ffe1ade2568d4cff5894552be8f43e63e379a4c9")))
463 (file-name "Selene")
464 (sha256
465 (base32
466 "1axrgv3rxxdsaf807lwvklfzicn6x6gpf35narllrnz9lg6hn508"))))
467 (build-system cmake-build-system)
468 (arguments
469 `(#:configure-flags
470 ;; lua pc file in CMakeLists.txt is lua5.3.pc
471 '("-DLUA_PC_CFG=lua;lua-5.3;lua-5.1")
472 #:test-target "all"
473 #:phases
474 ;; This is a header only library
475 (modify-phases %standard-phases
476 (delete 'build)
477 (replace 'install
478 (lambda* (#:key inputs outputs #:allow-other-keys)
479 (let* ((output (assoc-ref outputs "out"))
480 (source (assoc-ref inputs "source"))
481 (includedir (string-append output "/include")))
482 (copy-recursively
483 (string-append source "/include")
484 includedir))
485 #t))
486 ;; The path of test files are hard coded.
487 (replace 'check
488 (lambda* (#:key inputs outputs #:allow-other-keys)
489 (let* ((output (assoc-ref outputs "out"))
490 (source (assoc-ref inputs "source"))
491 (builddir (getcwd))
492 (testdir (string-append builddir "/test")))
493 (copy-recursively (string-append source "/test") testdir)
494 (invoke "make")
495 (mkdir-p "runner")
496 (copy-file "./test_runner" "./runner/test_runner")
497 (chdir "./runner")
498 (invoke "./test_runner")))))))
499 (native-inputs
500 `(("lua" ,lua)
501 ("pkg-config" ,pkg-config)))
502 (home-page "https://github.com/jeremyong/Selene")
503 (synopsis "Lua C++11 bindings")
504 (description
505 "Selene is a simple C++11 header-only library enabling seamless
506 interoperability between C++ and Lua programming language.")
507 (license license:zlib)))