Skip to content

Commit

Permalink
Merge pull request #32 from apple1417/master
Browse files Browse the repository at this point in the history
support standard mingw alongslide llvm-mingw
  • Loading branch information
apple1417 authored Jan 5, 2024
2 parents fa5b705 + 1729c74 commit fdc401f
Show file tree
Hide file tree
Showing 24 changed files with 227 additions and 126 deletions.
36 changes: 23 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ env:
# Important to pin the clang version, cause we also use it for linting
CLANG_VERSION: 17
CLANG_TIDY_JOBS: 4
# Since we use rather new c++ features, we need a rather new version of MinGW
# LLVM MinGW seems to be the newest prebuilt binaries around
LLVM_MINGW_VERSION: llvm-mingw-20230919-msvcrt-ubuntu-20.04-x86_64
LLVM_MINGW_DOWNLOAD: https://github.com/mstorsjo/llvm-mingw/releases/download/20230919/llvm-mingw-20230919-msvcrt-ubuntu-20.04-x86_64.tar.xz
# LLVM MinGW download
LLVM_MINGW_VERSION: llvm-mingw-20231128-msvcrt-ubuntu-20.04-x86_64
LLVM_MINGW_DOWNLOAD: https://github.com/mstorsjo/llvm-mingw/releases/download/20231128/llvm-mingw-20231128-msvcrt-ubuntu-20.04-x86_64.tar.xz
# xwin settings
XWIN_VERSION: xwin-0.3.1-x86_64-unknown-linux-musl
XWIN_DOWNLOAD: https://github.com/Jake-Shadle/xwin/releases/download/0.3.1/xwin-0.3.1-x86_64-unknown-linux-musl.tar.gz
XWIN_VERSION: xwin-0.5.0-x86_64-unknown-linux-musl
XWIN_DOWNLOAD: https://github.com/Jake-Shadle/xwin/releases/download/0.5.0/xwin-0.5.0-x86_64-unknown-linux-musl.tar.gz

jobs:
cache-clang:
Expand Down Expand Up @@ -55,15 +54,15 @@ jobs:

steps:
- name: Restore Clang Cache
if: contains(matrix.preset, 'clang')
if: startswith(matrix.preset, 'clang')
uses: actions/cache/restore@v3
with:
path: C:\Program Files\LLVM
key: ${{ runner.os }}-clang-${{ env.CLANG_VERSION }}
fail-on-cache-miss: true

- name: Add MSVC to PATH
if: contains(matrix.preset, 'msvc')
if: startswith(matrix.preset, 'msvc')
uses: TheMrMilchmann/setup-msvc-dev@v2
with:
arch: ${{ fromJSON('["x86", "x64"]')[contains(matrix.preset, 'x64')] }}
Expand Down Expand Up @@ -91,10 +90,15 @@ jobs:
fail-fast: false
matrix:
preset: [
"mingw-ue3-x86-release",
"mingw-ue4-x64-release",
"clang-cross-ue3-x86-release",
"clang-cross-ue4-x64-release",
"llvm-mingw-ue3-x86-release",
"llvm-mingw-ue4-x64-release",
# Currently, ubuntu-latest is 22.04, whose mingw version is too old, so disabling these
# builds for now
# Not sure of the exact threshold, 13.1.0 works
# "mingw-ue3-x86-release",
# "mingw-ue4-x64-release",
]

steps:
Expand All @@ -105,7 +109,7 @@ jobs:
# Caching would also lose the +x - so we'd have to tar before caching/untar after, making it
# even slower
- name: Setup Clang
if: contains(matrix.preset, 'clang')
if: startswith(matrix.preset, 'clang')
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
Expand All @@ -127,13 +131,19 @@ jobs:
/usr/bin/llvm-rc-${{ env.CLANG_VERSION }} \
200
- name: Setup MinGW
if: contains(matrix.preset, 'mingw')
- name: Setup LLVM MinGW
if: startswith(matrix.preset, 'llvm-mingw')
run: |
wget -nv ${{ env.LLVM_MINGW_DOWNLOAD }}
tar -xf ${{ env.LLVM_MINGW_VERSION }}.tar.xz -C ~/
echo $(readlink -f ~/${{ env.LLVM_MINGW_VERSION }}/bin) >> $GITHUB_PATH
- name: Set up MinGW
if: startswith(matrix.preset, 'mingw')
uses: egor-tensin/setup-mingw@v2
with:
platform: ${{ fromJSON('["x86", "x64"]')[contains(matrix.preset, 'x64')] }}

