简体   繁体   English

如何将非 bazel 项目添加为当前 bazel 项目的构建目标?

[英]How to add non-bazel project as a build target for current bazel project?

Background: I have a C++ header-only library eg: mpack mpack uses cmake build system.背景:我有一个 C++ 仅标头库,例如:mpack mpack 使用 cmake 构建系统。 However, I want to use some of its functions in my project (my_project) which uses bazel build system.但是,我想在使用 bazel 构建系统的项目 (my_project) 中使用它的一些功能。

I was following the steps from https://docs.bazel.build/versions/1.2.0/external.html#non-bazel-projects我正在按照https://docs.bazel.build/versions/1.2.0/external.html#non-bazel-projects中的步骤操作

Goal: Trying to include mpack.hpp in sni_filter.cc目标:尝试在 sni_filter.cc 中包含 mpack.hpp

My changes:我的改变:

a) Added the following snippet in WORKSPACE file a) 在 WORKSPACE 文件中添加了以下代码片段

new_local_repository(
    name = "mpack-c",
    path = "mpack-c",
    build_file = "BUILD.mpack-c",
)

b) Added BUILD.mpack-c b) 添加了 BUILD.mpack-c

cc_library(
    name = "mpack-lib",
    srcs = glob(["**"]),
    visibility = ["//visibility:public"],
)

c) Added the mpack-lib target in BUILD file of sni_filter c) 在 sni_filter 的 BUILD 文件中添加了 mpack-lib 目标

envoy_cc_library(
    name = "sni_filter_lib",
    srcs = ["sni_filter.cc"],
    hdrs = ["sni_filter.h"],    
    deps = [       
        "@mpack-c//:mpack-lib",
    ],
)

When I am trying to run a bazel build, its throwing an error:当我尝试运行 bazel 构建时,它抛出了一个错误:

ERROR: Error fetching repository: /xoxo/xyz/abc/repo/src/engine/WORKSPACE:28:21: In new_local_repository rule //external:mpack-c the 'build_file' attribute does not specify an existing file (/xoxo/xyz/abc/repo/src/engine/BUILD.mpack-c does not exist)
ERROR: /xoxo/xyz/abc/repo/src/engine/my_proj/sni_filter/BUILD:11:17: //my_proj/sni_filter:sni_filter_lib depends on @mpack-c//:mpack-lib in repository @mpack-c which failed to fetch. no such package '@mpack-c//': In new_local_repository rule //external:mpack-c the 'build_file' attribute does not specify an existing file (/xoxo/xyz/abc/repo/src/engine/BUILD.mpack-c does not exist)

Attached the directory struct附上目录结构在此处输入图像描述

The path in the new_local_repository attribute needs to either be absolute or relative to the directory the WORKSPACE file is located in. Also, the label in the build_file attribute needs to specified relative to the workspace root. new_local_repository属性中的路径需要是绝对路径或相对于WORKSPACE文件所在目录的路径。此外, build_file需要指定为相对于工作空间根目录。

So, in your WORKSPACE file replace:因此,在您的WORKSPACE文件中替换:

new_local_repository(
    name = "mpack-c",
    path = "mpack-c",
    build_file = "BUILD.mpack-c",
)

with:和:

new_local_repository(
    name = "mpack-c",
    path = "mpack",
    build_file = "mpack/BUILD.mpack-c",
)

For reference, see the documentation .有关参考,请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM