Skip to content

Commit fe18a6c

Browse files
zeromq: support more platform (#5796)
* zeromq: support more platform * fix windows cross-compilation * fix mingw * fix export macro
1 parent e24a06e commit fe18a6c

File tree

3 files changed

+133
-19
lines changed

3 files changed

+133
-19
lines changed

packages/c/cppzmq/xmake.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ package("cppzmq")
66

77
add_urls("https://github.com/zeromq/cppzmq/archive/refs/tags/$(version).tar.gz",
88
"https://github.com/zeromq/cppzmq.git")
9+
910
add_versions("v4.8.1", "7a23639a45f3a0049e11a188e29aaedd10b2f4845f0000cf3e22d6774ebde0af")
1011
add_versions("v4.9.0", "3fdf5b100206953f674c94d40599bdb3ea255244dcc42fab0d75855ee3645581")
1112
add_versions("v4.10.0", "c81c81bba8a7644c84932225f018b5088743a22999c6d82a2b5f5cd1e6942b74")
1213

1314
add_deps("cmake", "zeromq")
1415

15-
on_install("windows", "macosx", "linux", function (package)
16+
on_install(function (package)
1617
import("package.tools.cmake").install(package, {"-DCPPZMQ_BUILD_TESTS=OFF"})
1718
end)
1819

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
From 241c24cb038770d0c9b499fea8ae1e6df5d170a4 Mon Sep 17 00:00:00 2001
2+
From: Stephan Lachnit <[email protected]>
3+
Date: Tue, 23 Apr 2024 16:02:59 +0200
4+
Subject: [PATCH] Do not use _MSC_VER if windows
5+
6+
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.
7+
8+
Signed-off-by: Stephan Lachnit <[email protected]>
9+
---
10+
src/ipc_address.hpp | 2 +-
11+
src/ipc_connecter.cpp | 2 +-
12+
src/ipc_listener.cpp | 2 +-
13+
tests/testutil.cpp | 2 +-
14+
4 files changed, 4 insertions(+), 4 deletions(-)
15+
16+
diff --git a/src/ipc_address.hpp b/src/ipc_address.hpp
17+
index 422c271127..87f1245b1b 100644
18+
--- a/src/ipc_address.hpp
19+
+++ b/src/ipc_address.hpp
20+
@@ -7,7 +7,7 @@
21+
22+
#include <string>
23+
24+
-#if defined _MSC_VER
25+
+#if defined ZMQ_HAVE_WINDOWS
26+
#include <afunix.h>
27+
#else
28+
#include <sys/socket.h>
29+
diff --git a/src/ipc_connecter.cpp b/src/ipc_connecter.cpp
30+
index 3f988745e7..ed2a0645ab 100644
31+
--- a/src/ipc_connecter.cpp
32+
+++ b/src/ipc_connecter.cpp
33+
@@ -16,7 +16,7 @@
34+
#include "ipc_address.hpp"
35+
#include "session_base.hpp"
36+
37+
-#ifdef _MSC_VER
38+
+#if defined ZMQ_HAVE_WINDOWS
39+
#include <afunix.h>
40+
#else
41+
#include <unistd.h>
42+
diff --git a/src/ipc_listener.cpp b/src/ipc_listener.cpp
43+
index 586bd7641c..92293da792 100644
44+
--- a/src/ipc_listener.cpp
45+
+++ b/src/ipc_listener.cpp
46+
@@ -17,7 +17,7 @@
47+
#include "socket_base.hpp"
48+
#include "address.hpp"
49+
50+
-#ifdef _MSC_VER
51+
+#ifdef ZMQ_HAVE_WINDOWS
52+
#ifdef ZMQ_IOTHREAD_POLLER_USE_SELECT
53+
#error On Windows, IPC does not work with POLLER=select, use POLLER=epoll instead, or disable IPC transport
54+
#endif
55+
diff --git a/tests/testutil.cpp b/tests/testutil.cpp
56+
index bdc80283cb..6f21e8f608 100644
57+
--- a/tests/testutil.cpp
58+
+++ b/tests/testutil.cpp
59+
@@ -7,7 +7,7 @@
60+
61+
#if defined _WIN32
62+
#include "../src/windows.hpp"
63+
-#if defined _MSC_VER
64+
+#if defined ZMQ_HAVE_WINDOWS
65+
#if defined ZMQ_HAVE_IPC
66+
#include <direct.h>
67+
#include <afunix.h>
68+

packages/z/zeromq/xmake.lua

+63-18
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,96 @@ package("zeromq")
55

66
set_urls("https://github.com/zeromq/libzmq/releases/download/v$(version)/zeromq-$(version).tar.gz",
77
"https://github.com/zeromq/libzmq.git")
8+
89
add_versions("4.3.5", "6653ef5910f17954861fe72332e68b03ca6e4d9c7160eb3a8de5a5a913bfab43")
910
add_versions("4.3.2", "ebd7b5c830d6428956b67a0454a7f8cbed1de74b3b01e5c33c5378e22740f763")
1011
add_versions("4.3.4", "c593001a89f5a85dd2ddf564805deb860e02471171b3f204944857336295c3e5")
1112

13+
add_patches("4.3.5", "patches/4.3.5/mingw.patch", "d36460c7080f928cd83f2a5752ed832cc2dd8c0ce4d8d69fc8e23f09d48f166c")
1214
add_patches("4.3.4", "https://github.com/zeromq/libzmq/commit/438d5d88392baffa6c2c5e0737d9de19d6686f0d.patch", "08f8068e109225ff628f9205597b917f633f02bc0be9382b06fbd98b0de2f8a0")
1315

14-
if is_plat("macosx") then
16+
if is_plat("mingw") and is_subhost("msys") then
17+
add_extsources("pacman::zeromq")
18+
elseif is_plat("linux") then
19+
add_extsources("pacman::zeromq")
20+
elseif is_plat("macosx") then
1521
add_extsources("brew::zeromq")
1622
end
1723

24+
add_configs("openpgm", {description = "Build with support for OpenPGM", default = false, type = "boolean", readonly = true})
25+
add_configs("norm", {description = "Build with support for NORM", default = false, type = "boolean", readonly = true})
26+
add_configs("vmci", {description = "Build with support for VMware VMCI socket", default = false, type = "boolean", readonly = true})
27+
28+
add_configs("curve", {description = "Enable CURVE security", default = false, type = "boolean"})
1829
if is_plat("linux") then
1930
add_configs("libunwind", {description = "Enable libunwind.", default = false, type = "boolean"})
2031
end
2132

22-
if is_plat("windows") then
23-
add_deps("cmake")
33+
if is_plat("windows", "mingw") then
2434
add_syslinks("ws2_32", "advapi32", "rpcrt4", "iphlpapi")
25-
elseif is_plat("linux") then
35+
elseif is_plat("linux", "bsd") then
2636
add_syslinks("pthread")
2737
end
28-
on_load("windows", "linux", function (package)
29-
if package:is_plat("windows") and not package:config("shared") then
38+
39+
add_deps("cmake")
40+
41+
on_load(function (package)
42+
if not package:config("shared") then
3043
package:add("defines", "ZMQ_STATIC")
3144
end
45+
46+
if package:config("openpgm") then
47+
package:add("deps", "openpgm")
48+
end
49+
if package:config("norm") then
50+
package:add("deps", "norm")
51+
end
52+
if package:config("curve") then
53+
package:add("deps", "libsodium")
54+
end
55+
3256
if package:is_plat("linux") and package:config("libunwind") then
3357
package:add("deps", "libunwind")
3458
end
3559
end)
3660

37-
on_install("windows", function (package)
61+
on_install(function (package)
3862
io.replace("CMakeLists.txt", "NOT ${CMAKE_BUILD_TYPE} MATCHES \"Debug\"", "FALSE", {plain = true})
39-
local configs = {"-DBUILD_TESTS=OFF", "-DLIBZMQ_WERROR=OFF"}
40-
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
63+
64+
local configs = {
65+
"-DBUILD_TESTS=OFF",
66+
"-DLIBZMQ_WERROR=OFF",
67+
"-DWITH_DOC=OFF",
68+
"-DWITH_DOCS=OFF",
69+
"-DWITH_PERF_TOOL=OFF",
70+
"-DENABLE_CPACK=OFF",
71+
"-DENABLE_CLANG=OFF",
72+
}
73+
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
4174
table.insert(configs, "-DBUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
4275
table.insert(configs, "-DBUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
43-
import("package.tools.cmake").install(package, configs)
44-
end)
76+
table.insert(configs, "-DENABLE_ASAN=" .. (package:config("asan") and "ON" or "OFF"))
77+
if (package:is_plat("windows") and package:is_cross()) or package:is_plat("mingw") then
78+
-- hardcode win10
79+
table.insert(configs, "-DCMAKE_SYSTEM_VERSION=10.0")
80+
end
4581

46-
on_install("linux", "macosx", function (package)
47-
local configs = {"--disable-dependency-tracking", "--without-docs", "--enable-libbsd=no", "--disable-Werror"}
48-
table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
49-
table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
50-
table.insert(configs, "--enable-libunwind=" .. (package:config("libunwind") and "yes" or "no"))
51-
table.insert(configs, "--libdir=" .. package:installdir("lib"))
52-
import("package.tools.autoconf").install(package, configs)
82+
table.insert(configs, "-DWITH_OPENPGM=" .. (package:config("openpgm") and "ON" or "OFF"))
83+
table.insert(configs, "-DWITH_NORM=" .. (package:config("norm") and "ON" or "OFF"))
84+
table.insert(configs, "-DWITH_VMCI=" .. (package:config("vmci") and "ON" or "OFF"))
85+
if package:is_plat("mingw") then
86+
table.insert(configs, "-DPOLLER=epoll")
87+
end
88+
89+
local libsodium = package:dep("libsodium")
90+
if libsodium then
91+
table.insert(configs, "-DENABLE_CURVE=ON")
92+
table.insert(configs, "-DWITH_LIBSODIUM=ON")
93+
table.insert(configs, "-DWITH_LIBSODIUM_STATIC=" .. (libsodium:config("shared") and "OFF" or "ON"))
94+
else
95+
table.insert(configs, "-DENABLE_CURVE=OFF")
96+
end
97+
import("package.tools.cmake").install(package, configs)
5398
end)
5499

55100
on_test(function (package)

0 commit comments

Comments
 (0)