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's data attribute
  • as a compile time dependency. The rule provides QrcInfo which then can be used with qt_cc_rcc.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
dataA list of resources used by a 3D model.List of labelsoptional[]
envAdditional 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 -> Stringoptional{"QT_QPA_PLATFORM": "offscreen"}
modelA model to be converted to optimized format for QtQuick3d usage.Labelrequired

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.

Supports both Qt5 and Qt6.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
hdrsA list of C++ headers that needs to be moc'ed.List of labelsrequired

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsA list of C++ sources that needs to be moc'ed.List of labelsrequired

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsA list of targets that provide QrcInfo.List of labelsrequired

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsA list of .ui forms.List of labelsrequired

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsDependencies used to infer which Qt built-in metatypes should be passed to qmltyperegistrar.List of labelsoptional[]
major_versionMajor version of QML module.Integeroptional1
minor_versionMinor version of QML module.Integeroptional0
mocA qt_cc_moc target that provides MocInfoLabelrequired
module_nameA name of a module under which it will be accessible in QML.Stringrequired

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsA list of qrc files that will be propagated to qt_cc_rcc via QrcInfo.List of labelsoptional[]
dataA 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 labelsoptional[]
prefixA prefix to logically group resources.

Only available for auto qrc file generation, i.e. when the srcs attribute is empty.
Stringoptional""

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

NameDescriptionDefault Value
nameA unique name for this rule.none
srcsSee cc_binary's srcs attribute.[]
depsSee cc_binary's deps attribute.[]
moc_hdrsHeaders for moc. See qt_cc_moc for more info.None
moc_srcsSources for moc. See qt_cc_moc_import for more info.None
qrc_srcsqrc files for rcc. See qt_cc_rcc for more info.None
ui_srcsui files for uic. See qt_cc_uic for more info.None
qml_module_nameA unique name of QML module. See qt_qml_cc_module for more info.None
qml_module_major_versionA major version of QML module. See qt_qml_cc_module for more info.None
qml_module_minor_versionA minor version of QML module. See qt_qml_cc_module for more info.None
qml_import_pathsA 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_modulesA list of qt_qml_import targets which will be available during runtime. Can be combined with data; both lists are merged.[]
qt_qml_pathOptional 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_pathOptional path to Qt's plugins folder. If set, it configures QT_PLUGIN_PATH.None
kwargsAdditional 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

NameDescriptionDefault Value
nameA unique name for this rule.none
srcsSee cc_library's srcs attribute.[]
depsSee cc_library's deps attribute.[]
moc_hdrsHeaders for moc. See qt_cc_moc for more info.None
moc_srcsSources for moc. See qt_cc_moc_import for more info.None
qrc_srcsqrc files for rcc. See qt_cc_rcc for more info.None
ui_srcsui files for uic. See qt_cc_uic for more info.None
qml_module_nameA unique name of QML module. See qt_qml_cc_module for more info.None
qml_module_major_versionA major version of QML module. See qt_qml_cc_module for more info.None
qml_module_minor_versionA minor version of QML module. See qt_qml_cc_module for more info.None
kwargsAdditional 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

NameDescriptionDefault Value
nameA unique name for this rule.none
srcsA list of files that describe a QML module.none