Parcourir la source

zeromq: support more platform (#5796)

* zeromq: support more platform

* fix windows cross-compilation

* fix mingw

* fix export macro
star9029 il y a 8 mois
Parent
commit
fe18a6cedc

+ 2 - 1
packages/c/cppzmq/xmake.lua

@@ -6,13 +6,14 @@ package("cppzmq")
 
     add_urls("https://github.com/zeromq/cppzmq/archive/refs/tags/$(version).tar.gz",
              "https://github.com/zeromq/cppzmq.git")
+
     add_versions("v4.8.1", "7a23639a45f3a0049e11a188e29aaedd10b2f4845f0000cf3e22d6774ebde0af")
     add_versions("v4.9.0", "3fdf5b100206953f674c94d40599bdb3ea255244dcc42fab0d75855ee3645581")
     add_versions("v4.10.0", "c81c81bba8a7644c84932225f018b5088743a22999c6d82a2b5f5cd1e6942b74")
 
     add_deps("cmake", "zeromq")
 
-    on_install("windows", "macosx", "linux", function (package)
+    on_install(function (package)
         import("package.tools.cmake").install(package, {"-DCPPZMQ_BUILD_TESTS=OFF"})
     end)
 

+ 68 - 0
packages/z/zeromq/patches/4.3.5/mingw.patch

@@ -0,0 +1,68 @@
+From 241c24cb038770d0c9b499fea8ae1e6df5d170a4 Mon Sep 17 00:00:00 2001
+From: Stephan Lachnit <[email protected]>
+Date: Tue, 23 Apr 2024 16:02:59 +0200
+Subject: [PATCH] Do not use _MSC_VER if windows
+
+This fixes several instances where _MSC_VER was used to determine whether to use afunix.h or not. For example, MinGW requires the use of afunix.h but does not define _MSC_VER. The correct behavior is checking ZMQ_HAVE_WINDOWS.
+
+Signed-off-by: Stephan Lachnit <[email protected]>
+---
+ src/ipc_address.hpp   | 2 +-
+ src/ipc_connecter.cpp | 2 +-
+ src/ipc_listener.cpp  | 2 +-
+ tests/testutil.cpp    | 2 +-
+ 4 files changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/src/ipc_address.hpp b/src/ipc_address.hpp
+index 422c271127..87f1245b1b 100644
+--- a/src/ipc_address.hpp
++++ b/src/ipc_address.hpp
+@@ -7,7 +7,7 @@
+ 
+ #include <string>
+ 
+-#if defined _MSC_VER
++#if defined ZMQ_HAVE_WINDOWS
+ #include <afunix.h>
+ #else
+ #include <sys/socket.h>
+diff --git a/src/ipc_connecter.cpp b/src/ipc_connecter.cpp
+index 3f988745e7..ed2a0645ab 100644
+--- a/src/ipc_connecter.cpp
++++ b/src/ipc_connecter.cpp
+@@ -16,7 +16,7 @@
+ #include "ipc_address.hpp"
+ #include "session_base.hpp"
+ 
+-#ifdef _MSC_VER
++#if defined ZMQ_HAVE_WINDOWS
+ #include <afunix.h>
+ #else
+ #include <unistd.h>
+diff --git a/src/ipc_listener.cpp b/src/ipc_listener.cpp
+index 586bd7641c..92293da792 100644
+--- a/src/ipc_listener.cpp
++++ b/src/ipc_listener.cpp
+@@ -17,7 +17,7 @@
+ #include "socket_base.hpp"
+ #include "address.hpp"
+ 
+-#ifdef _MSC_VER
++#ifdef ZMQ_HAVE_WINDOWS
+ #ifdef ZMQ_IOTHREAD_POLLER_USE_SELECT
+ #error On Windows, IPC does not work with POLLER=select, use POLLER=epoll instead, or disable IPC transport
+ #endif
+diff --git a/tests/testutil.cpp b/tests/testutil.cpp
+index bdc80283cb..6f21e8f608 100644
+--- a/tests/testutil.cpp
++++ b/tests/testutil.cpp
+@@ -7,7 +7,7 @@
+ 
+ #if defined _WIN32
+ #include "../src/windows.hpp"
+-#if defined _MSC_VER
++#if defined ZMQ_HAVE_WINDOWS
+ #if defined ZMQ_HAVE_IPC
+ #include <direct.h>
+ #include <afunix.h>
+ 

+ 63 - 18
packages/z/zeromq/xmake.lua

@@ -5,51 +5,96 @@ package("zeromq")
 
     set_urls("https://github.com/zeromq/libzmq/releases/download/v$(version)/zeromq-$(version).tar.gz",
              "https://github.com/zeromq/libzmq.git")
+
     add_versions("4.3.5", "6653ef5910f17954861fe72332e68b03ca6e4d9c7160eb3a8de5a5a913bfab43")
     add_versions("4.3.2", "ebd7b5c830d6428956b67a0454a7f8cbed1de74b3b01e5c33c5378e22740f763")
     add_versions("4.3.4", "c593001a89f5a85dd2ddf564805deb860e02471171b3f204944857336295c3e5")
 
+    add_patches("4.3.5", "patches/4.3.5/mingw.patch", "d36460c7080f928cd83f2a5752ed832cc2dd8c0ce4d8d69fc8e23f09d48f166c")
     add_patches("4.3.4", "https://github.com/zeromq/libzmq/commit/438d5d88392baffa6c2c5e0737d9de19d6686f0d.patch", "08f8068e109225ff628f9205597b917f633f02bc0be9382b06fbd98b0de2f8a0")
 
-    if is_plat("macosx") then
+    if is_plat("mingw") and is_subhost("msys") then
+        add_extsources("pacman::zeromq")
+    elseif is_plat("linux") then
+        add_extsources("pacman::zeromq")
+    elseif is_plat("macosx") then
         add_extsources("brew::zeromq")
     end
 
+    add_configs("openpgm", {description = "Build with support for OpenPGM", default = false, type = "boolean", readonly = true})
+    add_configs("norm", {description = "Build with support for NORM", default = false, type = "boolean", readonly = true})
+    add_configs("vmci", {description = "Build with support for VMware VMCI socket", default = false, type = "boolean", readonly = true})
+
+    add_configs("curve", {description = "Enable CURVE security", default = false, type = "boolean"})
     if is_plat("linux") then
         add_configs("libunwind", {description = "Enable libunwind.", default = false, type = "boolean"})
     end
 
-    if is_plat("windows") then
-        add_deps("cmake")
+    if is_plat("windows", "mingw") then
         add_syslinks("ws2_32", "advapi32", "rpcrt4", "iphlpapi")
-    elseif is_plat("linux") then
+    elseif is_plat("linux", "bsd") then
         add_syslinks("pthread")
     end
-    on_load("windows", "linux", function (package)
-        if package:is_plat("windows") and not package:config("shared") then
+
+    add_deps("cmake")
+
+    on_load(function (package)
+        if not package:config("shared") then
             package:add("defines", "ZMQ_STATIC")
         end
+
+        if package:config("openpgm") then
+            package:add("deps", "openpgm")
+        end
+        if package:config("norm") then
+            package:add("deps", "norm")
+        end
+        if package:config("curve") then
+            package:add("deps", "libsodium")
+        end
+
         if package:is_plat("linux") and package:config("libunwind") then
             package:add("deps", "libunwind")
         end
     end)
 
-    on_install("windows", function (package)
+    on_install(function (package)
         io.replace("CMakeLists.txt", "NOT ${CMAKE_BUILD_TYPE} MATCHES \"Debug\"", "FALSE", {plain = true})
-        local configs = {"-DBUILD_TESTS=OFF", "-DLIBZMQ_WERROR=OFF"}
-        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
+
+        local configs = {
+            "-DBUILD_TESTS=OFF",
+            "-DLIBZMQ_WERROR=OFF",
+            "-DWITH_DOC=OFF",
+            "-DWITH_DOCS=OFF",
+            "-DWITH_PERF_TOOL=OFF",
+            "-DENABLE_CPACK=OFF",
+            "-DENABLE_CLANG=OFF",
+        }
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
         table.insert(configs, "-DBUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
         table.insert(configs, "-DBUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
-        import("package.tools.cmake").install(package, configs)
-    end)
+        table.insert(configs, "-DENABLE_ASAN=" .. (package:config("asan") and "ON" or "OFF"))
+        if (package:is_plat("windows") and package:is_cross()) or package:is_plat("mingw") then
+            -- hardcode win10
+            table.insert(configs, "-DCMAKE_SYSTEM_VERSION=10.0")
+        end
 
-    on_install("linux", "macosx", function (package)
-        local configs = {"--disable-dependency-tracking", "--without-docs", "--enable-libbsd=no", "--disable-Werror"}
-        table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
-        table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
-        table.insert(configs, "--enable-libunwind=" .. (package:config("libunwind") and "yes" or "no"))
-        table.insert(configs, "--libdir=" .. package:installdir("lib"))
-        import("package.tools.autoconf").install(package, configs)
+        table.insert(configs, "-DWITH_OPENPGM=" .. (package:config("openpgm") and "ON" or "OFF"))
+        table.insert(configs, "-DWITH_NORM=" .. (package:config("norm") and "ON" or "OFF"))
+        table.insert(configs, "-DWITH_VMCI=" .. (package:config("vmci") and "ON" or "OFF"))
+        if package:is_plat("mingw") then
+            table.insert(configs, "-DPOLLER=epoll")
+        end
+
+        local libsodium = package:dep("libsodium")
+        if libsodium then
+            table.insert(configs, "-DENABLE_CURVE=ON")
+            table.insert(configs, "-DWITH_LIBSODIUM=ON")
+            table.insert(configs, "-DWITH_LIBSODIUM_STATIC=" .. (libsodium:config("shared") and "OFF" or "ON"))
+        else
+            table.insert(configs, "-DENABLE_CURVE=OFF")
+        end
+        import("package.tools.cmake").install(package, configs)
     end)
 
     on_test(function (package)