bombomby / optick

C++ Profiler For Games
https://optick.dev
MIT License
2.95k stars 296 forks source link

MinGW Support #112

Open nathanvoglsam opened 4 years ago

nathanvoglsam commented 4 years ago

Currently OptickCore only supports compiling for MSVC for Windows. This pull request extends support of the current code and CMake build system to allow compiling OptickCore with the MinGW toolchain as well.

My motivation for this pull request is to enable using the x86_64-pc-windows-gnu target with rustc and the rust bindings. Debugger support for x86_64-pc-windows-gnu is immensely stronger than on the x86_64-pc-windows-msvc target so it would be ideal for me to still be able to use the gnu target.

Very little changes were needed. Almost every change was related to correctly handling conditional compilation as OPTICK_MSVC as used in many places where a more appropriate name would be OPTICK_WINDOWS as it wasn't guarding MSVC features but windows features.

I have tested the code using the CMake build system with MSVC, MinGW 6.0, MinGW 8.0 (Trunk, from MSYS2) and Linux. To provide a breakdown

The only change which I could see as contentious is for commit 3777e24. The SymLoadModule64 is defined to take char* for the module path parameter on MinGW. I believe this to be an error in the MinGW headers as the official MSVC Windows SDK headers define the parameter to take a const char*. The value for that paramater is taken from std::string.c_str() which always returns a const char* so will cause a compilation error on MinGW.

Under the assumption the MinGW header is wrong and the underlying function will never write through the pointer I cast the const away, which is super unsafe but I believe my assumption to be correct. This could be marked as a workaround and investigated further in the future if needed.

I also fixed a missing include in TestEngine

nathanvoglsam commented 4 years ago

Solves issue #102

MattyGroGy commented 3 years ago

Any updates on this?