bazel - 基于带有bazel的工具链选择()的最佳方法是什么?
问题描述
文档(https://docs.bazel.build/configurable-attributes.html)提供了以下示例,遗憾的是它不起作用:
cc_library(
name = "my_lib",
deps = select(
{
"//tools/cc_target_os:android": [":android_deps"],
"//tools/cc_target_os:windows": [":windows_deps"],
},
no_match_error = "Please build with an Android or Windows toolchain",
),
)
可悲的是,诸如“@platforms//os:macos”和“@platforms//os:windows”之类的匹配器只能检测到 HOST 平台,而不是 TARGET 平台。当在不同的架构上交叉编译时,这会中断。
我想出了一个有效的“android”匹配器:
config_setting(
name = "android",
values = {"crosstool_top": "//external:android/crosstool"},
)
但无法找到匹配 windows、macos 或 linux TARGET 工具链的方法。
谢谢!
解决方案
我认为您正在寻找平台:httpstarget_compatible_with
: //docs.bazel.build/versions/master/platforms.html和cc_library
.
我建议你想要类似的东西:
cc_library(
name = "my_lib_android",
deps = [":android_deps"],
target_compatible_with = [
"@platforms//os:android",
],
)
cc_library(
name = "my_lib_windows",
deps = [":windows_deps"],
target_compatible_with = [
"@platforms//os:windows",
],
)
然后,my_lib 的用户将不得不依赖 my_lib_android 或 my_lib_windows(视情况而定)。
推荐阅读
- firebase-realtime-database - Firebase 日志中的错误:警告,根据 GCLOUD_PROJECT 估计 Firebase 配置。初始化 firebase-admin 可能会失败
- mysql - MySQL中server-id和server_id的区别
- java - Open JDK 11 上的 SpringBoot - SecurityManager 处于活动状态时出现“ClassNotFound”错误
- git - 克隆存储库后,一个文件夹一直放在我的桌面上
- python - 网页抓取 : 在应答器中获取文本
内容 p 和脚本
- scrapy - 我可以安全地将 Scrapy 的 HttpCacheMiddleware 移近引擎吗?
- node.js - 使用 Sequelize 模型的问题,诸如“无法读取未定义的属性‘创建’”或未定义客户端等错误
- javascript - 将字符串转换为函数,给出 ReferenceError
- python - 在正则表达式中匹配两个字母
- linux - 如何为使用 ARCH_MULTIPLATFORM=y 的 ARM 平台指定物理内存偏移量?