QML module not recognized by Bazel build

37 views Asked by At

Currently, I try to build the Spotify demo described in the Qt QML Book using rules_qt6 with Bazel. I did setup a PR here.

The CMake variant of it has the following CMake function

qt_add_qml_module(SpotifyOAuth
    VERSION 1.0.0
    URI Spotify
    QML_FILES
        main.qml
    SOURCES
        spotifyapi.h spotifyapi.cpp
        spotifymodel.h spotifymodel.cpp
)

rules_qt6 does not offer a qt_add_qml_module rule currently. Neverthless, maybe with some workaround, this demo could get working. I know too less about the details of qt_add_qml_module to implement it currently.

I built the CMake version of the Spotify demo and have seen that it generates a qmldir file:

module Spotify
typeinfo SpotifyOAuth.qmltypes
prefer :/Spotify/

I tried to add those files (qmldir and SpotifyOAuth.qmltypes) via a Qt resource but on runtime I get still this error:

QQmlApplicationEngine failed to load component
qrc:/Spotify/main.qml:52:5: SpotifyAPI is not a type

You can run the demo via:

bazel run --config=gcc11 //Spotify:SpotifyOAuth # Ubuntu 22.04
bazel run --config=macos //Spotify:SpotifyOAuth # macOS
bazel run --config=vs2022 //Spotify:SpotifyOAuth # Windows + Visual Studio 2022

I am searching for ways to get this demo working by using the pre-generated files (i.e. qmldir, SpotifyOAuth.qmltypes) or by implementing a qt_add_qml_module Bazel macro/rule.

My build file looks currently like this:

load("@rules_qt//:qt.bzl", "qt_cc_binary", "qt_cc_library", "qt_resource")

qt_resource(
    name = "qrc",
    files = [
        "SpotifyOAuth.qmltypes",
        "qmldir",
    ],
)

qt_resource(
    name = "qrc2",
    files = [
        "main.qml"
    ],
)

qt_cc_library(
    name = "spotify",
    srcs = [
        "spotifyapi.cpp",
        "spotifymodel.cpp",
    ],
    hdrs = [
        "spotifyapi.h",
        "spotifymodel.h",
    ],
    deps = [
        "@rules_qt//:qt",
    ],
)

qt_cc_binary(
    name = "SpotifyOAuth",
    srcs = [
        "main.cpp",
    ],
    deps = [
        ":qrc",
        ":qrc2",
        ":spotify",
        "@rules_qt//:qt",
    ],
    data = [
        ":qrc",
        ":qrc2",
    ]
)

Maybe I have to provide a SpotifyModel.qml and SpotifyAPI.qml file myself, which define the API of the corresponding C++ components. Not sure about this. Any solutions are welcome!

0

There are 0 answers