I need to build my project with bazel and it uses libcap-dev as a dependency. how to use that inside bazel? I tried used the genrule to install it but i can’t use sudo inside the cmd section. I don’t want to rebuild the package inside my code but if there is no other option please tell me how.
2
Answers
Using packages from apt is not the most "bazelist" way to do manage dependencies. It would depend a lot on how your
sources.list
is configured and would not be hermetic at all.Build time dependency
I guess you need headers files as build-time dependencies.
You can grab tarballs from https://packages.debian.org/sid/libcap-dev with https://bazel.build/rules/lib/repo/http#http_archive or directly use the source repository https://salsa.debian.org/debian/libcap2 with the https://bazel.build/rules/lib/repo/git#new_git_repository rule.
Then you can import the lib with https://bazel.build/reference/be/c-cpp#cc_import
Runtime dependency
It depends a lot on what you are building. If you intend to run your project through
bazel run
with dynamically linked lib you will have to include the.so
files in thecc_library
for the matchingcc_binary
to find them.If you intend to build a debian package that can be distributed you will have to add libcap as a dependency of this package.
Example
The Drake robotics project has a deb archive rule: https://github.com/RobotLocomotion/drake/blob/master/tools/workspace/deb.bzl