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

259 views
Skip to first unread message

Sony

unread,
Mar 14, 2022, 8:00:26 PM3/14/22
to bazel-discuss
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

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)
src-dir.png

Alex Humesky

unread,
Mar 28, 2022, 10:49:39 PM3/28/22
to Sony, bazel-discuss
local_repository and new_local_repository are usually used to refer to things outside of the workspace, although they can be used to refer to things inside the workspace too (as you have here)

new_local_repository is used to add a build file from within the workspace to the external workspace, so build_file is relative to the workspace. So you might try build_file = "mpack/BUILD.mpack-c"

Note though that since mpack is already part of your workspace (i.e. vendored), and you've already written a build file for it, you don't need new_local_repository. If you rename BUILD.mpack-c to just BUILD, it will be like the rest of your workspace and you can refer to it as simply "//mpack:mpack-lib"

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/db7ca237-0ddd-4816-b0f2-e015c5f36bb4n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages