The goal of these rules is to be able to build Qt6 applications using Bazel on Linux, macOS and Windows without the need to preinstall Qt6. All the magic to set up Qt6 should be done by Bazel with as little effort as possible.
To get Qt working with C++, you need different tools, e.g., the Meta-Object Compiler (moc). This is needed since Qt introduces some language extensions to C++, such as the signal, slot concept. There is also the User Interface Compiler (uic), Resource Compiler (rcc), and translation tools. To get all of those things working, Qt is a bit more than a simple third-party dependency. The idea of this project is to introduce own rules that simplify the usage of Qt using Bazel.
These rules were tested with Bazel 8.x. There is a chance that you also get this working with Bazel 7.x. If you need support for older versions of Bazel, please check out an older state of this repository. Initially, this repository had support for Bazel 4.x.
When using these rules,
a prebuild version of Qt is fetched from download.qt.io.
Previously a prebuild version of Qt was fetched from vertexwahn.de (this approach was taken for example in release 0.0.4 of these rules).
There is a vaiable QT_BASE_DOWNLOAD_URL that you can change to fetch qt from a different source.
I created a .bazelrc file that contains different configs: vs2019, vs2022, gcc11, gcc13, and macos.
This is necessary since Qt6 requires at least C++17 standard to be enabled, and different C++ compilers require different flags to enable this.
The current targeted version of these rules is Qt 6.8.3. Qt 6.8 is the latest LTS version. Also, there is the idea that these rules can support different versions of Qt, but currently, only version 6.8.3 is tested and supported. When checking the code of these rules, you can also find version 6.4.0 and get a rough idea of how different versions of Qt can be supported at the same time using these rules. Anyways, due to some differences between different Qt versions, it is not always trivial to get everything working easily. The release 0.0.4 of these rules supports only Qt version 6.4.0.
This project uses Bazel as a build system. The current used version of Bazel is defined in .bazelversion.
Prerequisites:
The following tools should be installed:
Checkout, build, and run:
All platforms:
git clone https://github.com/Vertexwahn/rules_qt6
cd rules_qt6/testsRun Hello World demo with Windows 10/11 x64 with Visual Studio 2022:
bazel run --config=vs2022 //hello_world:hello_worldRun Hello World demo with Ubuntu 24.04:
bazel run --config=gcc13 //hello_world:hello_worldRun Hello World demo with macOS:
bazel run --config=macos //hello_world:hello_worldExpected output
The expected output should be similar (depending on your platform) to the following screenshots:
Windows
Ubuntu
macOS
More Examples
More examples can be found in the tests directory.
Any improvements to the Qt6 build experience using Bazel are welcome. Maybe you have solved this problem already. In this case, I would appreciate it if you could share your efforts under some permissive license. If you name no specific license, I assume you are fine with the current used license of this project (Apache 2.0 License).
| Project | Bzlmod Support | Platform Support | Build Type | Last Commit |
|---|---|---|---|---|
| aabtop/rules_qt | no | Windows, Linux | Prebuild | June 21, 2021 |
| bbreslauer/qt-bazel-example | no | Linux | Prebuild | April 5, 2020 |
| FirasRomaneh/QT5WithBazel | no | Linux | Prebuild | August 2, 2022 |
| gwkawano/bazel_qt | no | Linux | Prebuild | June 5, 2020 |
| jheaff1/rules_qt | no | Linux, macOS, Windows | Prebuild | June 19, 2023 |
| justbuchanan/bazel_rules_qt | no | Linux, macOS, Windows | Prebuild | November 13, 2024 |
| kklochkov/rules_qt | no | Linux, macOS | Prebuild | February 21, 2024 |
| The-OpenROAD-Project/qt_bazel_prebuilts | yes | ??? | From Source | Jul 15, 2025 |
This work is published under Apache 2.0 License.
This work builds on top of justbuchanan/bazel_rules_qt which is also licensed under Apache 2.0 and was forked from bbreslauer/qt-bazel-example. See here for details.


