Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mingw compilation fixes #78

Merged
merged 9 commits into from
Feb 6, 2023
Merged

Conversation

past-due
Copy link

Fixing mingw support: getsentry/sentry-native#744

@past-due past-due changed the title mingw: Add missing MINIDUMP_THREAD_NAME / MINIDUMP_THREAD_NAME_LIST definitions mingw compilation fixes Jan 26, 2023
Copy link
Collaborator

@supervacuus supervacuus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides a few fixes, this LGTM. Can you also provide the required CMake CLI parameters you used to get this to run?

CMakeLists.txt Show resolved Hide resolved
compat/mingw/dbghelp.h Show resolved Hide resolved
handler/CMakeLists.txt Outdated Show resolved Hide resolved
Comment on lines 226 to 234

# Define NTDDI_VERSION >= NTDDI_WIN10_RS5 - so InitializeContext2 definition is always available in process_reader_win.cc
# NTDDI_WIN10_RS5 = 0x0A000006 /* ABRACADABRA_WIN10_RS5 */
set_property(
SOURCE "win/process_reader_win.cc"
APPEND
PROPERTY COMPILE_DEFINITIONS
WINVER=0x0A00 _WIN32_WINNT=0x0A00 NTDDI_VERSION=0x0A000006
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please set these definitions only for MinGW?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC (it’s been a bit since I tested) these definitions were also needed - even if using a modern Windows 10 / 11 SDK that has the appropriate header entries - when compiling with MSVC if CMAKE_SYSTEM_VERSION (for the embedding sentry-native project) was set to < 10 (targeting a Windows 7 minimum, for example).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that we make this as conditional as possible. The crashpad build scripts are littered with unconditional settings that only make sense in a subset of the configurations affected. Since no CI setup would test (at least the build of) MSVC projects targeting Windows 7 (which we also don't officially support), these settings should be isolated as much as possible.

How about wrapping it inside something along the lines of

if (MINGW OR ("${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}" STREQUAL ""))
endif()

this should hit all MSVC target configurations below 10 (since it either isn't defined or empty), and it will work for MinGW.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, a check on CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION doesn't cover at least one common MSVC scenario.

Testing this with latest MSVC & Windows SDK, embedding sentry-native + these patches into a project with set(CMAKE_SYSTEM_VERSION "6.1"):

CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION is set in this case (10.0.20348.0, as it is picking it up from the installed recent Windows SDK), but with actual targeting set at Windows 7+, this CMake check is insufficient and compilation ultimately fails on MSVC.

[...] external\crashpad\snapshot\win\process_reader_win.cc(332,7): error C2039: 'InitializeContext2': is not a member of '`global namespace''
(etc)

So the NTDDI_VERSION (etc) overrides are still required to expose the definitions.

I've adjusted this check to:
if (MINGW OR ("${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}" STREQUAL "") OR (CMAKE_SYSTEM_VERSION LESS 10))

which does work in the several scenarios I've tested.

third_party/zlib/CMakeLists.txt Show resolved Hide resolved
Copy link
Member

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, I will defer this to @supervacuus

@past-due
Copy link
Author

past-due commented Feb 1, 2023

Besides a few fixes, this LGTM. Can you also provide the required CMake CLI parameters you used to get this to run?

I have opened a PR in the parent sentry-native repo to add CI for llvm-mingw builds (including testing this crashpad integration): getsentry/sentry-native#797

@supervacuus
Copy link
Collaborator

Thanks for fixing this @past-due!

@supervacuus supervacuus merged commit e39c0b6 into getsentry:getsentry Feb 6, 2023
supervacuus added a commit to getsentry/sentry-native that referenced this pull request Feb 7, 2023
- Switch Crashpad transport on Linux to use libcurl ([#803](#803), [crashpad#75](getsentry/crashpad#75), [crashpad#79](getsentry/crashpad#79))
- Avoid accidentally mutating CONTEXT when client-side stack walking in Crashpad ([#803](#803), [crashpad#77](getsentry/crashpad#77))
- Fix various mingw compilation issues ([#794](#794), [crashpad#78](getsentry/crashpad#78))
- Updated Crashpad backend to 2023-02-07. ([#803](#803), [crashpad#80](getsentry/crashpad#80))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants