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

use vcpkg for Windows & macOS builds; add Qt6 builds; use sccache #107

Merged
merged 6 commits into from
Mar 10, 2022

Conversation

Be-ing
Copy link
Contributor

@Be-ing Be-ing commented Mar 8, 2022

This builds Qt with vcpkg and caches the C++ dependencies on GitHub Packages. The builds work on Linux, Windows, and macOS for both Qt5 and Qt6, however the tests only pass on Linux. It uses sccache for both C++ and Rust to speed up the builds.

Currently it is using GitHub Packages under my GitHub user because that is what I have write access to. GITHUB_TOKEN can only have write access to the KDAB organization's GitHub Packages for a pull request from a branch on the upstream repository; it only has read access for pull requests from forked repositories. When this is merged, Be-ing should be replaced with KDAB in the Authenticate to GitHub Packages step of the GitHub Actions workflow and a GitHub Personal Access Token with read-only permission to packages generated for anonymous access in CMakeLists.txt.

Fixes #78, #79

@Be-ing Be-ing force-pushed the vcpkg branch 5 times, most recently from 2218664 to f176ea8 Compare March 8, 2022 08:38
@Be-ing
Copy link
Contributor Author

Be-ing commented Mar 8, 2022

qmltestrunner fails to import the QtQuick module on macOS. I suspect this has something to do with statically linking Qt. I tried specifying the -import and -plugins command line options for qmltestrunner using the absolute path to where vcpkg installed Qt, but those did not work. For now I have disabled the one test (example_qml_extension_plugin_test) which uses that. Otherwise macOS tests are working now.

Windows tests are failing to link symbols that look like they should come from cxx-qt-gen/src/cxx_qt.cpp. I don't know what's going wrong there. Maybe not worth spending time on before #105 is merged.

Windows Qt6 tests are hanging indefinitely.

@Be-ing Be-ing force-pushed the vcpkg branch 2 times, most recently from 776c64e to 20af347 Compare March 8, 2022 09:55
@ahayzen-kdab
Copy link
Collaborator

qmltestrunner fails to import the QtQuick module on macOS. I suspect this has something to do with statically linking Qt. I tried specifying the -import and -plugins command line options for qmltestrunner using the absolute path to where vcpkg installed Qt, but those did not work. For now I have disabled the one test (example_qml_extension_plugin_test) which uses that. Otherwise macOS tests are working now.

Windows tests are failing to link symbols that look like they should come from cxx-qt-gen/src/cxx_qt.cpp. I don't know what's going wrong there. Maybe not worth spending time on before #105 is merged.

Windows Qt6 tests are hanging indefinitely.

So the macOS part sounds interesting, which part are we static linking to Qt ? I thought we should be statically linking the Rust library into the C++ library or executable and then that is dynamic linking to Qt ? Or is something going wrong / missing on macOS ?

For Windows, as you've managed to get things building quite far, I'll try and setup an environment so I can investigate what is failing on Windows (as none of us have tried it yet 😅 ), and as you have noted parts there are potential issues in cxx_qt.cpp are being changed in #105 so it'll likely be after that.

@Be-ing
Copy link
Contributor Author

Be-ing commented Mar 8, 2022

So the macOS part sounds interesting, which part are we static linking to Qt ?

