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