Update tpt-libs, add support for compiling with MinGW on Windows

This commit is contained in:
Tamás Bálint Misius 2021-10-22 16:38:42 +02:00
parent 6653080400
commit 5582d6881d
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
26 changed files with 241 additions and 81 deletions

9
.github/build.sh vendored
View File

@ -33,7 +33,7 @@ if [ -z "${MOD_ID-}" ]; then
fi
if [ -z "${build_sh_init-}" ]; then
if [ $PLATFORM_SHORT == "win" ]; then
if [ $TOOLSET_SHORT == "msvc" ]; then
for i in C:/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/**/**/VC/Auxiliary/Build/vcvarsall.bat; do
vcvarsall_path=$i
done
@ -103,7 +103,12 @@ fi
if [ "$RELTYPE" != "dev" ]; then
other_flags+=$'\t-Dignore_updates=false'
fi
meson -Dbuildtype=release -Db_pie=false -Db_staticpic=false -Db_lto=true $static_flag -Dinstall_check=true $other_flags build
lto_flag=-Db_lto=true
if [ $TOOLSET_SHORT == "mingw" ]; then
# This simply doesn't work with MinGW. I have no idea why and I also don't care.
lto_flag=
fi
meson -Dbuildtype=release -Db_pie=false -Db_staticpic=false $lto_flag $static_flag -Dinstall_check=true $other_flags build
cd build
ninja
if [ $PLATFORM_SHORT == "lin" ] || [ $PLATFORM_SHORT == "mac" ]; then

View File

@ -48,13 +48,13 @@ jobs:
# --------------+------------+------------+------------+------------+------------+------------+
# gcc-static | | | NO | NO | NO | NO |
# msvc-static | NO | NO | | NO | NO | |
# mingw-static | NO | NO | NO | NO | NO | NO [1] |
# mingw-static | NO | NO | | NO | NO | NO |
# gcc-dynamic | | | NO | NO | NO | NO |
# msvc-dynamic | NO | NO | | NO | NO | |
# mingw-dynamic | NO | NO | NO | NO | NO | NO |
# mingw-dynamic | NO | NO | | NO | NO | NO |
#
# [1] I don't currently care enough about mingw to figure out how to do this.
# Please keep this matrix in sync with the other one in this file, see the ### blocks.
# The only difference should be that the second matrix has all mingw cells disabled; we don't publish mingw builds on starcatcher.
#########################################################
############# BEGIN BLOCK FOR COPYING BELOW #############
#########################################################
@ -64,6 +64,11 @@ jobs:
static_dynamic: [static, dynamic]
exclude:
- toolset_short: mingw
machine_short: i686 # remove this line after copying the matrix below
- toolset_short: mingw # remove this line after copying the matrix below
platform_short: lin # remove this line after copying the matrix below
- toolset_short: mingw # remove this line after copying the matrix below
platform_short: mac # remove this line after copying the matrix below
- machine_short: i686
platform_short: lin
- machine_short: i686
@ -82,10 +87,10 @@ jobs:
os: ubuntu-18.04
suffix: ''
- platform_short: mac
os: macos-latest
os: macos-10.15
suffix: ''
- platform_short: win
os: windows-latest
os: windows-2019
suffix: '.exe'
steps:
- uses: actions/checkout@v2

View File

