The goal of these rules is to be able to build Qt6 applications using Bazel on Windows, Linux and macOS without the need to preinstall Qt6. All the magic to set up Qt6 should be done by Bazel with as little effort as possible.
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/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 20.04:
bazel run --config=gcc9 //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 macOS 11/12:
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install qt@6 # Unfortunately a preinstalled version of Qt6 is still needed on macOS
brew link qt@6
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
Ubuntu
macOS
More Examples
More examples can be found in the tests directory.
Currently, on macOS, these rules need a preinstalled version of Qt on the system (brew install qt@6 && brew link qt@6
).
On Windows and Linux it should be possible to run bazel run --config=[gcc9|gcc11|vs2019|vs2022] //hello_world:hello_world
without the need to preinstall Bazel.
These rules require at least Bazel 4.0.0 to work. With some small modifications, you can get work these rules also on earlier versions of Bazel.
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 a config for vs2019
, vs2022
, gcc9
, gcc11
, and ``macos`.
This is needed since Qt6 needs at least C++17 standard enabled and different C++ compilers need different flags to enable this.
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).
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