Bazel 构建:通过命令行参数化的依赖项

发布于 2025-01-12 22:11:57 字数 634 浏览 3 评论 0原文

我有一个 C/C++ 插件项目,其中有不同的实现,我希望能够在构建时选择使用哪个实现。

WORKSPACE
plugin/
    BUILD
    plugin.c
    plugin.h
plugin_impl1/
    BUILD
    ...
plugin_impl2/
    BUILD
    ...

plugin_impl1/BUILD:

cc_library(
  name = "plugin_impl1"
  srcs = [...]
  hdrs = [...]
)

plugin_impl2/BUILD:

cc_library(
  name = "plugin_impl2"
  srcs = [...]
  hdrs = [...]
)

我想知道如何编写plugin/BUILD,以便我可以编写如下内容:

bazel build //plugin --which plugin_impl2

可执行文件名称应始终相同,因此不能选择具有不同目标名称(对于插件)的多个规则。

I have a project for a plugin in C/C++ where I have different implementations and I would like to be able to select which implementation to use when building.

WORKSPACE
plugin/
    BUILD
    plugin.c
    plugin.h
plugin_impl1/
    BUILD
    ...
plugin_impl2/
    BUILD
    ...

plugin_impl1/BUILD:

cc_library(
  name = "plugin_impl1"
  srcs = [...]
  hdrs = [...]
)

plugin_impl2/BUILD:

cc_library(
  name = "plugin_impl2"
  srcs = [...]
  hdrs = [...]
)

I want to know how to write plugin/BUILD so that I could write something like:

bazel build //plugin --which plugin_impl2

The executable name should always be the same so having multiple rules with different target names (for plugin) is not an option.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文