Browse Source

fcgi: add package (#8401)

star9029 2 months ago
parent
commit
0b0a382067

+ 39 - 0
packages/f/fcgi/patches/windows_type.patch

@@ -0,0 +1,39 @@
+diff --git a/libfcgi/os_win32.c b/libfcgi/os_win32.c
+index 1a77ca6..c047be9 100644
+--- a/libfcgi/os_win32.c
++++ b/libfcgi/os_win32.c
+@@ -222,7 +222,7 @@ static int Win32NewDescriptor(FILE_TYPE type, int fd, int desiredFd)
+ static void StdinThread(void * startup) 
+ {
+     int doIo = TRUE;
+-    unsigned long fd;
++    unsigned long long fd;
+     unsigned long bytesRead;
+     POVERLAPPED_REQUEST pOv;
+ 
+@@ -1467,7 +1467,7 @@ int OS_CloseRead(int fd)
+  */
+ int OS_DoIo(struct timeval *tmo)
+ {
+-    unsigned long fd;
++    unsigned long long fd;
+     unsigned long bytes;
+     POVERLAPPED_REQUEST pOv;
+     struct timeb tb;
+@@ -1539,6 +1539,7 @@ static int isAddrOK(struct sockaddr_in * inet_sockaddr, const char * okAddrs)
+ }
+ 
+ #ifndef NO_WSAACEPT
++
+ static int CALLBACK isAddrOKCallback(LPWSABUF  lpCallerId,
+                                      LPWSABUF  dc0,
+                                      LPQOS     dc1,
+@@ -1546,7 +1547,7 @@ static int CALLBACK isAddrOKCallback(LPWSABUF  lpCallerId,
+                                      LPWSABUF  dc3,
+                                      LPWSABUF  dc4,
+                                      GROUP     *dc5,
+-                                     DWORD     data)
++                                     DWORD_PTR     data)
+ {
+     struct sockaddr_in *sockaddr = (struct sockaddr_in *) lpCallerId->buf;
+ 

+ 110 - 0
packages/f/fcgi/port/fcgi_config.h.in

@@ -0,0 +1,110 @@
+/* include/fcgi_config.h */
+
+/* Define if you have the <arpa/inet.h> header file. */
+${define HAVE_ARPA_INET_H}
+
+/* Define if you have the <dlfcn.h> header file. */
+${define HAVE_DLFCN_H}
+
+/* Define if there's a fileno() prototype in stdio.h */
+${define HAVE_FILENO_PROTO}
+
+/* Define if the fpos_t typedef is in stdio.h */
+${define HAVE_FPOS}
+
+/* Define if you have the <inttypes.h> header file. */
+${define HAVE_INTTYPES_H}
+
+/* Define if you have the `dnet_stub' library (-ldnet_stub). */
+${define HAVE_LIBDNET_STUB}
+
+/* Define if you have the `ieee' library (-lieee). */
+${define HAVE_LIBIEEE}
+
+/* Define if you have the `nsl' library (-lnsl). */
+${define HAVE_LIBNSL}
+
+/* Define if you have the pthread library */
+${define HAVE_LIBPTHREAD}
+
+/* Define if you have the `resolv' library (-lresolv). */
+${define HAVE_LIBRESOLV}
+
+/* Define if you have the `socket' library (-lsocket). */
+${define HAVE_LIBSOCKET}
+
+/* Define if you have the <limits.h> header file. */
+${define HAVE_LIMITS_H}
+
+/* Define if you have the <memory.h> header file. */
+${define HAVE_MEMORY_H}
+
+/* Define if you have the <netdb.h> header file. */
+${define HAVE_NETDB_H}
+
+/* Define if you have the <netinet/in.h> header file. */
+${define HAVE_NETINET_IN_H}
+
+/* Define if sockaddr_un in sys/un.h contains a sun_len component */
+${define HAVE_SOCKADDR_UN_SUN_LEN}
+
+/* Define if the socklen_t typedef is in sys/socket.h */
+${define HAVE_SOCKLEN}
+
+/* Define if you have the <stdint.h> header file. */
+${define HAVE_STDINT_H}
+
+/* Define if you have the <stdlib.h> header file. */
+${define HAVE_STDLIB_H}
+
+/* Define if you have the `strerror' function. */
+${define HAVE_STRERROR}
+
+/* Define if you have the <strings.h> header file. */
+${define HAVE_STRINGS_H}
+
+/* Define if you have the <string.h> header file. */
+${define HAVE_STRING_H}
+
+/* Define if you have the <sys/param.h> header file. */
+${define HAVE_SYS_PARAM_H}
+
+/* Define if you have the <sys/socket.h> header file. */
+${define HAVE_SYS_SOCKET_H}
+
+/* Define if you have the <sys/stat.h> header file. */
+${define HAVE_SYS_STAT_H}
+
+/* Define if you have the <sys/time.h> header file. */
+${define HAVE_SYS_TIME_H}
+
+/* Define if you have the <sys/types.h> header file. */
+${define HAVE_SYS_TYPES_H}
+
+/* Define if you have the <unistd.h> header file. */
+${define HAVE_UNISTD_H}
+
+/* Define if va_arg(arg, long double) crashes the compiler */
+${define HAVE_VA_ARG_LONG_DOUBLE_BUG}
+
+/* Name of package */
+// ${define PACKAGE}
+
+/* Define if you have the ANSI C header files. */
+// ${define STDC_HEADERS}
+
+/* Define if cross-process locking is required by accept() */
+${define USE_LOCKING}
+
+/* Version number of package */
+// ${define VERSION}
+
+/* Define to empty if `const' does not conform to ANSI C. */
+// ${define const}
+
+/* Define as `__inline' if that's what the C compiler calls it, or to nothing
+   if it is not supported. */
+// ${define inline}
+
+/* Define to `int' if <sys/types.h> does not define. */
+// ${define ssize_t}

+ 86 - 0
packages/f/fcgi/port/xmake.lua

@@ -0,0 +1,86 @@
+option("ver", {default = nil})
+
+add_rules("mode.debug", "mode.release")
+if has_config("ver") then
+    set_version(get_config("ver"), {soname = true})
+end
+
+includes("@builtin/check")
+
+target("fcgi")
+    set_kind("$(kind)")
+    add_files("libfcgi/*.c|os_*.c")
+    if is_plat("windows", "mingw") then
+        add_files("libfcgi/os_win32.c")
+    else
+        add_files("libfcgi/os_unix.c")
+    end
+    if is_plat("windows") then
+        if is_kind("static") then
+            add_defines("DLLAPI=", {public = true})
+        else
+            add_defines("DLLAPI=__declspec(dllexport)")
+        end
+    end
+    add_includedirs("include", {public = true})
+    add_headerfiles("include/*.h|fcgi_config_x86.h")
+
+    if is_plat("windows", "mingw") then
+        add_syslinks("ws2_32")
+    elseif is_plat("linux", "bsd") then
+        add_syslinks("m")
+    end
+
+    set_configdir("include")
+    add_configfiles("fcgi_config.h.in")
+        
+    local header_map = {
+        HAVE_ARPA_INET_H = "arpa/inet.h",
+        HAVE_DLFCN_H = "dlfcn.h",
+        HAVE_INTTYPES_H = "inttypes.h",
+        HAVE_LIMITS_H = "limits.h",
+        HAVE_MEMORY_H = "memory.h",
+        HAVE_NETDB_H = "netdb.h",
+        HAVE_NETINET_IN_H = "netinet/in.h",
+        HAVE_STDINT_H = "stdint.h",
+        HAVE_STDLIB_H = "stdlib.h",
+        HAVE_STRINGS_H = "strings.h",
+        HAVE_STRING_H = "string.h",
+        HAVE_SYS_PARAM_H = "sys/param.h",
+        HAVE_SYS_SOCKET_H = "sys/socket.h",
+        HAVE_SYS_STAT_H = "sys/stat.h",
+        HAVE_SYS_TIME_H = "sys/time.h",
+        HAVE_SYS_TYPES_H = "sys/types.h",
+        HAVE_UNISTD_H = "unistd.h"
+    }
+    for macro, header in pairs(header_map) do
+        configvar_check_cincludes(macro, header)
+    end
+    configvar_check_cfuncs("HAVE_STRERROR", "strerror", {includes = {"string.h"}})
+    configvar_check_cfuncs("HAVE_FILENO_PROTO", "fileno", {includes = {"stdio.h"}})
+    configvar_check_ctypes("HAVE_FPOS", "fpos_t", {includes = "stdio.h"})
+    configvar_check_ctypes("HAVE_SOCKLEN", "socklen_t", {includes = "sys/socket.h"})
+    configvar_check_csnippets("HAVE_SOCKADDR_UN_SUN_LEN", [[
+        struct sockaddr_un addr;
+        addr.sun_len = 0;
+    ]], {includes = "sys/un.h"})
+    configvar_check_csnippets("HAVE_VA_ARG_LONG_DOUBLE_BUG", [[
+        long double lDblArg; va_list arg; lDblArg = va_arg(arg, long double);
+    ]], {includes = "stdarg.h"})
+
+target("fcgi++")
+    set_kind("$(kind)")
+    add_files("libfcgi/*.cpp")
+    if is_plat("windows") then
+        if is_kind("static") then
+            add_defines("DLLAPI=", {public = true})
+        else
+            add_defines("DLLAPI=__declspec(dllexport)")
+        end
+    end
+    add_deps("fcgi")
+
+target("cgi-fcgi")
+    set_kind("binary")
+    add_files("cgi-fcgi/cgi-fcgi.c")
+    add_deps("fcgi")

+ 34 - 0
packages/f/fcgi/xmake.lua

@@ -0,0 +1,34 @@
+package("fcgi")
+    set_homepage("https://fastcgi-archives.github.io")
+    set_description("Protocol for interfacing interactive programs with a web server")
+    set_license("OML")
+
+    set_urls("https://github.com/FastCGI-Archives/fcgi2/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/FastCGI-Archives/fcgi2.git")
+
+    add_versions("2.4.6", "39af4fb21a6d695a5f0b1c4fa95776d2725f6bc6c77680943a2ab314acd505c1")
+
+    if is_plat("windows", "mingw") and is_arch("x64", "x86_64") then
+        add_patches("*", "patches/windows_type.patch", "921143191bc0f2c33773d35a7a0352ab04c95963e03073c3f9dc3ec5c7751340")
+    end
+
+    add_links("fcgi++", "fcgi")
+
+    if is_plat("windows", "mingw") then
+        add_syslinks("ws2_32")
+    elseif is_plat("linux", "bsd") then
+        add_syslinks("m")
+    end
+
+    on_install(function (package)
+        if package:is_plat("windows") and  not package:config("shared") then
+            package:add("defines", "DLLAPI=")
+        end
+        os.cp(path.join(package:scriptdir(), "port", "fcgi_config.h.in"), "fcgi_config.h.in")
+        os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
+        import("package.tools.xmake").install(package, {ver = package:version_str()})
+    end)
+
+    on_test(function (package)
+        assert(package:has_cfuncs("FCGI_Accept", {includes = "fcgi_stdio.h"}))
+    end)