@ -53,7 +53,7 @@ endif
uopt_static = get_option('static')
use_tpt_libs = 'no'
tpt_libs_vtag = 'v20210822114001'
tpt_libs_vtag = 'v20211022224519'
if uopt_static == 'system'
if copt_platform == 'win'
error('no way to find static system libraries on windows')
@ -67,22 +67,21 @@ else
endif
if use_tpt_libs != 'no'
nope = false
if copt_architecture == 'i686' and (copt_platform != 'win' or copt_compiler != 'msvc')
if copt_architecture == 'i686' and not copt_msvc
nope = true
endif
if copt_architecture == 'x86_64' and (copt_platform == 'lin' or copt_platform == 'mac') and copt_compiler != 'gcc'
nope = true
endif
if copt_architecture == 'x86_64' and copt_platform == 'win' and copt_compiler == 'gcc'
nope = true
quad_compiler = copt_compiler
if copt_platform == 'win' and copt_compiler == 'gcc'
quad_compiler = 'mingw'
if get_option('b_lto')
error('mingw does not like static + lto, you will have to disable this error if you want to proceed')
endif
endif
if nope
error('no prebuilt @0@-@1@-@2@-@3@ libraries are currently provided'.format(copt_architecture, copt_platform, copt_compiler, use_tpt_libs))
endif
quad_compiler = copt_compiler
if use_tpt_libs == 'dynamic' and copt_platform == 'win'
# DLLs should be compatible with anything, right?
quad_compiler = 'msvc'
error('no prebuilt @0@-@1@-@2@-@3@ libraries are currently provided'.format(copt_architecture, copt_platform, quad_compiler, use_tpt_libs))
endif
tpt_libs = subproject('tpt-libs-prebuilt-@0@-@1@-@2@-@3@-@4@'.format(copt_architecture, copt_platform, quad_compiler, use_tpt_libs, tpt_libs_vtag))
endif
@ -201,6 +200,15 @@ else
args_ccomp += [ '-march=native' ]
endif
endif
if copt_platform == 'win'
args_ccomp += [
'-DUNICODE',
'-D_UNICODE',
]
if uopt_static != 'none'
project_link_args = [ '-static', '-static-libgcc', '-static-libstdc++' ]
endif
endif
if not get_option('debug')
args_ccomp += [
'-ftree-vectorize',

View File

@ -12,15 +12,17 @@
#include <cstdint>
#ifdef WIN
#define NOMINMAX
#include <windows.h>
# ifndef NOMINMAX
# define NOMINMAX
# endif
# include <windows.h>
#else
#include <unistd.h>
#include <sys/stat.h>
# include <unistd.h>
# include <sys/stat.h>
#endif
#ifdef MACOSX
#include <mach-o/dyld.h>
#include <errno.h>
# include <mach-o/dyld.h>
# include <errno.h>
#endif
#include "common/Platform.h"

View File

@ -15,15 +15,17 @@
#endif
#ifdef WIN
#define NOMINMAX
#include <shlobj.h>
#include <objidl.h>
#include <shlwapi.h>
#include <windows.h>
#include <direct.h>
# ifndef NOMINMAX
# define NOMINMAX
# endif
# include <shlobj.h>
# include <objidl.h>
# include <shlwapi.h>
# include <windows.h>
# include <direct.h>
#else
#include <sys/stat.h>
#include <unistd.h>
# include <sys/stat.h>
# include <unistd.h>
#endif
#include "ClientListener.h"

View File

@ -9,20 +9,22 @@
#include <sys/stat.h>
#ifdef WIN
#define NOMINMAX
#include <direct.h>
#include <io.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <shellapi.h>
#include <windows.h>
# ifndef NOMINMAX
# define NOMINMAX
# endif
# include <direct.h>
# include <io.h>
# include <shlobj.h>
# include <shlwapi.h>
# include <shellapi.h>
# include <windows.h>
#else
#include <unistd.h>
#include <ctime>
#include <sys/time.h>
# include <unistd.h>
# include <ctime>
# include <sys/time.h>
#endif
#ifdef MACOSX
#include <mach-o/dyld.h>
# include <mach-o/dyld.h>
#endif
#include "Misc.h"

View File

@ -4,6 +4,7 @@
#include <limits>
#include <stdexcept>
#include "common/tpt-thread-local.h"
#include "String.h"
ByteString ConversionError::formatError(ByteString::value_type const *at, ByteString::value_type const *upto)
@ -375,7 +376,7 @@ struct LocaleImpl
static LocaleImpl *getLocaleImpl()
{
thread_local LocaleImpl li;
static THREAD_LOCAL(LocaleImpl, li);
return &li;
}

View File

@ -2,4 +2,5 @@ common_files += files(
'Platform.cpp',
'String.cpp',
'tpt-rand.cpp',
'tpt-thread-local.cpp',
)

View File

@ -0,0 +1,79 @@
#include "tpt-thread-local.h"
#ifdef __MINGW32__
# include <pthread.h>
# include <cstdlib>
# include <cassert>
static pthread_once_t once = PTHREAD_ONCE_INIT;
static pthread_key_t key;
struct ThreadLocalCommon
{
size_t size;
void (*ctor)(void *);
void (*dtor)(void *);
size_t padding;
};
static_assert(sizeof(ThreadLocalCommon) == 0x20, "fix me");
struct ThreadLocalEntry
{
void *ptr;
};
// https://stackoverflow.com/questions/16552710/how-do-you-get-the-start-and-end-addresses-of-a-custom-elf-section
extern ThreadLocalCommon __start_tpt_tls;
extern ThreadLocalCommon __stop_tpt_tls;
static void ThreadLocalDestroy(void *opaque)
{
auto *staticsBegin = &__start_tpt_tls;
auto *staticsEnd = &__stop_tpt_tls;
auto staticsCount = staticsEnd - staticsBegin;
auto *liveObjects = reinterpret_cast<ThreadLocalEntry *>(opaque);
if (liveObjects)
{
for (auto i = 0; i < staticsCount; ++i)
{
if (liveObjects[i].ptr)
{
staticsBegin[i].dtor(liveObjects[i].ptr);
free(liveObjects[i].ptr);
}
}
free(liveObjects);
}
}
static void ThreadLocalCreate()
{
assert(!pthread_key_create(&key, ThreadLocalDestroy));
}
void *ThreadLocalGet(void *opaque)
{
auto *staticsBegin = &__start_tpt_tls;
auto *staticsEnd = &__stop_tpt_tls;
auto *staticsOpaque = reinterpret_cast<ThreadLocalCommon *>(opaque);
pthread_once(&once, ThreadLocalCreate);
auto *liveObjects = reinterpret_cast<ThreadLocalEntry *>(pthread_getspecific(key));
if (!liveObjects)
{
auto staticsCount = staticsEnd - staticsBegin;
liveObjects = reinterpret_cast<ThreadLocalEntry *>(calloc(staticsCount, sizeof(ThreadLocalEntry)));
assert(liveObjects);
assert(!pthread_setspecific(key, reinterpret_cast<void *>(liveObjects)));
}
auto idx = staticsOpaque - staticsBegin;
auto &entry = liveObjects[idx];
if (!entry.ptr)
{
entry.ptr = malloc(staticsBegin[idx].size);
assert(entry.ptr);
staticsBegin[idx].ctor(entry.ptr);
}
return entry.ptr;
}
#endif

View File

@ -0,0 +1,42 @@
#pragma once
#include "Config.h"
#ifdef __MINGW32__
# include <cstddef>
template<class Type>
class ThreadLocal
{
static void Ctor(Type *type)
{
new (type) Type();
}
static void Dtor(Type *type)
{
type->~Type();
}
size_t size = sizeof(Type);
void (*ctor)(Type *) = Ctor;
void (*dtor)(Type *) = Dtor;
size_t padding;
public:
Type *operator &()
{
static_assert(sizeof(ThreadLocal<Type>) == 0x20, "fix me");
void *ThreadLocalGet(void *opaque);
return reinterpret_cast<Type *>(ThreadLocalGet(reinterpret_cast<void *>(this)));
}
operator Type &()
{
return *(this->operator &());
}
};
# define THREAD_LOCAL(Type, tl) ThreadLocal<Type> tl __attribute__((section("tpt_tls"))) __attribute__((aligned(0x20)))
#else
# define THREAD_LOCAL(Type, tl) thread_local Type tl
#endif

View File

@ -1,5 +1,6 @@
#include "UpdateActivity.h"
#include "client/http/Request.h"
#include "bzip2/bzlib.h"
#include "Config.h"
@ -10,7 +11,6 @@
#include "tasks/Task.h"
#include "tasks/TaskWindow.h"
#include "client/http/Request.h"
#include "gui/dialogues/ConfirmPrompt.h"
#include "gui/interface/Engine.h"

View File

@ -29,6 +29,7 @@
#include "common/tpt-compat.h"
#include "common/tpt-minmax.h"
#include "common/tpt-rand.h"
#include "common/tpt-thread-local.h"
#include "gui/game/Brush.h"
#ifdef LUACONSOLE
@ -667,7 +668,7 @@ bool Simulation::FloodFillPmapCheck(int x, int y, int type)
CoordStack& Simulation::getCoordStackSingleton()
{
// Future-proofing in case Simulation is later multithreaded
thread_local CoordStack cs;
static THREAD_LOCAL(CoordStack, cs);
return cs;
}

View File

@ -1,6 +0,0 @@
[wrap-file]
directory = tpt-libs-prebuilt-i686-win-msvc-dynamic-v20210822114001
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20210822114001/tpt-libs-prebuilt-i686-win-msvc-dynamic-v20210822114001.zip
source_filename = tpt-libs-prebuilt-i686-win-msvc-dynamic-v20210822114001.zip
source_hash = 343f5674768ea3fa8d23626d905fa17bf3cbfca1a184c087d006742419f874e1

View File

@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-i686-win-msvc-dynamic-v20211022224519
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20211022224519/tpt-libs-prebuilt-i686-win-msvc-dynamic-v20211022224519.zip
source_filename = tpt-libs-prebuilt-i686-win-msvc-dynamic-v20211022224519.zip
source_hash = 0e05374cec73600254982af6c8faeae93a7b7d5ea36553d0c2d15bb6684005d1

View File

@ -1,6 +0,0 @@
[wrap-file]
directory = tpt-libs-prebuilt-i686-win-msvc-static-v20210822114001
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20210822114001/tpt-libs-prebuilt-i686-win-msvc-static-v20210822114001.zip
source_filename = tpt-libs-prebuilt-i686-win-msvc-static-v20210822114001.zip
source_hash = c990f46a8ec586e8f7e5ffcb20e0247d594308192a9aa80e85233bd69015a20a

View File

@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-i686-win-msvc-static-v20211022224519
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20211022224519/tpt-libs-prebuilt-i686-win-msvc-static-v20211022224519.zip
source_filename = tpt-libs-prebuilt-i686-win-msvc-static-v20211022224519.zip
source_hash = 681d23de72148efc25f78c758fe51e543c54459741f597221cf76f38dfd0b606

View File

@ -1,6 +0,0 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-lin-gcc-static-v20210822114001
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20210822114001/tpt-libs-prebuilt-x86_64-lin-gcc-static-v20210822114001.zip
source_filename = tpt-libs-prebuilt-x86_64-lin-gcc-static-v20210822114001.zip
source_hash = 209790fa0fff376134b0479806b8a1943f8334517a182f6152e05c9a1d2c4f06

View File

@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-lin-gcc-static-v20211022224519
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20211022224519/tpt-libs-prebuilt-x86_64-lin-gcc-static-v20211022224519.zip
source_filename = tpt-libs-prebuilt-x86_64-lin-gcc-static-v20211022224519.zip
source_hash = 9b04f5f3d8a0912970cfe1bf3445005a930f9a3e5403a2815d9f6280125350f0

View File

@ -1,6 +0,0 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-mac-gcc-static-v20210822114001
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20210822114001/tpt-libs-prebuilt-x86_64-mac-gcc-static-v20210822114001.zip
source_filename = tpt-libs-prebuilt-x86_64-mac-gcc-static-v20210822114001.zip
source_hash = 9547334e8d13edeb5c494ce6d3d7deee343553aaad4ec52c624972e436aef21d

View File

@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-mac-gcc-static-v20211022224519
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20211022224519/tpt-libs-prebuilt-x86_64-mac-gcc-static-v20211022224519.zip
source_filename = tpt-libs-prebuilt-x86_64-mac-gcc-static-v20211022224519.zip
source_hash = 946f3ae27a5f8b28f6abe2486f6ecc36ba96408fd61ee81a3e2985eb30b02dd7

View File

@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-win-mingw-dynamic-v20211022224519
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20211022224519/tpt-libs-prebuilt-x86_64-win-mingw-dynamic-v20211022224519.zip
source_filename = tpt-libs-prebuilt-x86_64-win-mingw-dynamic-v20211022224519.zip
source_hash = 72b4c8bcdfe37861326999d394f7fa10093961e2e5de9d59a41a8e323ba009f7

View File

@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-win-mingw-static-v20211022224519
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20211022224519/tpt-libs-prebuilt-x86_64-win-mingw-static-v20211022224519.zip
source_filename = tpt-libs-prebuilt-x86_64-win-mingw-static-v20211022224519.zip
source_hash = fc0abc52e15f6f3b919fd793a03503e7c1a69465318be9659576f1dfca9ffbd2

View File

@ -1,6 +0,0 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-win-msvc-dynamic-v20210822114001
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20210822114001/tpt-libs-prebuilt-x86_64-win-msvc-dynamic-v20210822114001.zip
source_filename = tpt-libs-prebuilt-x86_64-win-msvc-dynamic-v20210822114001.zip
source_hash = 30f8dca1b88e42865a452c8ed76dfe6827eb837fffa6cba32a61a78e596d9b6a

View File

@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-win-msvc-dynamic-v20211022224519
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20211022224519/tpt-libs-prebuilt-x86_64-win-msvc-dynamic-v20211022224519.zip
source_filename = tpt-libs-prebuilt-x86_64-win-msvc-dynamic-v20211022224519.zip
source_hash = 3c28326015e98efe60d178661657dcf56d65c883d95e3cd043943fe55c51ff85

View File

@ -1,6 +0,0 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-win-msvc-static-v20210822114001
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20210822114001/tpt-libs-prebuilt-x86_64-win-msvc-static-v20210822114001.zip
source_filename = tpt-libs-prebuilt-x86_64-win-msvc-static-v20210822114001.zip
source_hash = 496c1d2f9408c580bb85ea93fbb6d2d16b05c408961ab380aa8bc796ef65ac0b

View File

@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-win-msvc-static-v20211022224519
source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20211022224519/tpt-libs-prebuilt-x86_64-win-msvc-static-v20211022224519.zip
source_filename = tpt-libs-prebuilt-x86_64-win-msvc-static-v20211022224519.zip
source_hash = 5982c4408d06649517761a21ec86bae49fd351b1a553b01e99d1afa10f127713