From 95d0402b563d2ccfba3c546f93cd32c3846f1e8d Mon Sep 17 00:00:00 2001
From: Valter Nazianzeno <manipuladordedados@gmail.com>
Date: Thu, 24 Aug 2023 23:58:43 -0300
Subject: [PATCH] gnu: emilua: Update build options

Based on a review the tests are functional now.
---
 gnu/packages/lua.scm | 92 +++++++++++++++++++++++++++++++-------------
 1 file changed, 65 insertions(+), 27 deletions(-)

diff --git a/gnu/packages/lua.scm b/gnu/packages/lua.scm
index 405f8511cb..e8be5c28cf 100644
--- a/gnu/packages/lua.scm
+++ b/gnu/packages/lua.scm
@@ -19,6 +19,7 @@
 ;;; Copyright © 2022 Luis Henrique Gomes Higino <luishenriquegh2701@gmail.com>
 ;;; Copyright © 2022 Leo Nikkilä <hello@lnikki.la>
 ;;; Copyright © 2023 Yovan Naumovski <yovan@gorski.stream>
+;;; Copyright © 2023 Valter Nazianzeno <manipuladordedados@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -64,6 +65,11 @@ (define-module (gnu packages lua)
   #:use-module (gnu packages vim)
   #:use-module (gnu packages xml)
   #:use-module (gnu packages xorg)
+  #:use-module (gnu packages rdf)
+  #:use-module (gnu packages gperf)
+  #:use-module (gnu packages gawk)
+  #:use-module (gnu packages gcc)
+  #:use-module (gnu packages linux)
   #:use-module (srfi srfi-1))
 
 (define-public lua
@@ -1130,49 +1136,81 @@ (define-public lua-resty-shell
 (define-public emilua
   (package
    (name "emilua")
-   (version "0.3.2")
+   (version "0.4.3")
    (source (origin
             (method git-fetch)
             (uri (git-reference
                   (url "https://gitlab.com/emilua/emilua.git")
-                  (commit (string-append "v" version))
-                  ;; Current version requires Trial.Protocol and the HTTP lib
-                  ;; developed as part of GSoC 2014 for Boost, and these are
-                  ;; dependencies unlikely to be "unbundled" in future releases.
-                  (recursive? #t)))
+                  (commit (string-append "v" version))))
             (file-name (git-file-name name version))
             (sha256
              (base32
-              "1999bgrh52124a5g4qizav3x257ff2brjr855srpm1jv1nxzbygv"))))
+              "1dwag2pyqc0g86rris4w4fzafmz9a6kiqd47vdq7hl3a1lyi74mx"))))
    (build-system meson-build-system)
    (arguments
-    `(;; Tests are disabled for now due to an issue that affecs guix:
-      ;; <https://gitlab.com/emilua/emilua/-/issues/22>
+   	`(#:phases
+       (modify-phases %standard-phases
+		(add-after 'unpack
+		(lambda* (#:key inputs #:allow-other-keys)
+			(use-modules (guix build utils))
+			(substitute* "src/emilua_gperf.awk" (("/usr/bin/env") (which "env")))
+			(substitute* "src/system.cpp" (("P_PIDFD") "P_PID"))
+			(copy-recursively (assoc-ref inputs "emilua-http")
+							"emilua-http")
+			(copy-recursively (assoc-ref inputs "trial-protocol")
+							"trial-protocol")                              
+			(chdir "subprojects")
+			(symlink "../emilua-http" "emilua-http")
+			(copy-file "packagefiles/emilua-http/meson.build" "emilua-http/meson.build")
+			(symlink "../trial-protocol" "trial-protocol")
+			(copy-file "packagefiles/trial.protocol/meson.build" "trial-protocol/meson.build")
+			(chdir "../")                                           
+			#t)))
       #:configure-flags
+      ;; Linux namespaces are disabled for now due to conflict with some packages in guix.
       (list "-Denable_http=true"
-            "-Denable_tests=false"
+      		"-Denable_file_io=true"
+      		"-Denable_io_uring=true"
+      		"-Denable_linux_namespaces=false"
+            "-Denable_tests=true"
             "-Denable_manpages=false"
-            "-Dversion_suffix=-guix1")))
+            "-Dversion_suffix=-guix1")))            
    (native-inputs
     (list luajit-lua52-openresty
-          pkg-config
           re2c
-          xxd))
+          gperf
+          gawk
+          xxd
+          pkg-config))
    (inputs
-    (list boost
-          boost-static
-          fmt-7
-          ;; LuaJIT has a 2GiB addressing limit[1] that has been fixed on OpenResty
-          ;; fork. Emilua is severely affected by this limit, so the upstream package
-          ;; is avoided. Emilua also depends on the -DLUAJIT_ENABLE_LUA52COMPAT
-          ;; configure flag[2] for some features to work (e.g. __pairs on HTTP
-          ;; headers).
-          ;;
-          ;; [1] <http://hacksoflife.blogspot.com/2012/12/integrating-luajit-with-x-plane-64-bit.html>
-          ;; [2] <http://luajit.org/extensions.html#lua52>
-          luajit-lua52-openresty
-          ncurses
-          openssl))
+   	`(("emilua-http" ,(origin
+                        (method git-fetch)
+                        (uri (git-reference
+                              (url "https://github.com/BoostGSoC14/boost.http")
+                              (commit "93ae527c89ffc517862e1f5f54c8a257278f1195")))
+                        (sha256
+                         (base32
+                         "0jm7fw0cjd3s9zkkvyh6mcj6z32hcy7l9bszv74l92qk15ivvp9h")))
+                         )
+       ("trial-protocol" ,(origin
+                           (method git-fetch)
+                           (uri (git-reference
+                                 (url "https://github.com/breese/trial.protocol")
+                                 (commit "79149f604a49b8dfec57857ca28aaf508069b669")))
+                           (sha256
+                         	(base32
+                             "0k42i5b4v3zz5x0r3dssiymgmn2x8zg4fzdksya9aggxgigippsx"))))                                                  
+    ("boost" ,boost)     
+	("boost-static" ,boost-static)
+	("fmt-8" ,fmt-8)
+	("gcc-12" ,gcc-12)
+	("luajit-lua52-openresty" ,luajit-lua52-openresty)
+	("ncurses" ,ncurses)
+	("serd" ,serd)
+	("sord" ,sord)
+	("libcap" ,libcap)
+	("liburing" ,liburing)
+	("openssl" ,openssl)))
    (native-search-paths
     (list
      (search-path-specification

base-commit: ff48a10807162233f32010420e96752d6744c6b8
-- 
2.41.0

