2
0
Эх сурвалжийг харах

Add sockpp (#2299)

* sockpp: add package

* Update xmake.lua

* and and fix sockpp

---------

Co-authored-by: star9029 <[email protected]>
Co-authored-by: Jérôme Leclercq <[email protected]>
ruki 2 жил өмнө
parent
commit
11aeaec167

+ 53 - 0
packages/s/sockpp/patches/0.8.1/strerror.patch

@@ -0,0 +1,53 @@
+diff --git a/src/exception.cpp b/src/exception.cpp
+index 7cb010d..e9f1da1 100644
+--- a/src/exception.cpp
++++ b/src/exception.cpp
+@@ -57,30 +57,30 @@ sys_error::sys_error(int err) : runtime_error(error_str(err)), errno_(err)
+ 
+ std::string sys_error::error_str(int err)
+ {
+-	char buf[1024];
+-	buf[0] = '\x0';
++    char buf[1024];
++    buf[0] = '\x0';
+ 
+-	#if defined(_WIN32)
+-		FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+-			NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+-			buf, sizeof(buf), NULL);
++    #if defined(_WIN32)
++        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
++            NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
++            buf, sizeof(buf), NULL);
+     #else
+-    	#ifdef _GNU_SOURCE
+-			#if !defined(__GLIBC__)
+-			// use the XSI standard behavior.
+-				int e = strerror_r(err, buf, sizeof(buf));
+-				auto s = strerror(e);
+-				return s ? std::string(s) : std::string();
+-			#else
+-			// assume GNU exception
+-				auto s = strerror_r(err, buf, sizeof(buf));
+-				return s ? std::string(s) : std::string();
+-			#endif
++        #ifdef _GNU_SOURCE
++            #if defined(__GLIBC__) || (defined(__ANDROID_API__) && __ANDROID_API__ >= 23)
++                // assume GNU exception
++                auto s = strerror_r(err, buf, sizeof(buf));
++                return s ? std::string(s) : std::string();
++            #else
++                // use the XSI standard behavior.
++                int e = strerror_r(err, buf, sizeof(buf));
++                auto s = strerror(e);
++                return s ? std::string(s) : std::string();
++            #endif
+         #else
+             ignore_result(strerror_r(err, buf, sizeof(buf)));
+         #endif
+     #endif
+-	return std::string(buf);
++    return std::string(buf);
+ }
+ 
+ /////////////////////////////////////////////////////////////////////////////

+ 56 - 0
packages/s/sockpp/xmake.lua

@@ -0,0 +1,56 @@
+package("sockpp")
+    set_homepage("https://github.com/fpagliughi/sockpp")
+    set_description("Modern C++ socket library")
+    set_license("BSD-3-Clause")
+
+    add_urls("https://github.com/fpagliughi/sockpp/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/fpagliughi/sockpp.git")
+
+    add_versions("v0.8.1", "a8aedff8bd8c1da530b91be650352008fddabc9f1df0d19701d76cbc359c8651")
+
+    add_patches("0.8.1", path.join(os.scriptdir(), "patches", "0.8.1", "strerror.patch"), "8de819ba185c644254633d1de609e2c571c6c6f1aa7d2ac4329676ecf96fa556")
+
+    if is_plat("windows", "mingw") then
+        add_syslinks("ws2_32")
+    end
+
+    if is_plat("linux") then
+        add_configs("can", {description = "Build SocketCAN support.", default = false, type = "boolean"})
+    end
+
+    add_deps("cmake")
+
+    on_install(function (package)
+        local configs =
+        {
+            "-DSOCKPP_BUILD_STATIC=OFF",
+            "-DSOCKPP_BUILD_EXAMPLES=OFF",
+            "-DSOCKPP_BUILD_TESTS=OFF",
+            "-DSOCKPP_BUILD_DOCUMENTATION=OFF",
+        }
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
+        if package:config("shared") then
+            table.insert(configs, "-DSOCKPP_BUILD_SHARED=ON")
+            table.insert(configs, "-DSOCKPP_BUILD_STATIC=OFF")
+        else
+            table.insert(configs, "-DSOCKPP_BUILD_SHARED=OFF")
+            table.insert(configs, "-DSOCKPP_BUILD_STATIC=ON")
+        end
+        if package:is_plat("linux") then
+            table.insert(configs, "-DSOCKPP_BUILD_CAN=" .. (package:config("can") and "ON" or "OFF"))
+        end
+        import("package.tools.cmake").install(package, configs)
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            #include <string>
+            #include <sockpp/tcp_connector.h>
+            using namespace std::chrono;
+            void test() {
+                std::string host = "localhost";
+                in_port_t port = 12345;
+                sockpp::tcp_connector conn({host, port}, seconds{5});
+            }
+        ]]}, {configs = {languages = "c++14"}}))
+    end)