1

使用 bazel 进行初始构建设置,用于在一个最小示例(具有广泛的依赖关系)上测试通用 UI 库。构建设置包括该库的规则和配置。但是,当我扩展此构建时,将依赖项目作为包(BUILD)添加到子文件夹中并将库保留为 new_local_repository - bazel 吐出错误。

它不会将该库的共享二进制文件复制到构建输出。因此,它给出了共享库或所需二进制文件丢失的随机(依赖于任何二进制文件)错误:

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

这是示例工作区文件:workspace(name = "project")

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

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

qt.构建:

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"],
)
4

1 回答 1

0

似乎有几个错误,如果删除可能会一起解决问题:

  • 规则“new_”用于添加不是用 Bazel 构建的存储库(请参阅文档
  • 当使用规则 new_local_repository 依赖不是用 Bazel 构建的 repo 时,您必须指定该 repo 的路径(您这样做了)以及用于构建该 repo 的构建文件。构建文件是相对于其他存储库的根目录简单地定义的,所以简单地 /<BUILD File)。您指定为构建文件(build_file = "//:qt.BUILD",) 的内容看起来错误。

祝你今天过得愉快 :)

于 2021-12-17T09:33:50.837 回答