vcpkg defaults to building everything statically on macOS (as well as Linux, though we're not using vcpkg for Linux builds).

Or is something going wrong / missing on macOS ?

I haven't tested static linking on another OS or dynamic linking on macOS, but that may be worth a try.

@Be-ing
Copy link
Contributor Author

Be-ing commented Mar 8, 2022

I'll try and setup an environment so I can investigate what is failing on Windows

Note that this branch will automatically download the dependencies with vcpkg when configuring CMake using my read-only PAT. This takes a while (several minutes) during which there isn't much feedback from vcpkg, but don't worry, it hasn't frozen.

@Be-ing
Copy link
Contributor Author

Be-ing commented Mar 8, 2022

qmltestrunner fails to import the QtQuick module on macOS. I suspect this has something to do with statically linking Qt.

I suspect this may be a bug in qmltestrunner's build system rather than in cxx-qt.

@Be-ing Be-ing force-pushed the vcpkg branch 3 times, most recently from f47b6ca to b1e755b Compare March 9, 2022 14:58
@Be-ing
Copy link
Contributor Author

Be-ing commented Mar 9, 2022

How shall we proceed with this PR? I think it would be reasonable to disable the tests for Windows, merge this, then you could fix the Windows tests in a future PR.

If you want to speed up the CI runs, manually cancel the earlier runs from https://github.com/KDAB/cxx-qt/actions. The earlier runs will take many hours before they finish because they didn't hit the GitHub Packages cache. I don't have permission to cancel CI runs on this repo.

@Be-ing Be-ing force-pushed the vcpkg branch 5 times, most recently from c1d9ab3 to 5314485 Compare March 9, 2022 18:54
@ahayzen-kdab
Copy link
Collaborator

How shall we proceed with this PR? I think it would be reasonable to disable the tests for Windows, merge this, then you could fix the Windows tests in a future PR.

If you want to speed up the CI runs, manually cancel the earlier runs from https://github.com/KDAB/cxx-qt/actions. The earlier runs will take many hours before they finish because they didn't hit the GitHub Packages cache. I don't have permission to cancel CI runs on this repo.

I'll try and have a closer look at this tomorrow, I wonder about splitting things into smaller changes as we have multiple things going on here. eg there could be the following pull requests (?)

  • Add Qt 6 support for Linux
  • Add macOS support (Qt 5 and Qt 6)
  • Add Windows support (Qt 5 and Qt 6) (we could then leave this one open until we figure out the changes to get the tests passing :-) ) (and probably stack this branch ontop of the macOS one, as the macOS one looks likely to land next)

@Be-ing
Copy link
Contributor Author

Be-ing commented Mar 9, 2022

Add Qt 6 support for Linux

The rewrite of the GitHub Actions workflow file and adding vcpkg for macOS & Windows is all done together in one commit. If you insist I could split it up, but IMO that wouldn't be worth the trouble.

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.

It's looking good, left some more comments for clarifications :-)

CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
.github/workflows/github-cxx-qt-tests.yml Outdated Show resolved Hide resolved
.github/workflows/github-cxx-qt-tests.yml Outdated Show resolved Hide resolved
.github/workflows/github-cxx-qt-tests.yml Show resolved Hide resolved
.github/workflows/github-cxx-qt-tests.yml Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
cmake/CompilerCaching.cmake Show resolved Hide resolved
vcpkg.json Show resolved Hide resolved
@Be-ing Be-ing force-pushed the vcpkg branch 3 times, most recently from 0731fa6 to 0f28bcb Compare March 10, 2022 15:50
@Be-ing
Copy link
Contributor Author

Be-ing commented Mar 10, 2022

Well, this is strange. Explicitly setting QT_DEFAULT_VERSION_MAJOR=6 with both Qt5 and Qt6 development packages installed on Fedora 35 fails with:

CMake Error at /usr/lib64/cmake/Qt5QmlImportScanner/Qt5QmlImportScannerConfig.cmake:11 (qt6_import_qml_plugins):
  Unknown CMake command "qt6_import_qml_plugins".
Call Stack (most recent call first):
  examples/qml_extension_plugin/CMakeLists.txt:44 (qt_import_qml_plugins)

qt6_import_qml_plugins is defined in /usr/lib64/cmake/Qt6Qml/Qt6QmlMacros.cmake. I am puzzled why Qt5QmlImportScannerConfig.cmake is invoked at all. Not setting QT_DEFAULT_VERSION_MAJOR works fine and defaults to Qt6 as expected. Setting QT_DEFAULT_MAJOR_VERSION=5 also works. I suppose there's a bug in Qt's CMake scripts?? Anyway, it's working now.

