rules_qt6
0.0.4
published 10 hours ago
37 stars
12 forks
3 watchers
Apache License 2.0
public
1 assets
4,178 downloads
568 KB
0.0.4
October 12, 2025
[expand for release notes]

Support Ukraine Bazel logo Qt logo

Bazel rules for Qt6

Goal

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.

Quick start

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:

  • Git
  • Bazel
  • A C++ compiler (GCC, Visual Studio, Clang, etc.)

Checkout, build, and run:

All platforms:

git clone https://github.com/Vertexwahn/rules_qt6
cd rules_qt6/tests

Run Hello World demo with Windows 10/11 x64 with Visual Studio 2019:

bazel run --config=vs2019 //hello_world:hello_world

Run Hello World demo with Windows 10/11 x64 with Visual Studio 2022:

bazel run --config=vs2022 //hello_world:hello_world

Run Hello World demo with Ubuntu 22.04:

bazel run --config=gcc11 //hello_world:hello_world

Run Hello World demo with Ubuntu 24.04:

bazel run --config=gcc13 //hello_world:hello_world

Run Hello World demo with macOS:

bazel run --config=macos //hello_world:hello_world

Expected output

The expected output should be similar (depending on your platform) to the following screenshots:

Windows

Screenshot of HelloWorld demo on Windows 11

Ubuntu

Screenshot of HelloWorld demo on Ubuntu 22.04

macOS

Screenshot of HelloWorld demo on macOS

More Examples

More examples can be found in the tests directory.

Why rules and not a simple dependency?

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.

Current status

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 vertexwahn.de. Implementation details can be found in fetch_qt.bzl.

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.

Contributions

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).

Similar projects

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

License

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: https://github.com/justbuchanan/bazel_rules_qt/graphs/contributors

Thanks to all contributors ❤