Skip to content

Add MinGW (Windows GNU) toolchain support#1396

Open
GuyFromTheInternet wants to merge 2 commits intoKDAB:mainfrom
GuyFromTheInternet:mingw-support
Open

Add MinGW (Windows GNU) toolchain support#1396
GuyFromTheInternet wants to merge 2 commits intoKDAB:mainfrom
GuyFromTheInternet:mingw-support

Conversation

@GuyFromTheInternet
Copy link

@GuyFromTheInternet GuyFromTheInternet commented Jan 23, 2026

This PR adds support for building cxx-qt applications with the MinGW (x86_64-pc-windows-gnu) toolchain on Windows.

Changes:

Started using Q_COREAPP_STARTUP_FUNCTION for metatype registration, the previous implementation used std::call_once for one-time metatype registration during static initialization. This fails on MinGW because the pthread TLS emulation (_emutls*) used by MinGW's std::call_once implementation isn't initialized during static constructors, causing a crash.

I also use atomic operations for initialization guards since this is simpler, has no TLS dependencies and works correctly on all platforms including MinGW.

Files changed:

  • crates/cxx-qt/src/init.cpp - Use Q_COREAPP_STARTUP_FUNCTION (Qt5 only)
  • crates/cxx-qt-lib/src/core/init.cpp - Use Q_COREAPP_STARTUP_FUNCTION
  • crates/cxx-qt-lib/src/gui/init.cpp - Use Q_COREAPP_STARTUP_FUNCTION
  • crates/cxx-qt-build/src/lib.rs - Use atomic operations for initialization

Tested with Qt 6.8.3 MinGW build on Windows 11 using x86_64-pc-windows-gnu target.

@GuyFromTheInternet GuyFromTheInternet marked this pull request as draft January 24, 2026 01:25
Use Q_COREAPP_STARTUP_FUNCTION for metatype registration, which is Qt's recommended approach and works reliably on all platforms including MinGW.

Change generated initializer code to use atomic operations instead of std::call_once for simpler, more portable initialization.
@GuyFromTheInternet GuyFromTheInternet marked this pull request as ready for review January 24, 2026 02:30
Copy link
Collaborator

@ahayzen-kdab ahayzen-kdab left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks for looking at solving this!

Looks like CI is failing as clang-format needs to run over the files, are you able to do that?

And then would you be comfortable attempting to add a CI runner for this? As it would be good to ensure we do not regress and we can prove that it works.

This would be a matter of adding MinGW to the matrix similar to MSVC here (can be release rather than debug) https://github.com/KDAB/cxx-qt/blob/main/.github/workflows/github-cxx-qt-tests.yml#L394 set the values in the matrix, eg likely it is win64_mingw as the aqt_arch, then check if any other runner.os == 'Windows' need updating/changing. And note only do this for Qt 6, don't both with Qt 5.

@ahayzen-kdab
Copy link
Collaborator

And guess there might need to be a Rust toolchain installed too, so might need to be an additional entry for that

@GuyFromTheInternet
Copy link
Author

Pretty sure I did everything you asked

@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (55106f0) to head (ed42b48).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main     #1396    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           75        75            
  Lines        13124     13457   +333     
==========================================
+ Hits         13124     13457   +333     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants