bazelbuild / bazelbuild/rules_pkg

Use cases for packaging runfiles

Open
#642 0 comments 3 reactions 0 assignees View on GitHub
P2
Dominant language
Starlark
Stars
253
Forks
221
Avg merge
10h 33m
Merged PRs (30d)
1

Description

I had the chance to talk to @aiuto at Bazelcon last week and I wanted to note the use cases I had in mind for the discussions we had. The discussions were related to packaging runfiles.

### Use case 1
This is already detailed in #631. We have a macro around `pkg_tar` that solves the problem. But if feels like it should really be a flag in `pkg_tar` instead.

### Use case 2
This use case is around runfiles for deployed binaries. For example, we currently have:
```python
cc_binary(
name = "bin",
...
)
pkg_files(
name = "bin_dir",
srcs = [":bin"],
prefix = "opt/foo/bin",
)
pkg_files(
name = "systemd_startup_files",
...
)
pkg_tar(
name = "deployable_tar",
srcs = [
":bin_dir",
":systemd_startup_files",
],
)
```
I.e. we have a package that gets deployed so that the binaries get started on boot by systemd. This is the most bare example I can think of that is still representative of our use case.

The trouble comes up under 2 scenarios:
1. `bin` is compiled against a pre-compiled library `libfoo.so`, or
2. `bin` has `data` dependencies. E.g. a config file `conf.json`.

In both scenarios the result is that `bin` has some runfiles. Unfortunately, it looks like the `pkg_files` rule discards runfiles information. So the `data` dependencies and the pre-compiled libraries don't make it into the tarball regardless of the `include_runfiles` attribute's value.

I don't know what the right answer is here, but it would be kind of nice to say something like this:
```python
pkg_files(
name = "bin_dir",
srcs = [":bin"],
prefix = "opt/foo/bin",
cc_runfiles_prefix = "opt/foo/lib",
data_runfiles_prefix = "opt/foo/share",
)
```
I suspect there's no way for `pkg_files` to distinguish between the binary's `data` dependencies and the .so files it links against. In that case, a simplified version that would achieve something similar would be:
```python
pkg_files(
name = "bin_dir",
srcs = [":bin"],
prefix = "opt/foo/bin",
runfiles_prefix = "opt/foo/data",
)
```
Right now we work around this by not using `pkg_fies` when we need runfiles support. Instead, we use `pkg_tar` because of its `include_runfiles` support.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.