Skip to content

kklochkov/rules_qt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Qt5/Qt6 rules for Bazel

The set of rules to build GUI applications with Qt Framework. I created these rules when QtQuick3D was introduced to experiment with it. I finally found time to clean up rules and make them public, so others that both love Bazel and Qt can use them.

Qt modules

Rules should support all available pre-installed Qt modules. qt_local_repo (a repository rule) queries qmake to get full info about available Qt tools, libraries, plugins and QtQuick imports. So, all modules should be supported (if installed). Though, I tested mostly QtWidget, QtQuick/QtQml and QtQuick3D.

Qt tools

Rules and macros

Besides the aforementioned set of rules, there are two convenience macros available: qt_cc_library and qt_cc_binary.

Rules are intended to be used when one needs more fine-grained Qt target composition.

Macros, usually, are the first choice to build Qt targets, because of their simplicity of use. In essence they still use the same Qt rules, but nicely hide implementation details from a user.

Supported platforms

Tested on Ubuntu (22.04) and macOS Ventura 13.3.1 (Apple Silicon).

What is not supported

  • deployment is not supported
  • dynamic plugins development is not supported
  • since rules rely on pre-installed Qt on a host, produces binaries are not hermetic

Before using rules

In order to use rules, Qt needs to be installed on a host and the path to qmake needs to be provided in qt_local_repo's path attribute.

See examples/WORKSPACE for additional info.

Qt can be installed in several ways:

Installation

WORKSPACE file

See release for the WORKSPACE setup of the currect release.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "com_github_kklochkov_rules_qt",
    urls = ["<URL>"],
    sha256 = "<SHA256>",
)

load("@com_github_kklochkov_rules_qt//qt:repositories.bzl", "rules_qt_dependencies", "rules_qt_toolchains")

rules_qt_dependencies()

rules_qt_toolchains()

# Qt local repo
load("@com_github_kklochkov_rules_qt//qt:qt_local_repo.bzl", "qt_local_repo")

qt_local_repo(
    name = "qt",
    path = "/path/to/qt/bin",
)

IMPORTANT NOTE:

qt_local_repo should be named qt, because the repo is used to retrieve installation paths from qtconf.bzl which are used by qt_cc_binary.

In case a different name is used for the repository, it will not be possible to use qt_cc_binary without errors. One will have to use cc_binary and manually provide QT_PLUGIN_PATH, QML2_IMPORT_PATH and QML_IMPORT_PATH from @<custom_qt_repo_nam>//:qtconf.bzl. See the reference usage.

BUILD file

load("@com_github_kklochkov_rules_qt//qt:defs.bzl", "qt_cc_binary")

qt_cc_binary(
    name = "hello_world",
    srcs = ["main.cpp"],
    deps = ["@qt//:QtCore"],
)

See examples section on how to run examples.

Examples

To run examples, cd examples and follow instructions in README.md.

List of repository rules

List of rules

List of macros

Providers

Toolchain

Dependencies