docs.md
May 14, 2026 ยท View on GitHub
A set of convenience macros for using Qt's rules with Bazel.
qt_balsam
load("@rules_qt//qt:defs.bzl", "qt_balsam")
qt_balsam(name, data, env, model)
Invokes balsam to generate optimized 3D for use with QtQuick3d.
The generated model can be used in two way:
- as a runtime dependency,
by depending on it in
cc_binary'sdataattribute - as a compile time dependency. The rule provides QrcInfo which then can be used with qt_cc_rcc.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| data | A list of resources used by a 3D model. | List of labels | optional | [] |
| env | Additional environment variables to be passed to the balsam process. Defaults to QT_QPA_PLATFORM=offscreen so balsam can run without a display server. | Dictionary: String -> String | optional | {"QT_QPA_PLATFORM": "offscreen"} |
| model | A model to be converted to optimized format for QtQuick3d usage. | Label | required |
qt_cc_moc
load("@rules_qt//qt:defs.bzl", "qt_cc_moc")
qt_cc_moc(name, hdrs)
Invokes moc on a given set of headers and exposes generated (moc'ed) C++ sources
to be further used in downstream cc_* rules.
Besides C++ sources, the rules exposes metatypes info in json format via MocInfo.
These are required to properly register C++ QtQml types when using the qt_qml_cc_module.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| hdrs | A list of C++ headers that needs to be moc'ed. | List of labels | required |
qt_cc_moc_import
load("@rules_qt//qt:defs.bzl", "qt_cc_moc_import")
qt_cc_moc_import(name, srcs)
Invokes moc on a given set of sources and exposes generated (moc'ed) C++ sources
to be further used in downstream cc_* rules.
See https://doc.qt.io/qt-5/moc.html#writing-make-rules-for-invoking-moc for more details.
The quote from the official docs:
For Q_OBJECT class declarations in implementation (.cpp) files, we suggest a makefile rule like this:
foo.o: foo.moc
foo.moc: foo.cpp
moc $(DEFINES) $(INCPATH) -i $< -o $@
This guarantees that make will run the moc before it compiles foo.cpp. You can then put
#include "foo.moc"
at the end of foo.cpp, where all the classes declared in that file are fully known.
NOTE
The rule uses CcInfo with compilation_context filled in to propagate [generated_name].moc (which is an implementation C++ file),
because cc_*'s srcs attribute has a fixed set of supported file extensions.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| srcs | A list of C++ sources that needs to be moc'ed. | List of labels | required |
qt_cc_rcc
load("@rules_qt//qt:defs.bzl", "qt_cc_rcc")
qt_cc_rcc(name, srcs)
The rule generates C++ sources based on information provided via QrcInfo mandatory provider.
As of now qt_qrc and qt_balsam rules use QrcInfo provider.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| srcs | A list of targets that provide QrcInfo. | List of labels | required |
qt_cc_uic
load("@rules_qt//qt:defs.bzl", "qt_cc_uic")
qt_cc_uic(name, srcs)
Invokes uic on a given set of UI forms and exposes generated C++ headers
to be further used in downstream cc_* rules as compile time dependency,
i.e. to the deps attribute of cc_* rules.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| srcs | A list of .ui forms. | List of labels | required |
qt_qml_cc_module
load("@rules_qt//qt:defs.bzl", "qt_qml_cc_module")
qt_qml_cc_module(name, deps, major_version, minor_version, moc, module_name)
Collects metainformation, provided by qt_cc_moc via MocInfo, of available C++ QML types and generates C++ routines to register them as QML modules.
More info about QtQml C++ integration can be found here: Qt5 and Qt6.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Dependencies used to infer which Qt built-in metatypes should be passed to qmltyperegistrar. | List of labels | optional | [] |
| major_version | Major version of QML module. | Integer | optional | 1 |
| minor_version | Minor version of QML module. | Integer | optional | 0 |
| moc | A qt_cc_moc target that provides MocInfo | Label | required | |
| module_name | A name of a module under which it will be accessible in QML. | String | required |
qt_qrc
load("@rules_qt//qt:defs.bzl", "qt_qrc")
qt_qrc(name, srcs, data, prefix)
The rule either exposes already available Qt's Resources files (qrc) via srcs attribute or generates one
for further use by the resource compiler (qt_cc_rcc rule).
The information between qt_qrc and qt_cc_rcc rules are passed via QrcInfo provider.
In case when srcs has values, the rule will generate the same amount of C++ sources as a number of qrc files.
When the attribute is empty, the rule will first generate a qrc file for all resources available in data
attribute and place them under specified prefix (by default it's empty).
If both srcs and prefix attributes are provided, the prefix will be ignored.
The data attribute should have all necessary files listed for successful code generation.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| srcs | A list of qrc files that will be propagated to qt_cc_rcc via QrcInfo. | List of labels | optional | [] |
| data | A list of resources which will be propagated to qt_cc_rcc via QrcInfo. In case of auto qrc files generation, all files listed in this attribute will be part of the generated one. | List of labels | optional | [] |
| prefix | A prefix to logically group resources. Only available for auto qrc file generation, i.e. when the srcs attribute is empty. | String | optional | "" |
qt_cc_binary
load("@rules_qt//qt:defs.bzl", "qt_cc_binary")
qt_cc_binary(name, srcs, deps, moc_hdrs, moc_srcs, qrc_srcs, ui_srcs, qml_module_name,
qml_module_major_version, qml_module_minor_version, qml_import_paths, qml_modules,
qt_qml_path, qt_plugin_path, **kwargs)
Convenience macro around Qt's rule and cc_binary.
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| name | A unique name for this rule. | none |
| srcs | See cc_binary's srcs attribute. | [] |
| deps | See cc_binary's deps attribute. | [] |
| moc_hdrs | Headers for moc. See qt_cc_moc for more info. | None |
| moc_srcs | Sources for moc. See qt_cc_moc_import for more info. | None |
| qrc_srcs | qrc files for rcc. See qt_cc_rcc for more info. | None |
| ui_srcs | ui files for uic. See qt_cc_uic for more info. | None |
| qml_module_name | A unique name of QML module. See qt_qml_cc_module for more info. | None |
| qml_module_major_version | A major version of QML module. See qt_qml_cc_module for more info. | None |
| qml_module_minor_version | A minor version of QML module. See qt_qml_cc_module for more info. | None |
| qml_import_paths | A list of paths where the QtQml engine should look for additional imports. Sets QML2_IMPORT_PATH (Qt5) and QML_IMPORT_PATH (Qt6) environment variables. | [] |
| qml_modules | A list of qt_qml_import targets which will be available during runtime. Can be combined with data; both lists are merged. | [] |
| qt_qml_path | Optional path to Qt's built-in QML imports folder. If set, it is appended to QML2_IMPORT_PATH and QML_IMPORT_PATH. | None |
| qt_plugin_path | Optional path to Qt's plugins folder. If set, it configures QT_PLUGIN_PATH. | None |
| kwargs | Additional arguments for cc_binary rule. | none |
qt_cc_library
load("@rules_qt//qt:defs.bzl", "qt_cc_library")
qt_cc_library(name, srcs, deps, moc_hdrs, moc_srcs, qrc_srcs, ui_srcs, qml_module_name,
qml_module_major_version, qml_module_minor_version, **kwargs)
Convenience macro around Qt's rule and cc_library.
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| name | A unique name for this rule. | none |
| srcs | See cc_library's srcs attribute. | [] |
| deps | See cc_library's deps attribute. | [] |
| moc_hdrs | Headers for moc. See qt_cc_moc for more info. | None |
| moc_srcs | Sources for moc. See qt_cc_moc_import for more info. | None |
| qrc_srcs | qrc files for rcc. See qt_cc_rcc for more info. | None |
| ui_srcs | ui files for uic. See qt_cc_uic for more info. | None |
| qml_module_name | A unique name of QML module. See qt_qml_cc_module for more info. | None |
| qml_module_major_version | A major version of QML module. See qt_qml_cc_module for more info. | None |
| qml_module_minor_version | A minor version of QML module. See qt_qml_cc_module for more info. | None |
| kwargs | Additional arguments for cc_library rule. | none |
qt_qml_import
load("@rules_qt//qt:defs.bzl", "qt_qml_import")
qt_qml_import(name, srcs)
Convenience macro around filegroup to import QML module.
The target then can be used as runtime deps of qt_cc_binary or compile time by using it in conjunction with qt_qrc.
It expects that the QML module provides qmldir.
See Qt 5 QtQml directory imports and Qt 6 QtQml directory imports for additional info.
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| name | A unique name for this rule. | none |
| srcs | A list of files that describe a QML module. | none |