# xwin does take long enough that caching's worth it
- name: Restore xwin cache
if: contains(matrix.preset, 'cross')
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ set_target_properties(_unrealsdk_interface PROPERTIES
COMPILE_WARNING_AS_ERROR True
INTERPROCEDURAL_OPTIMIZATION True
)

if(MSVC)
target_compile_options(_unrealsdk_interface INTERFACE /W4)
else()
target_compile_options(_unrealsdk_interface INTERFACE -Wall -Wextra -Wpedantic)
endif()
# CMake doesn't understand warnings as errors for MinGW yet
if(MINGW)
target_compile_options(_unrealsdk_interface INTERFACE -Werror)
endif()

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
try_compile(supports_format
Expand Down
64 changes: 64 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@
},
"toolchainFile": "common_cmake/clang-cross-x64.cmake"
},
{
"name": "_llvm_mingw_x86",
"hidden": true,
"condition": {
"type": "notEquals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"toolchainFile": "common_cmake/llvm-i686-w64-mingw32.cmake"
},
{
"name": "_llvm_mingw_x64",
"hidden": true,
"condition": {
"type": "notEquals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"toolchainFile": "common_cmake/llvm-x86_64-w64-mingw32.cmake"
},
{
"name": "_mingw_x86",
"hidden": true,
Expand Down Expand Up @@ -224,6 +244,50 @@
"_release"
]
},
{
"name": "llvm-mingw-ue3-x86-debug",
"displayName": "UE3 x86 Debug (LLVM MinGW)",
"inherits": [
"_base",
"_llvm_mingw_x86",
"_ue3",
"_x86",
"_debug"
]
},
{
"name": "llvm-mingw-ue3-x86-release",
"displayName": "UE3 x86 Release (LLVM MinGW)",
"inherits": [
"_base",
"_llvm_mingw_x86",
"_ue3",
"_x86",
"_release"
]
},
{
"name": "llvm-mingw-ue4-x64-debug",
"displayName": "UE4 x64 Debug (LLVM MinGW)",
"inherits": [
"_base",
"_llvm_mingw_x64",
"_ue4",
"_x64",
"_debug"
]
},
{
"name": "llvm-mingw-ue4-x64-release",
"displayName": "UE4 x64 Release (LLVM MinGW)",
"inherits": [
"_base",
"_llvm_mingw_x64",
"_ue4",
"_x64",
"_release"
]
},
{
"name": "mingw-ue3-x86-debug",
"displayName": "UE3 x86 Debug (MinGW)",
Expand Down
2 changes: 1 addition & 1 deletion common_cmake
10 changes: 5 additions & 5 deletions src/unrealsdk/game/bl2/antidebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ typedef NTSTATUS(WINAPI* NtQueryInformationProcess_func)(HANDLE ProcessHandle,
ULONG ProcessInformationLength,
PULONG ReturnLength);

#if defined(__clang__) || defined(__MINGW32__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wenum-constexpr-conversion"
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wenum-constexpr-conversion"
#endif

constexpr auto ThreadHideFromDebugger = static_cast<THREAD_INFORMATION_CLASS>(17);
constexpr auto ProcessDebugObjectHandle = static_cast<PROCESSINFOCLASS>(30);

#if defined(__clang__) || defined(__MINGW32__)
#pragma GCC diagnostic pop
#if defined(__clang__)
#pragma clang diagnostic pop
#endif

// NOLINTEND(readability-identifier-naming)
Expand Down
9 changes: 9 additions & 0 deletions src/unrealsdk/game/bl2/bl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ void BL2Hook::hook(void) {
hexedit_array_limit_message();
}

#if defined(__MINGW32__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes" // thiscall on non-class
#endif

#pragma region FName::Init

namespace {
Expand Down Expand Up @@ -105,6 +110,10 @@ void BL2Hook::ftext_as_culture_invariant(unreal::FText* /*text*/,

#pragma endregion

#if defined(__MINGW32__)
#pragma GCC diagnostic pop
#endif

} // namespace unrealsdk::game

#endif
9 changes: 9 additions & 0 deletions src/unrealsdk/game/bl2/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ namespace unrealsdk::game {

namespace {

#if defined(__MINGW32__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes" // thiscall on non-class
#endif

struct FMalloc;
struct FMallocVFtable {
void* exec;
Expand All @@ -24,6 +29,10 @@ struct FMalloc {
FMallocVFtable* vftable;
};

#if defined(__MINGW32__)
#pragma GCC diagnostic pop
#endif

FMalloc* gmalloc;

const constinit Pattern<8> GMALLOC_PATTERN{
Expand Down
9 changes: 9 additions & 0 deletions src/unrealsdk/game/tps/tps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ using namespace unrealsdk::unreal;

namespace unrealsdk::game {

#if defined(__MINGW32__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes" // thiscall on non-class
#endif

void TPSHook::fname_init(FName* name, const wchar_t* str, int32_t number) const {
// NOLINTNEXTLINE(modernize-use-using)
typedef void*(__thiscall * fname_init_func)(FName * name, const wchar_t* str, int32_t number,
Expand All @@ -18,6 +23,10 @@ void TPSHook::fname_init(FName* name, const wchar_t* str, int32_t number) const
reinterpret_cast<fname_init_func>(this->fname_init_ptr)(name, str, number, 1, 1, 0);
}

#if defined(__MINGW32__)
#pragma GCC diagnostic pop
#endif

} // namespace unrealsdk::game

#endif
1 change: 1 addition & 0 deletions src/unrealsdk/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>

// This file is just a forwarder for whichever formatting library is configured, it doesn't define
// anything itself, so is fine to include here
Expand Down
12 changes: 6 additions & 6 deletions src/unrealsdk/unreal/classes/properties/copyable_property.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ namespace unrealsdk::unreal {
template <typename T>
class CopyableProperty : public UProperty {
public:
CopyableProperty<T>() = delete;
CopyableProperty<T>(const CopyableProperty<T>&) = delete;
CopyableProperty<T>(CopyableProperty<T>&&) = delete;
CopyableProperty<T>& operator=(const CopyableProperty<T>&) = delete;
CopyableProperty<T>& operator=(CopyableProperty<T>&&) = delete;
~CopyableProperty<T>() = delete;
CopyableProperty() = delete;
CopyableProperty(const CopyableProperty&) = delete;
CopyableProperty(CopyableProperty&&) = delete;
CopyableProperty& operator=(const CopyableProperty&) = delete;
CopyableProperty& operator=(CopyableProperty&&) = delete;
~CopyableProperty() = delete;
};

template <typename T>
Expand Down
6 changes: 3 additions & 3 deletions src/unrealsdk/unreal/classes/properties/uboolproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace unrealsdk::unreal {
#pragma pack(push, 0x4)
#endif

#if defined(__clang__) || defined(__MINGW32__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-private-field"
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif

class UBoolProperty : public UProperty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ void PropTraits<UInterfaceProperty>::set(const UInterfaceProperty* prop,

// Ensure the object is of a valid class
if (value != nullptr) {
FImplementedInterface* impl = nullptr;
FImplementedInterface impl{};
if (!value->is_implementation(prop_iface, &impl)) {
throw std::runtime_error("Object is not implementation of "
+ (std::string)prop_iface->Name);
}
pointer_offset = impl->get_pointer_offset();
pointer_offset = impl.get_pointer_offset();
}

auto iface = reinterpret_cast<FScriptInterface*>(addr);
Expand Down
4 changes: 2 additions & 2 deletions src/unrealsdk/unreal/classes/uclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace unrealsdk::unreal {

bool UClass::implements(const UClass* iface, FImplementedInterface** impl_out) const {
bool UClass::implements(const UClass* iface, FImplementedInterface* impl_out) const {
// For each class in the inheritance chain
for (const UObject* superfield : this->superfields()) {
// Make sure it's a class
Expand All @@ -21,7 +21,7 @@ bool UClass::implements(const UClass* iface, FImplementedInterface** impl_out) c
if (our_iface.Class == iface) {
// Output the implementation, if necessary
if (impl_out != nullptr) {
*impl_out = &our_iface;
*impl_out = our_iface;
}
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/unrealsdk/unreal/classes/uclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ struct FImplementedInterface;
#pragma pack(push, 0x4)
#endif

#if defined(__clang__) || defined(__MINGW32__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-private-field"
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif

class UClass : public UStruct {
Expand Down Expand Up @@ -75,7 +75,7 @@ class UClass : public UStruct {
* @return True if this class implements the given interface.
*/
[[nodiscard]] bool implements(const UClass* iface,
FImplementedInterface** impl_out = nullptr) const;
FImplementedInterface* impl_out = nullptr) const;
};

template <>
Expand Down
6 changes: 3 additions & 3 deletions src/unrealsdk/unreal/classes/uenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace unrealsdk::unreal {
#pragma pack(push, 0x4)
#endif

#if defined(__clang__) || defined(__MINGW32__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-private-field"
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif

class UEnum : public UField {
Expand Down
6 changes: 3 additions & 3 deletions src/unrealsdk/unreal/classes/ufunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace unrealsdk::unreal {
#pragma pack(push, 0x4)
#endif

#if defined(__clang__) || defined(__MINGW32__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-private-field"
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif

class UFunction : public UStruct {
Expand Down
Loading

0 comments on commit fdc401f

Please sign in to comment.