Skip to content

Commit 4398d61

Browse files
Merge pull request #134 from jclc/fix/disable-packet-tagging-on-mingw
Disable packet tagging on MingW by default, fix TLS qualifier
2 parents eb88bae + bdedb6a commit 4398d61

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-3
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,40 @@ jobs:
5151
- name: Test (vs2019)
5252
if: runner.os == 'Windows'
5353
run: "& ./bin/test.exe"
54-
54+
55+
build_and_test_mingw:
56+
name: Build & test (MingW)
57+
58+
strategy:
59+
matrix:
60+
os: [windows-latest]
61+
configuration: [release, debug]
62+
63+
runs-on: ${{ matrix.os }}
64+
65+
defaults:
66+
run:
67+
shell: msys2 {0}
68+
69+
steps:
70+
- uses: actions/checkout@master
71+
72+
# Set up msys2/MingW-w64 toolchain
73+
- name: Setup (msys2)
74+
uses: msys2/setup-msys2@v2
75+
with:
76+
msystem: UCRT64
77+
update: true
78+
install: >-
79+
mingw-w64-ucrt-x86_64-make
80+
mingw-w64-ucrt-x86_64-premake
81+
mingw-w64-ucrt-x86_64-gcc
82+
83+
- name: Build (msys2)
84+
run: |
85+
premake5 gmake
86+
mingw32-make clean
87+
mingw32-make all config=${{ matrix.configuration }}
88+
89+
- name: Test (msys2)
90+
run: "./bin/test.exe"

netcode.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ void netcode_enable_packet_tagging()
8282
netcode_packet_tagging_enabled = 1;
8383
}
8484

85+
#else
86+
87+
void netcode_enable_packet_tagging() {}
88+
8589
#endif // #if NETCODE_PACKET_TAGGING
8690

8791
// ------------------------------------------------------------------
@@ -157,22 +161,28 @@ void netcode_default_free_function( void * context, void * pointer )
157161

158162
#if NETCODE_PLATFORM == NETCODE_PLATFORM_WINDOWS
159163

164+
#ifndef NOMINMAX
160165
#define NOMINMAX
166+
#endif // #ifndef NOMINMAX
161167
#define _WINSOCK_DEPRECATED_NO_WARNINGS
162168
#include <winsock2.h>
163169
#include <ws2def.h>
164170
#include <ws2tcpip.h>
165171
#include <ws2ipdef.h>
166172
#include <iphlpapi.h>
173+
#ifdef _MSC_VER
167174
#pragma comment( lib, "WS2_32.lib" )
168175
#pragma comment( lib, "IPHLPAPI.lib" )
176+
#endif // #ifdef _MSC_VER
169177

170178
#ifdef SetPort
171179
#undef SetPort
172180
#endif // #ifdef SetPort
173181

174182
#include <iphlpapi.h>
183+
#ifdef _MSC_VER
175184
#pragma comment( lib, "IPHLPAPI.lib" )
185+
#endif // #ifdef _MSC_VER
176186

177187
#elif NETCODE_PLATFORM == NETCODE_PLATFORM_MAC || NETCODE_PLATFORM == NETCODE_PLATFORM_UNIX
178188

@@ -478,7 +488,9 @@ typedef UINT32 QOS_FLOWID, *PQOS_FLOWID;
478488
#endif // #ifdef __MINGW32__
479489
#include <qos2.h>
480490

491+
#ifdef _MSC_VER
481492
#pragma comment( lib, "Qwave.lib" )
493+
#endif // #ifdef _MSC_VER
482494

483495
static int netcode_set_socket_codepoint( SOCKET socket, QOS_TRAFFIC_TYPE trafficType, QOS_FLOWID flowId, PSOCKADDR addr )
484496
{
@@ -5217,7 +5229,9 @@ double netcode_time()
52175229

52185230
// windows
52195231

5232+
#ifndef NOMINMAX
52205233
#define NOMINMAX
5234+
#endif // #ifndef NOMINMAX
52215235
#include <windows.h>
52225236

52235237
void netcode_sleep( double time )

netcode.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,16 @@ int netcode_init();
113113
void netcode_term();
114114

115115
#ifndef NETCODE_PACKET_TAGGING
116+
#ifndef __MINGW32__
116117
#define NETCODE_PACKET_TAGGING 1
118+
#else
119+
// At least as of version 14.2.0, the Qwave library is not properly implemented
120+
// in MingW-w64, so packet tagging is disabled by default.
121+
#define NETCODE_PACKET_TAGGING 0
122+
#endif // #ifndef __MINGW32__
117123
#endif // #ifndef NETCODE_PACKET_TAGGING
118124

119-
#if NETCODE_PACKET_TAGGING
120125
void netcode_enable_packet_tagging();
121-
#endif // #if NETCODE_PACKET_TAGGING
122126

123127
struct netcode_address_t
124128
{

premake5.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,38 @@ project "sodium"
3535
project "test"
3636
files { "test.cpp" }
3737
links { "sodium" }
38+
filter { "action:gmake*", "system:windows" }
39+
links { "ws2_32", "iphlpapi" }
3840

3941
project "soak"
4042
files { "soak.c", "netcode.c" }
4143
links { "sodium" }
44+
filter { "action:gmake*", "system:windows" }
45+
links { "ws2_32", "iphlpapi" }
4246

4347
project "profile"
4448
files { "profile.c", "netcode.c" }
4549
links { "sodium" }
50+
filter { "action:gmake*", "system:windows" }
51+
links { "ws2_32", "iphlpapi" }
4652

4753
project "client"
4854
files { "client.c", "netcode.c" }
4955
links { "sodium" }
56+
filter { "action:gmake*", "system:windows" }
57+
links { "ws2_32", "iphlpapi" }
5058

5159
project "server"
5260
files { "server.c", "netcode.c" }
5361
links { "sodium" }
62+
filter { "action:gmake*", "system:windows" }
63+
links { "ws2_32", "iphlpapi" }
5464

5565
project "client_server"
5666
files { "client_server.c", "netcode.c" }
5767
links { "sodium" }
68+
filter { "action:gmake*", "system:windows" }
69+
links { "ws2_32", "iphlpapi" }
5870

5971
newaction
6072
{

sodium/sodium_randombytes_salsa20_random.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength);
8989
# endif
9090
#endif
9191

92+
#if !defined(TLS) && !defined(__STDC_NO_THREADS__) && \
93+
defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
94+
# define TLS _Thread_local
95+
#endif
9296
#ifndef TLS
9397
# ifdef _WIN32
9498
# define TLS __declspec(thread)

0 commit comments

Comments
 (0)