Hi,
rules_pkg has various packaging rules.
pkg_tar is the basic one to build tarballs. There are also pkg_deb and pkg_rpm for building those up into installable packages.
Those rules don't directly know anything about how to package C++ code. There are a lot of decisions to make about what to package where which I think you'll need to answer for your use case. I see three options which might make sense, depending on what you're looking for:
The easiest approach is manually specifying all the files (headers, output libraries, etc) you want to package in pkg_tar rules. This is very straightforward and should work fine for small/simple projects.
The next-more-complicated approach is writing a
macro to automatically creates a pkg_tar and corresponding cc_library, and then using it instead of cc_library directly. This doesn't require digging into any complicated APIs from the C++ rules, while still letting you customize the paths everything ends up at. To me, the main limitation is having to manually track dependencies between libraries, which will get complicated if you have deeply nested dependency trees. You could write a pkg_tar which collects up the pkg_tars from each library to combine them at the end. Something like this:
def cc_install_library(name, srcs, hdrs):
native.cc_library(name = name, srcs = srcs, hdrs = hdrs):
pkg_tar(name = name + '_install', srcs = hdrs + [':%s.so' % name], package_dir = 'usr/lib')
The most complicated approach would be a
custom rule that looks at the
CcInfo provider from the cc_library rules and packages the files based on that. This provides access to all of the information about the libraries, their source files, their outputs, and how those all relate. The downside is having to work with the APIs that provide all of that information. You can re-use some of the pieces from rules_pkg to build up tarballs of the files you want (I'd start by looking at how pkg_tar works).
Brian