@Be-ing
Copy link
Contributor Author

Be-ing commented Mar 10, 2022

I think all review comments have been addressed at this point. I also added documentation to README.md explaining how the build system works.

@ahayzen-kdab
Copy link
Collaborator

Well, this is strange. Explicitly setting QT_DEFAULT_VERSION_MAJOR=6 with both Qt5 and Qt6 development packages installed on Fedora 35 fails with:

CMake Error at /usr/lib64/cmake/Qt5QmlImportScanner/Qt5QmlImportScannerConfig.cmake:11 (qt6_import_qml_plugins):
  Unknown CMake command "qt6_import_qml_plugins".
Call Stack (most recent call first):
  examples/qml_extension_plugin/CMakeLists.txt:44 (qt_import_qml_plugins)

qt6_import_qml_plugins is defined in /usr/lib64/cmake/Qt6Qml/Qt6QmlMacros.cmake. I am puzzled why Qt5QmlImportScannerConfig.cmake is invoked at all. Not setting QT_DEFAULT_VERSION_MAJOR works fine and defaults to Qt6 as expected. Setting QT_DEFAULT_MAJOR_VERSION=5 also works. I suppose there's a bug in Qt's CMake scripts?? Anyway, it's working now.

Right sounds like a bug to report upstream :-)

@Be-ing Be-ing changed the title use vcpkg for Windows & macOS builds; add Qt6 builds use vcpkg for Windows & macOS builds; add Qt6 builds; compiler caching Mar 10, 2022
@Be-ing Be-ing changed the title use vcpkg for Windows & macOS builds; add Qt6 builds; compiler caching use vcpkg for Windows & macOS builds; add Qt6 builds; use sccache Mar 10, 2022
@ahayzen-kdab
Copy link
Collaborator

OK, lets go with this!

@ahayzen-kdab ahayzen-kdab merged commit d203f27 into KDAB:main Mar 10, 2022
@Be-ing Be-ing mentioned this pull request Mar 10, 2022
7 tasks
@ahayzen-kdab
Copy link
Collaborator

@Be-ing Thanks for your contribution! I wasn't expecting to have this working for a while! :-)

I'll try updating the tokens, I wonder if the "username" is my account or the org account if the token is from my personal account 🤔 ...

@Be-ing Be-ing deleted the vcpkg branch March 10, 2022 17:34
@Be-ing
Copy link
Contributor Author

Be-ing commented Mar 10, 2022

I wonder if the "username" is my account or the org account

Yes, it's confusing, but the user for the GitHub Packages NuGet source is the organization (KDAB), not ahayzen-kdab.

For example you can see the packages I built on my fork: https://github.com/Be-ing?tab=packages

@ahayzen-kdab
Copy link
Collaborator

Thanks :-)

@Be-ing
Copy link
Contributor Author

Be-ing commented Mar 10, 2022

The CI build on the update-tokens branch succeeded. You can merge that to the main branch now.

I wasn't expecting to have this working for a while! :-)

Yep, I've done this for two different cross platform C++ applications before, which took months of work, so I figured I'd help out with this cool project. In my experience this setup with vcpkg, GitHub Actions, and GitHub Packages has been the most practical way to maintain cross platform C++ applications. Don't hesitate to ping me if you have any questions maintaining it. The same build process works both on CI and for local development, so you don't get ugly surprises when developers try to get started contributing nor weird issues in CI builds that developers can't reproduce locally. Also, vcpkg works on Linux, so you can maintain packaging for Windows and macOS from Linux without needing to actually use Windows or macOS much.

P.S. I just sent an application to [email protected]. It would be great to continue working together on this project. :)

@ahayzen-kdab
Copy link
Collaborator

Thanks! It's all in main now :-) I'll tag you if we have any further issues thanks! And good luck ! :-)

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.

Add CI for using macOS with clang
2 participants