'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. However, I want to use some of its functions in my project (my_project) which uses bazel build system.
I was following the steps from https://docs.bazel.build/versions/1.2.0/external.html#non-bazel-projects
Goal: Trying to include mpack.hpp in sni_filter.cc
My changes:
a) Added the following snippet in WORKSPACE file
new_local_repository(
name = "mpack-c",
path = "mpack-c",
build_file = "BUILD.mpack-c",
)
b) Added 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
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 :
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)
Solution 1:[1]
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.
So, in your WORKSPACE file replace:
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | chuckx |

