English 中文(简体)
不能根据Bazel平台选择依赖
原标题:Cannot select dependency based on platform in Bazel
  • 时间:2023-10-06 17:34:58
  •  标签:
  • bazel

我正在学习Bazel,并试图建造一些第三方图书馆。 我有时使用我的马奇,有时使用我的班子计算机。 因此,当我建立<代码>开放式<> 我想根据平台使用不同的<条码>连接点

从我所读到的内容来看,应当使用<条码> 。 这是我拥有的,但当我依靠我的无赖机器时,我会:

ERROR: Target //thirdparty/opencv:opencv is incompatible and cannot be built, but was explicitly requested.
Dependency chain:
    //thirdparty/opencv:opencv (442d8d)
    //thirdparty/opencv:opencv_deps (442d8d)   <-- target platform (@local_config_platform//:host) didn t satisfy constraint @platforms//os:osx
INFO: Elapsed time: 0.284s

就像它不尊重选择吗?

load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

cc_library(
    name = "opencv_deps",
    linkopts = select({
        "@platforms//os:macos": [
        "-ldl", 
        "-lz", 
        "-lpthread",
        "-lavutil",
        "-lavformat", 
        "-lavcodec", 
        "-lswscale", 
        "-L/opt/homebrew/opt/ffmpeg/lib", 
        "-L/opt/homebrew/Cellar/libx11/1.8.6/lib", 
        "-framework Cocoa",
        "-framework Accelerate",
        ],
        "@platforms//os:linux": [
            "-ldl",
            "-lz",
            "-lpthread"
        ],
    }),
    target_compatible_with = [
        "@platforms//os:macos",
        "@platforms//os:linux"
    ],
)

cmake(
    name = "opencv",
    build_args = [
        "-j3",
    ],
    cache_entries = {
        "OPENCV_FORCE_3RDPARTY_BUILD": "ON",
        "BUILD_SHARED_LIBS": "OFF",
        "BUILD_TESTS": "OFF",
        "BUILD_PERF_TESTS": "OFF",
        "BUILD_opencv_apps": "OFF",
        "BUILD_opencv_calib3d": "OFF",
        "BUILD_opencv_core": "ON",
        "BUILD_opencv_dnn": "OFF",
        "BUILD_opencv_features2d": "OFF",
        "BUILD_opencv_flann": "OFF",
        "BUILD_opencv_gapi": "OFF",
        "BUILD_opencv_highgui": "ON",
        "BUILD_opencv_imgcodecs": "ON",
        "BUILD_opencv_imgproc": "ON",
        "BUILD_opencv_java_bindings_generator": "OFF",
        "BUILD_opencv_js": "OFF",
        "BUILD_opencv_ml": "OFF",
        "BUILD_opencv_objdetect": "OFF",
        "BUILD_opencv_photo": "OFF",
        "BUILD_opencv_python_bindings_generator": "OFF",
        "BUILD_opencv_stitching": "OFF",
        "BUILD_opencv_ts": "OFF",
        "BUILD_opencv_video": "OFF",
        "BUILD_opencv_videoio": "ON",
        "BUILD_opencv_world": "ON",
        "BUILD_IPP_IW": "ON",
        "WITH_ADE": "OFF",
        "WITH_CAROTENE": "OFF",
        "WITH_IPP": "OFF",
        "WITH_ITT": "ON",
        "WITH_OPENEXR": "OFF",
        "WITH_JASPER": "OFF",
        "WITH_JPEG": "OFF",
        "WITH_OPENJPEG": "ON",
        "WITH_TIFF": "OFF",
        "WITH_WEBP": "ON",
        "WITH_QUIRC": "ON",
        "WITH_GTK": "OFF",
        "WITH_OPENBLAS": "ON",
        "WITH_OPENCL": "OFF",
    },
    env = {
        "CMAKE_BUILD_TYPE": "RelWithDebInfo",
        "CMAKE_BUILD_PARALLEL_LEVEL": "16",
    },
    lib_source = "@opencv//:opencv_all",
    out_include_dir = "include/opencv4",
    out_static_libs = [
        "libopencv_world.a",
        "opencv4/3rdparty/libittnotify.a",
        "opencv4/3rdparty/liblibopenjp2.a",
        "opencv4/3rdparty/liblibwebp.a",
        "opencv4/3rdparty/liblibpng.a",
    ],
    targets = [
        "install",
    ],
    visibility = ["//visibility:public"],
    deps = [":opencv_deps"]
)
问题回答

You misuse the target_compatible_with attribute. It cannot have multiple values, i.e. cannot be macos and linux at the same time. Remove the target_compatible_with attribute and it should work then.

From the documentation:

目标: 标签清单;缺省为[] 制约因素清单——必须列入目标平台的价值,以便把这一目标视为兼容。 除此以外,规则类别已经规定了任何限制。 如果目标平台不能满足所有列出的限制,那么该目标就被认为不相容。





相关问题
不能根据Bazel平台选择依赖

我正在学习Bazel,并试图建造一些第三方图书馆。 我有时使用我的马奇,有时使用我的班子计算机。 因此,在我建立开放式电话时,我想根据......使用不同的连接点。

热门标签