From 1c8a768ce7c19f1e592012ec1860f1af14baf971 Mon Sep 17 00:00:00 2001 From: 27justin Date: Wed, 11 Jun 2025 11:10:20 +0200 Subject: [PATCH 1/2] fix(mingw): allow for cross-compilation to windows using mingw --- CMakeLists.txt | 14 ++++++++++++++ include/Ark/Compiler/AST/BaseParser.hpp | 2 +- include/Ark/VM/Plugin.hpp | 5 ++++- include/Proxy/MiniWindows.h | 6 +++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16759c23d..f875d51fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,15 @@ if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR APPLE) # set fmtlib visibility to default target_compile_definitions(ArkReactor PUBLIC FMT_SHARED) + # Enable FMT_LIB_EXPORT on MingW, otherwise it will fail to compile. + if (MINGW) + target_compile_definitions(ArkReactor PUBLIC FMT_LIB_EXPORT) + # Add -static to linking flags for MingW, otherwise it will + # dynamically link to libgcc_s_seh-1.dll, libwinpthread-1.dll + # and libstdc++-6.dll + target_link_options(ArkReactor PRIVATE -static) + endif () + if (APPLE) # The standard SSH libraries are depreciate on APPLE. # Thus they currently generate a warning that we have to ignore for now. @@ -284,6 +293,11 @@ if (ARK_BUILD_EXE) set_target_properties(arkscript PROPERTIES UNITY_BUILD ON UNITY_BUILD_MODE BATCH UNITY_BUILD_BATCH_SIZE 16) endif () + if (MINGW) + # Statically link the arkscript executable + target_link_options(arkscript PRIVATE -static) + endif () + enable_lto(arkscript) # Installs the arkscript executable. diff --git a/include/Ark/Compiler/AST/BaseParser.hpp b/include/Ark/Compiler/AST/BaseParser.hpp index 1f302d883..109683f19 100644 --- a/include/Ark/Compiler/AST/BaseParser.hpp +++ b/include/Ark/Compiler/AST/BaseParser.hpp @@ -84,7 +84,7 @@ namespace Ark::internal * * @return distance in characters from the beginning of the file to the cursor */ - long getCount() { return std::distance(m_str.begin(), m_it); } + size_t getCount() { return std::distance(m_str.begin(), m_it); } /** * diff --git a/include/Ark/VM/Plugin.hpp b/include/Ark/VM/Plugin.hpp index c80c9550a..c46ee947c 100644 --- a/include/Ark/VM/Plugin.hpp +++ b/include/Ark/VM/Plugin.hpp @@ -94,7 +94,10 @@ namespace Ark::internal T funcptr; #if defined(ARK_OS_WINDOWS) - if (NULL == (funcptr = reinterpret_cast(GetProcAddress(m_instance, procname.c_str())))) + // casting from FARPROC -> void* -> T is required on MingW + // target, immediate conversion from FARPROC -> T will fail. + void* pluginhandle = reinterpret_cast(GetProcAddress(m_instance, procname.c_str())); + if (NULL == (funcptr = reinterpret_cast(pluginhandle))) { throw std::system_error( std::error_code(::GetLastError(), std::system_category()), std::string("PluginError: Couldn't find ") + procname); diff --git a/include/Proxy/MiniWindows.h b/include/Proxy/MiniWindows.h index 952078cdd..58f4140c9 100644 --- a/include/Proxy/MiniWindows.h +++ b/include/Proxy/MiniWindows.h @@ -13,7 +13,11 @@ # define _ARM_ # endif -# define NOMINMAX +// Do not define NOMINMAX, if it's already defined (without, the +// #define causes issues on MingW) +# ifndef NOMINMAX +# define NOMINMAX +# endif // https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror # include From f68de101d16d29100e08d597b4b9a5942144a830 Mon Sep 17 00:00:00 2001 From: 27justin Date: Wed, 11 Jun 2025 19:54:50 +0200 Subject: [PATCH 2/2] fix(mingw): add -static to unittests and correct return type for getCount --- CMakeLists.txt | 4 ++++ include/Ark/Compiler/AST/BaseParser.hpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f875d51fc..fe8e82c4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,6 +207,10 @@ if (ARK_TESTS) add_executable(unittests ${SOURCES}) target_include_directories(unittests PUBLIC ${ark_SOURCE_DIR}/tests/unittests) + if (MINGW) + target_link_options(unittests PRIVATE -static) + endif () + target_include_directories(unittests SYSTEM PUBLIC ${ark_SOURCE_DIR}/lib/dtl/dtl) add_subdirectory(${ark_SOURCE_DIR}/lib/ut) diff --git a/include/Ark/Compiler/AST/BaseParser.hpp b/include/Ark/Compiler/AST/BaseParser.hpp index 109683f19..8ec0247a5 100644 --- a/include/Ark/Compiler/AST/BaseParser.hpp +++ b/include/Ark/Compiler/AST/BaseParser.hpp @@ -84,7 +84,7 @@ namespace Ark::internal * * @return distance in characters from the beginning of the file to the cursor */ - size_t getCount() { return std::distance(m_str.begin(), m_it); } + ssize_t getCount() { return std::distance(m_str.begin(), m_it); } /** *