From 398833ebe333efa751c52d2fa0f0a940d1d9878b Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 14 May 2023 09:18:54 -0500 Subject: [PATCH 1/9] Enable FFI module unconditionally. --- src/conf/janetconf.h | 4 ++-- src/include/janet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/conf/janetconf.h b/src/conf/janetconf.h index 13d7f4ff..73e39d55 100644 --- a/src/conf/janetconf.h +++ b/src/conf/janetconf.h @@ -6,8 +6,8 @@ #define JANET_VERSION_MAJOR 1 #define JANET_VERSION_MINOR 28 #define JANET_VERSION_PATCH 0 -#define JANET_VERSION_EXTRA "" -#define JANET_VERSION "1.28.0" +#define JANET_VERSION_EXTRA "-dev" +#define JANET_VERSION "1.28.0-dev" /* #define JANET_BUILD "local" */ diff --git a/src/include/janet.h b/src/include/janet.h index c88cd35c..941a6c35 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -182,7 +182,7 @@ extern "C" { /* Enable or disable the FFI library. Currently, FFI only enabled on * x86-64 operating systems. */ #ifndef JANET_NO_FFI -#if !defined(__EMSCRIPTEN__) && (defined(__x86_64__) || defined(_M_X64)) +#if !defined(__EMSCRIPTEN__) #define JANET_FFI #endif #endif From 88d0c2ca0f8102df3d18cc8cbf9076296a3952e6 Mon Sep 17 00:00:00 2001 From: Ico Doornekamp Date: Mon, 15 May 2023 12:15:36 +0200 Subject: [PATCH 2/9] add net/setsockopt --- src/core/net.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/src/core/net.c b/src/core/net.c index 8ebbdb53..8c911f92 100644 --- a/src/core/net.c +++ b/src/core/net.c @@ -872,6 +872,98 @@ JANET_CORE_FN(cfun_stream_flush, return argv[0]; } +struct sockopt_type { + const char *name; + int level; + int optname; + enum JanetType type; +}; + +// List of supported socket options; The type JANET_POINTER is used +// for options that require special handling depending on the type. +static const struct sockopt_type sockopt_type_list[] = { + { "SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, JANET_BOOLEAN }, + { "SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, JANET_BOOLEAN }, + { "SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, JANET_BOOLEAN }, + { "IP_MULTICAST_TTL", IPPROTO_IP, IP_MULTICAST_TTL, JANET_NUMBER }, + { "IP_ADD_MEMBERSHIP", IPPROTO_IP, IP_ADD_MEMBERSHIP, JANET_POINTER }, + { "IP_DROP_MEMBERSHIP", IPPROTO_IP, IP_DROP_MEMBERSHIP, JANET_POINTER }, + { "IPV6_JOIN_GROUP", IPPROTO_IPV6, IPV6_JOIN_GROUP, JANET_POINTER }, + { "IPV6_LEAVE_GROUP", IPPROTO_IPV6, IPV6_LEAVE_GROUP, JANET_POINTER }, + { NULL } +}; + +JANET_CORE_FN(cfun_net_setsockopt, + "(net/setsockopt stream option value)", + "set socket options.\n" + "\n" + "supported options and associated value types:\n" + "- :SO_BROADCAST boolean\n" + "- :SO_REUSEADDR boolean\n" + "- :SO_KEEPALIVE boolean\n" + "- :IP_MULTICAST_TTL number\n" + "- :IP_ADD_MEMBERSHIP string\n" + "- :IP_DROP_MEMBERSHIP string\n" + "- :IPV6_JOIN_GROUP string\n" + "- :IPV6_LEAVE_GROUP string\n") { + janet_arity(argc, 3, 3); + JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type); + janet_stream_flags(stream, JANET_STREAM_SOCKET); + JanetKeyword optstr = janet_getkeyword(argv, 1); + + const struct sockopt_type *st = sockopt_type_list; + while(st->name) { + if (janet_cstrcmp(optstr, st->name) == 0) { + break; + } + st++; + } + + if(st->name == NULL) { + janet_panicf("unknown socket option %q", argv[1]); + } + + union { + int v_int; + struct ip_mreq v_mreq; + struct ipv6_mreq v_mreq6; + } val; + + void *optval = (void *)&val; + socklen_t optlen = 0; + + if(st->type == JANET_BOOLEAN) { + val.v_int = janet_getboolean(argv, 2); + optlen = sizeof(val.v_int); + } else if(st->type == JANET_NUMBER) { + val.v_int = janet_getinteger(argv, 2); + optlen = sizeof(val.v_int); + } else if(st->optname == IP_ADD_MEMBERSHIP || st->optname == IP_DROP_MEMBERSHIP) { + const char *addr = janet_getcstring(argv, 2); + memset(&val.v_mreq, 0, sizeof val.v_mreq); + val.v_mreq.imr_interface.s_addr = htonl(INADDR_ANY); + val.v_mreq.imr_multiaddr.s_addr = inet_addr(addr); + optlen = sizeof(val.v_mreq); + } else if(st->optname == IPV6_JOIN_GROUP || st->optname == IPV6_LEAVE_GROUP) { + const char *addr = janet_getcstring(argv, 2); + memset(&val.v_mreq6, 0, sizeof val.v_mreq6); + val.v_mreq6.ipv6mr_interface = 0; + inet_pton(AF_INET6, addr, &val.v_mreq6.ipv6mr_multiaddr); + optlen = sizeof(val.v_mreq6); + } else { + janet_panicf("invalid socket option type"); + } + + janet_assert(optlen != 0, "invalid socket option value"); + + int r = setsockopt((JSock) stream->handle, st->level, st->optname, optval, optlen); + if(r == -1) { + janet_panicf("setsockopt(%q): %s", argv[1], strerror(errno)); + } + + return janet_wrap_nil(); +} + static const JanetMethod net_stream_methods[] = { {"chunk", cfun_stream_chunk}, {"close", janet_cfun_stream_close}, @@ -886,6 +978,7 @@ static const JanetMethod net_stream_methods[] = { {"evchunk", janet_cfun_stream_chunk}, {"evwrite", janet_cfun_stream_write}, {"shutdown", cfun_net_shutdown}, + {"setsockopt", cfun_net_setsockopt}, {NULL, NULL} }; @@ -910,6 +1003,7 @@ void janet_lib_net(JanetTable *env) { JANET_CORE_REG("net/peername", cfun_net_getpeername), JANET_CORE_REG("net/localname", cfun_net_getsockname), JANET_CORE_REG("net/address-unpack", cfun_net_address_unpack), + JANET_CORE_REG("net/setsockopt", cfun_net_setsockopt), JANET_REG_END }; janet_core_cfuns_ext(env, NULL, net_cfuns); From 68c35feaea4d2ad76c54593f0e4f3623f48da086 Mon Sep 17 00:00:00 2001 From: Ico Doornekamp Date: Mon, 15 May 2023 12:33:37 +0200 Subject: [PATCH 3/9] Formatting --- src/core/net.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/core/net.c b/src/core/net.c index 8c911f92..ac97554a 100644 --- a/src/core/net.c +++ b/src/core/net.c @@ -894,32 +894,32 @@ static const struct sockopt_type sockopt_type_list[] = { }; JANET_CORE_FN(cfun_net_setsockopt, - "(net/setsockopt stream option value)", - "set socket options.\n" - "\n" - "supported options and associated value types:\n" - "- :SO_BROADCAST boolean\n" - "- :SO_REUSEADDR boolean\n" - "- :SO_KEEPALIVE boolean\n" - "- :IP_MULTICAST_TTL number\n" - "- :IP_ADD_MEMBERSHIP string\n" - "- :IP_DROP_MEMBERSHIP string\n" - "- :IPV6_JOIN_GROUP string\n" - "- :IPV6_LEAVE_GROUP string\n") { + "(net/setsockopt stream option value)", + "set socket options.\n" + "\n" + "supported options and associated value types:\n" + "- :SO_BROADCAST boolean\n" + "- :SO_REUSEADDR boolean\n" + "- :SO_KEEPALIVE boolean\n" + "- :IP_MULTICAST_TTL number\n" + "- :IP_ADD_MEMBERSHIP string\n" + "- :IP_DROP_MEMBERSHIP string\n" + "- :IPV6_JOIN_GROUP string\n" + "- :IPV6_LEAVE_GROUP string\n") { janet_arity(argc, 3, 3); JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type); janet_stream_flags(stream, JANET_STREAM_SOCKET); JanetKeyword optstr = janet_getkeyword(argv, 1); const struct sockopt_type *st = sockopt_type_list; - while(st->name) { + while (st->name) { if (janet_cstrcmp(optstr, st->name) == 0) { break; } st++; } - if(st->name == NULL) { + if (st->name == NULL) { janet_panicf("unknown socket option %q", argv[1]); } @@ -932,19 +932,19 @@ JANET_CORE_FN(cfun_net_setsockopt, void *optval = (void *)&val; socklen_t optlen = 0; - if(st->type == JANET_BOOLEAN) { + if (st->type == JANET_BOOLEAN) { val.v_int = janet_getboolean(argv, 2); optlen = sizeof(val.v_int); - } else if(st->type == JANET_NUMBER) { + } else if (st->type == JANET_NUMBER) { val.v_int = janet_getinteger(argv, 2); optlen = sizeof(val.v_int); - } else if(st->optname == IP_ADD_MEMBERSHIP || st->optname == IP_DROP_MEMBERSHIP) { + } else if (st->optname == IP_ADD_MEMBERSHIP || st->optname == IP_DROP_MEMBERSHIP) { const char *addr = janet_getcstring(argv, 2); memset(&val.v_mreq, 0, sizeof val.v_mreq); val.v_mreq.imr_interface.s_addr = htonl(INADDR_ANY); val.v_mreq.imr_multiaddr.s_addr = inet_addr(addr); optlen = sizeof(val.v_mreq); - } else if(st->optname == IPV6_JOIN_GROUP || st->optname == IPV6_LEAVE_GROUP) { + } else if (st->optname == IPV6_JOIN_GROUP || st->optname == IPV6_LEAVE_GROUP) { const char *addr = janet_getcstring(argv, 2); memset(&val.v_mreq6, 0, sizeof val.v_mreq6); val.v_mreq6.ipv6mr_interface = 0; @@ -957,7 +957,7 @@ JANET_CORE_FN(cfun_net_setsockopt, janet_assert(optlen != 0, "invalid socket option value"); int r = setsockopt((JSock) stream->handle, st->level, st->optname, optval, optlen); - if(r == -1) { + if (r == -1) { janet_panicf("setsockopt(%q): %s", argv[1], strerror(errno)); } From ab8c5a0b5fff91ade10772ad8aa52ca0eb2338df Mon Sep 17 00:00:00 2001 From: Ico Doornekamp Date: Mon, 15 May 2023 15:25:09 +0200 Subject: [PATCH 4/9] net/setsockopt optname symbols are now lower case --- src/core/net.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/core/net.c b/src/core/net.c index ac97554a..32319305 100644 --- a/src/core/net.c +++ b/src/core/net.c @@ -882,14 +882,14 @@ struct sockopt_type { // List of supported socket options; The type JANET_POINTER is used // for options that require special handling depending on the type. static const struct sockopt_type sockopt_type_list[] = { - { "SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, JANET_BOOLEAN }, - { "SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, JANET_BOOLEAN }, - { "SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, JANET_BOOLEAN }, - { "IP_MULTICAST_TTL", IPPROTO_IP, IP_MULTICAST_TTL, JANET_NUMBER }, - { "IP_ADD_MEMBERSHIP", IPPROTO_IP, IP_ADD_MEMBERSHIP, JANET_POINTER }, - { "IP_DROP_MEMBERSHIP", IPPROTO_IP, IP_DROP_MEMBERSHIP, JANET_POINTER }, - { "IPV6_JOIN_GROUP", IPPROTO_IPV6, IPV6_JOIN_GROUP, JANET_POINTER }, - { "IPV6_LEAVE_GROUP", IPPROTO_IPV6, IPV6_LEAVE_GROUP, JANET_POINTER }, + { "so_broadcast", SOL_SOCKET, SO_BROADCAST, JANET_BOOLEAN }, + { "so_reuseaddr", SOL_SOCKET, SO_REUSEADDR, JANET_BOOLEAN }, + { "so_keepalive", SOL_SOCKET, SO_KEEPALIVE, JANET_BOOLEAN }, + { "ip_multicast_ttl", IPPROTO_IP, IP_MULTICAST_TTL, JANET_NUMBER }, + { "ip_add_membership", IPPROTO_IP, IP_ADD_MEMBERSHIP, JANET_POINTER }, + { "ip_drop_membership", IPPROTO_IP, IP_DROP_MEMBERSHIP, JANET_POINTER }, + { "ipv6_join_group", IPPROTO_IPV6, IPV6_JOIN_GROUP, JANET_POINTER }, + { "ipv6_leave_group", IPPROTO_IPV6, IPV6_LEAVE_GROUP, JANET_POINTER }, { NULL } }; @@ -898,14 +898,14 @@ JANET_CORE_FN(cfun_net_setsockopt, "set socket options.\n" "\n" "supported options and associated value types:\n" - "- :SO_BROADCAST boolean\n" - "- :SO_REUSEADDR boolean\n" - "- :SO_KEEPALIVE boolean\n" - "- :IP_MULTICAST_TTL number\n" - "- :IP_ADD_MEMBERSHIP string\n" - "- :IP_DROP_MEMBERSHIP string\n" - "- :IPV6_JOIN_GROUP string\n" - "- :IPV6_LEAVE_GROUP string\n") { + "- :so_broadcast boolean\n" + "- :so_reuseaddr boolean\n" + "- :so_keepalive boolean\n" + "- :ip_multicast_ttl number\n" + "- :ip_add_membership string\n" + "- :ip_drop_membership string\n" + "- :ipv6_join_group string\n" + "- :ipv6_leave_group string\n") { janet_arity(argc, 3, 3); JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type); janet_stream_flags(stream, JANET_STREAM_SOCKET); From 2a6c615becc2268ec1ea52b80a1cea5e86cb778a Mon Sep 17 00:00:00 2001 From: Ico Doornekamp Date: Mon, 15 May 2023 16:55:09 +0200 Subject: [PATCH 5/9] features.h: define _DARWIN_C_SOURCE for __APPLE__ --- src/core/features.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/features.h b/src/core/features.h index 0adb136a..f2522500 100644 --- a/src/core/features.h +++ b/src/core/features.h @@ -36,6 +36,10 @@ # endif #endif +#if defined(__APPLE__) +#define _DARWIN_C_SOURCE +#endif + /* Needed for sched.h for cpu count */ #ifdef __linux__ #define _GNU_SOURCE From ac5f1fe1bea045064893950f167f312f8a290ac1 Mon Sep 17 00:00:00 2001 From: Ico Doornekamp Date: Tue, 16 May 2023 19:44:31 +0200 Subject: [PATCH 6/9] enable debug symbols in janet binary; strip target at 'make instal' --- Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f2432311..50d759a8 100644 --- a/Makefile +++ b/Makefile @@ -47,11 +47,11 @@ SONAME_SETTER=-Wl,-soname, HOSTCC?=$(CC) HOSTAR?=$(AR) CFLAGS?=-O2 -LDFLAGS?=-rdynamic +LDFLAGS?=-rdynamic -g RUN:=$(RUN) -COMMON_CFLAGS:=-std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -BOOT_CFLAGS:=-DJANET_BOOTSTRAP -DJANET_BUILD=$(JANET_BUILD) -O0 -g $(COMMON_CFLAGS) +COMMON_CFLAGS:=-std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g +BOOT_CFLAGS:=-DJANET_BOOTSTRAP -DJANET_BUILD=$(JANET_BUILD) -O0 $(COMMON_CFLAGS) BUILD_CFLAGS:=$(CFLAGS) $(COMMON_CFLAGS) # For installation @@ -223,7 +223,7 @@ repl: $(JANET_TARGET) debug: $(JANET_TARGET) $(DEBUGGER) ./$(JANET_TARGET) -VALGRIND_COMMAND=valgrind --leak-check=full +VALGRIND_COMMAND=valgrind --leak-check=full --quiet valgrind: $(JANET_TARGET) $(VALGRIND_COMMAND) ./$(JANET_TARGET) @@ -293,6 +293,7 @@ build/janet.pc: $(JANET_TARGET) install: $(JANET_TARGET) $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) build/janet.pc build/janet.h mkdir -p '$(DESTDIR)$(BINDIR)' cp $(JANET_TARGET) '$(DESTDIR)$(BINDIR)/janet' + strip '$(DESTDIR)$(BINDIR)/janet' mkdir -p '$(DESTDIR)$(INCLUDEDIR)/janet' cp -r build/janet.h '$(DESTDIR)$(INCLUDEDIR)/janet' ln -sf -T ./janet/janet.h '$(DESTDIR)$(INCLUDEDIR)/janet.h' || true #fixme bsd From d6f5a060ed9d1d88977595b50031f267eabe09bf Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Tue, 16 May 2023 21:00:31 -0500 Subject: [PATCH 7/9] Squashed commit of the following: commit 725b8749464895e21c761f1c5479692335282f62 Author: Calvin Rose Date: Tue May 16 20:58:34 2023 -0500 Update header file. commit 38bf2a5131694cc8f6c7ee2a7e70c768dc51f68f Author: Calvin Rose Date: Tue May 16 19:43:22 2023 -0500 Run experiment on bsd. --- src/core/features.h | 5 +++-- src/core/net.c | 38 +++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/core/features.h b/src/core/features.h index f2522500..46caff58 100644 --- a/src/core/features.h +++ b/src/core/features.h @@ -26,9 +26,10 @@ #define JANET_FEATURES_H_defined #if defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__) \ - || defined(__bsdi__) || defined(__DragonFly__) + || defined(__bsdi__) || defined(__DragonFly__) || defined(__FreeBSD__) /* Use BSD source on any BSD systems, include OSX */ # define _BSD_SOURCE +# define _POSIX_C_SOURCE 200809L #else /* Use POSIX feature flags */ # ifndef _POSIX_C_SOURCE @@ -66,7 +67,7 @@ #endif /* Needed for several things when building with -std=c99. */ -#if !__BSD_VISIBLE && defined(__DragonFly__) +#if !__BSD_VISIBLE && (defined(__DragonFly__) || defined(__FreeBSD__)) #define __BSD_VISIBLE 1 #endif diff --git a/src/core/net.c b/src/core/net.c index 32319305..843f36f8 100644 --- a/src/core/net.c +++ b/src/core/net.c @@ -879,18 +879,18 @@ struct sockopt_type { enum JanetType type; }; -// List of supported socket options; The type JANET_POINTER is used -// for options that require special handling depending on the type. +/* List of supported socket options; The type JANET_POINTER is used + * for options that require special handling depending on the type. */ static const struct sockopt_type sockopt_type_list[] = { - { "so_broadcast", SOL_SOCKET, SO_BROADCAST, JANET_BOOLEAN }, - { "so_reuseaddr", SOL_SOCKET, SO_REUSEADDR, JANET_BOOLEAN }, - { "so_keepalive", SOL_SOCKET, SO_KEEPALIVE, JANET_BOOLEAN }, - { "ip_multicast_ttl", IPPROTO_IP, IP_MULTICAST_TTL, JANET_NUMBER }, - { "ip_add_membership", IPPROTO_IP, IP_ADD_MEMBERSHIP, JANET_POINTER }, - { "ip_drop_membership", IPPROTO_IP, IP_DROP_MEMBERSHIP, JANET_POINTER }, - { "ipv6_join_group", IPPROTO_IPV6, IPV6_JOIN_GROUP, JANET_POINTER }, - { "ipv6_leave_group", IPPROTO_IPV6, IPV6_LEAVE_GROUP, JANET_POINTER }, - { NULL } + { "so-broadcast", SOL_SOCKET, SO_BROADCAST, JANET_BOOLEAN }, + { "so-reuseaddr", SOL_SOCKET, SO_REUSEADDR, JANET_BOOLEAN }, + { "so-keepalive", SOL_SOCKET, SO_KEEPALIVE, JANET_BOOLEAN }, + { "ip-multicast-ttl", IPPROTO_IP, IP_MULTICAST_TTL, JANET_NUMBER }, + { "ip-add-membership", IPPROTO_IP, IP_ADD_MEMBERSHIP, JANET_POINTER }, + { "ip-drop-membership", IPPROTO_IP, IP_DROP_MEMBERSHIP, JANET_POINTER }, + { "ipv6-join-group", IPPROTO_IPV6, IPV6_JOIN_GROUP, JANET_POINTER }, + { "ipv6-leave-group", IPPROTO_IPV6, IPV6_LEAVE_GROUP, JANET_POINTER }, + { NULL, 0, 0, JANET_POINTER } }; JANET_CORE_FN(cfun_net_setsockopt, @@ -898,14 +898,14 @@ JANET_CORE_FN(cfun_net_setsockopt, "set socket options.\n" "\n" "supported options and associated value types:\n" - "- :so_broadcast boolean\n" - "- :so_reuseaddr boolean\n" - "- :so_keepalive boolean\n" - "- :ip_multicast_ttl number\n" - "- :ip_add_membership string\n" - "- :ip_drop_membership string\n" - "- :ipv6_join_group string\n" - "- :ipv6_leave_group string\n") { + "- :so-broadcast boolean\n" + "- :so-reuseaddr boolean\n" + "- :so-keepalive boolean\n" + "- :ip-multicast-ttl number\n" + "- :ip-add-membership string\n" + "- :ip-drop-membership string\n" + "- :ipv6-join-group string\n" + "- :ipv6-leave-group string\n") { janet_arity(argc, 3, 3); JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type); janet_stream_flags(stream, JANET_STREAM_SOCKET); From 148917d4caa79784fb00905bbb4b807e4964b05b Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Tue, 16 May 2023 21:10:18 -0500 Subject: [PATCH 8/9] Move -g to CFLAGS to make it easier to remove/customize --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 50d759a8..f5595310 100644 --- a/Makefile +++ b/Makefile @@ -46,11 +46,11 @@ SONAME_SETTER=-Wl,-soname, # For cross compilation HOSTCC?=$(CC) HOSTAR?=$(AR) -CFLAGS?=-O2 -LDFLAGS?=-rdynamic -g +CFLAGS?=-O2 -g +LDFLAGS?=-rdynamic RUN:=$(RUN) -COMMON_CFLAGS:=-std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g +COMMON_CFLAGS:=-std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC BOOT_CFLAGS:=-DJANET_BOOTSTRAP -DJANET_BUILD=$(JANET_BUILD) -O0 $(COMMON_CFLAGS) BUILD_CFLAGS:=$(CFLAGS) $(COMMON_CFLAGS) From a6a097c111eb4087389ce73050c847bdd1175e7f Mon Sep 17 00:00:00 2001 From: Ico Doornekamp Date: Thu, 18 May 2023 14:20:38 +0200 Subject: [PATCH 9/9] Add CI test for mingw/wine on linux --- .github/workflows/test.yml | 17 +++++++++++++++++ src/core/features.h | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6dde896c..c620c513 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,3 +57,20 @@ jobs: - name: Build the project shell: cmd run: make -j CC=gcc + + test-mingw-linux: + name: Build and test with Mingw on Linux + Wine + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@master + - name: Setup Mingw and wine + run: | + sudo dpkg --add-architecture i386 + sudo apt-get update + sudo apt-get install libstdc++6:i386 libgcc-s1:i386 + sudo apt-get install gcc-mingw-w64-x86-64-win32 wine wine32 wine64 + - name: Compile the project + run: make clean && make CC=x86_64-w64-mingw32-gcc LD=x86_64-w64-mingw32-gcc UNAME=MINGW RUN=wine + - name: Test the project + run: make test UNAME=MINGW RUN=wine diff --git a/src/core/features.h b/src/core/features.h index 46caff58..b3e1f752 100644 --- a/src/core/features.h +++ b/src/core/features.h @@ -50,6 +50,11 @@ #define WIN32_LEAN_AND_MEAN #endif +/* needed for inet_pton and InitializeSRWLock */ +#ifdef __MINGW32__ +#define _WIN32_WINNT _WIN32_WINNT_VISTA +#endif + /* Needed for realpath on linux, as well as pthread rwlocks. */ #ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 600