bedbad
bedbad

Reputation: 1153

bazel doesn't copy binary files to build output folder

Initial build setup with bazel for a common UI library tests fine on a minimal example(with extensive dependancies). The build setup included rules and configuration for that library. However, when I extended this build the adding the dependee project as a package(BUILD) in subfolder and leaving the library as new_local_repository - bazel spits an error.

It does not copy shared binaries of that library to the build output. Consequently it gives random(any of the binaries depended) error that the shared lib or required binary is missing:

ERROR: C:/users/ilya/source/repos/project-cross-platform/project/BUILD:28:10: Copying Execution Dynamic Library failed: missing input file 'external/qt/bin/Qt5Core.dll', owner: '@qt//:bin/Qt5Core.dll'
[5 / 49] [Prepa] BazelWorkspaceStatusAction stable-status.txt
Target //project:main failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: C:/users/ilya/source/repos/project-cross-platform/project/BUILD:28:10 Copying Execution Dynamic Library failed: 1 input file(s) do not exist
INFO: Elapsed time: 4.681s, Critical Path: 0.04s
INFO: 1 process: 1 internal.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

Here's the sample workspace file: workspace(name = "project")

load("@project//:qt_configure.bzl", "local_qt_path")

new_local_repository(
    name = "qt",
    build_file = "//:qt.BUILD",
    path = "./",
)

qt.BUILD:

load("@rules_cc//cc:defs.bzl", "cc_import", "cc_library")

QT_LIBRARIES = [
    ("core", "QtCore", "Qt5Core", []),
    ("network", "QtNetwork", "Qt5Network", []),
    ("widgets", "QtWidgets", "Qt5Widgets", [":qt_core", ":qt_gui"]),
    ("quick", "QtQuick", "Qt5Quick", [":qt_gui", ":qt_qml", ":qt_qml_models"]),
    ("qml", "QtQml", "Qt5Qml", [":qt_core", ":qt_network"]),
    ("qml_models", "QtQmlModels", "Qt5QmlModels", []),
    ("gui", "QtGui", "Qt5Gui", [":qt_core"]),
    ("opengl", "QtOpenGL", "Qt5OpenGL", []),
]

[
    cc_import(
        name = "qt_%s_windows_import" % name,
        # When being on Linux this glob will be empty
        hdrs = glob(["include/%s/**" % include_folder], allow_empty=True),
        interface_library = "lib/%s.lib" % library_name,
        shared_library = "bin/%s.dll" % library_name,
        # Not available in cc_import (See: https://github.com/bazelbuild/bazel/issues/12745)
        # target_compatible_with = ["@platforms//os:windows"],
    )
    for name, include_folder, library_name, _ in QT_LIBRARIES
]

[
    cc_library(
        name = "qt_%s_windows" % name,
        # When being on Linux this glob will be empty
        hdrs = glob(["include/%s/**" % include_folder], allow_empty=True),
        includes = ["include"],
        # Available from Bazel 4.0.0
        # target_compatible_with = ["@platforms//os:windows"],
        deps = [":qt_%s_windows_import" % name],
    )
    for name, include_folder, _, _ in QT_LIBRARIES
]

[
    cc_library(
        name = "qt_%s" % name,
        visibility = ["//visibility:public"],
        deps = dependencies + select({
            "@platforms//os:linux": [":qt_%s_linux" % name],
            "@platforms//os:windows": [":qt_%s_windows" % name],
        }),
    )
    for name, _, _, dependencies in QT_LIBRARIES
]

# TODO: Make available also for Windows
cc_library(
    name = "qt_3d",
    # When being on Windows this glob will be empty
    hdrs = glob([
        "Qt3DAnimation/**",
        "Qt3DCore/**",
        "Qt3DExtras/**",
        "Qt3DInput/**",
        "Qt3DLogic/**",
        "Qt3DQuick/**",
        "Qt3DQuickAnimation/**",
        "Qt3DQuickExtras/**",
        "Qt3DQuickInput/**",
        "Qt3DQuickRender/**",
        "Qt3DQuickScene2D/**",
        "Qt3DRender/**",
    ], allow_empty=True),
    includes = ["."],
    linkopts = [
        "-lQt53DAnimation",
        "-lQt53DCore",
        "-lQt53DExtras",
        "-lQt53DInput",
        "-lQt53DLogic",
        "-lQt53DQuick",
        "-lQt53DQuickAnimation",
        "-lQt53DQuickExtras",
        "-lQt53DQuickInput",
        "-lQt53DQuickRender",
        "-lQt53DQuickScene2D",
        "-lQt53DRender",
    ],
    # Available from Bazel 4.0.0
    # target_compatible_with = ["@platforms//os:linux"],
)

filegroup(
    name = "uic",
    srcs = ["bin/uic.exe"],
    visibility = ["//visibility:public"],
)

filegroup(
    name = "moc",
    srcs = ["bin/moc.exe"],
    visibility = ["//visibility:public"],
)

Upvotes: 1

Views: 1160

Answers (1)

Anas
Anas

Reputation: 31

There seem to be a couple of mistakes that if removed will perhaps solve the problem all together:

  • the rules "new_" are meant for adding repositories that are not built with Bazel (see documentation)
  • When using the rule new_local_repository to depend on a repo that is not built with Bazel you have to specify the path to that repo (you did that) and a build file to use to build that repo. The build file is simply defined relative to that other repository's root so simply /<BUILD File). What you specified as build file(build_file = "//:qt.BUILD",) looks wrong.

Have a nice day :)

Upvotes: 1

Related Questions