Browse Source

easywsclient: add package (#2869)

* easywsclient: add package

* easywsclient: fix linux

* easywsclient: fix hash

* easywsclient: remove new line

* easywsclient: update fix_linux.patch

* easywsclient: use add_cstdint.patch

* easywsclient: update patch

* easywsclient: fix patch

* easywsclient: update patch

* easywsclient: add_syslinks ws2_32

* easywsclient: update patch

* easywsclient: add patch

* easywsclient: add patch

* easywsclient: remove patch

* easywsclient: use unique_ptr for test
Chi Huu Huynh 1 year ago
parent
commit
1e14614f74

+ 42 - 0
packages/e/easywsclient/patches/2021.01.12/add_cstdint.patch

@@ -0,0 +1,42 @@
+diff --git a/easywsclient.cpp b/easywsclient.cpp
+index 0c98098..750d513 100644
+--- a/easywsclient.cpp
++++ b/easywsclient.cpp
+@@ -26,17 +26,6 @@
+     #ifndef snprintf
+         #define snprintf _snprintf_s
+     #endif
+-    #if _MSC_VER >=1600
+-        // vs2010 or later
+-        #include <stdint.h>
+-    #else
+-        typedef __int8 int8_t;
+-        typedef unsigned __int8 uint8_t;
+-        typedef __int32 int32_t;
+-        typedef unsigned __int32 uint32_t;
+-        typedef __int64 int64_t;
+-        typedef unsigned __int64 uint64_t;
+-    #endif
+     #define socketerrno WSAGetLastError()
+     #define SOCKET_EAGAIN_EINPROGRESS WSAEINPROGRESS
+     #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
+@@ -52,7 +41,6 @@
+     #include <sys/time.h>
+     #include <sys/types.h>
+     #include <unistd.h>
+-    #include <stdint.h>
+     #ifndef _SOCKET_T_DEFINED
+         typedef int socket_t;
+         #define _SOCKET_T_DEFINED
+diff --git a/easywsclient.hpp b/easywsclient.hpp
+index 08c4a7b..df60500 100644
+--- a/easywsclient.hpp
++++ b/easywsclient.hpp
+@@ -10,6 +10,7 @@
+ 
+ #include <string>
+ #include <vector>
++#include <cstdint>
+ 
+ namespace easywsclient {
+ 

+ 18 - 0
packages/e/easywsclient/patches/2021.01.12/move_import.patch

@@ -0,0 +1,18 @@
+diff --git a/easywsclient.cpp b/easywsclient.cpp
+index 0c98098..aca7e77 100644
+--- a/easywsclient.cpp
++++ b/easywsclient.cpp
+@@ -1,3 +1,4 @@
++#include "easywsclient.hpp"
+ 
+ #ifdef _WIN32
+     #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
+@@ -73,8 +74,6 @@
+ #include <vector>
+ #include <string>
+ 
+-#include "easywsclient.hpp"
+-
+ using easywsclient::Callback_Imp;
+ using easywsclient::BytesCallback_Imp;
+ 

+ 43 - 0
packages/e/easywsclient/xmake.lua

@@ -0,0 +1,43 @@
+package("easywsclient")
+    set_homepage("https://github.com/dhbaird/easywsclient")
+    set_description("A short and sweet WebSocket client for C++")
+    set_license("MIT")
+
+    add_urls("https://github.com/dhbaird/easywsclient.git")
+    add_versions("2021.01.12", "afc1d8cfc584e0f1f4a77e8c0ce3e979d9fe7ce2")
+    add_patches("2021.01.12", path.join(os.scriptdir(), "patches", "2021.01.12", "add_cstdint.patch"), "babddf02e9eae42cc11e5458478f207837a402c425b31dafd2ef63a29b7d6744")
+    add_patches("2021.01.12", path.join(os.scriptdir(), "patches", "2021.01.12", "move_import.patch"), "9265412268390cbfcb799f40324c3e255ae6fc01c292e749c131f1c3c19e32bd")
+
+    if is_plat("mingw") then
+        add_syslinks("ws2_32")
+    end
+
+    on_install(function (package)
+        local configs = {}
+        io.writefile("xmake.lua", [[
+            add_rules("mode.release", "mode.debug")
+            target("easywsclient")
+                set_kind("$(kind)")
+                set_languages("cxx11")
+                add_files("easywsclient.cpp")
+                add_headerfiles("(easywsclient.hpp)")
+                if is_plat("windows") then
+                    add_defines("_WIN32")
+                end
+                if is_plat("mingw") then
+                    add_syslinks("ws2_32")
+                end
+        ]])
+        import("package.tools.xmake").install(package, configs)
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            #include <memory>
+            #include "easywsclient.hpp"
+            void test() {
+                std::unique_ptr<easywsclient::WebSocket> ws(easywsclient::WebSocket::from_url("ws://echo.websocket.org"));
+                ws->send("Hello World!");
+            }
+        ]]}), {configs = {languages = "cxx11"}})
+    end)