-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Packaging binaries with runfiles tree #579
Comments
Can you describe this in more detail? Looking at the code it is hard to
understand the intent
of what you start with, what you end with, and if this belongs in rules_pkg
or rules_docker.
My current opinion is that rules docker should have all of the rules for
building docker images.
The job of rules_pkg is to make it easy for rules_docker to consume
pkg_files (or maybe pkg_tar)
directly. I don't know enough about building docker images to determine
requirements for that,
so you'll have to educate.
…On Fri, May 6, 2022 at 6:00 PM Milan Vukov ***@***.***> wrote:
I have a simple use-case (I believe) where I want to package a binary with
runfiles tree correctly set up inside the archive -- pretty much exactly
what rules_docker does to package a binary in a Docker layer. pkg_zip
flattens everything and that doesn't work for me (at least that was the
case when I tried to use an older version of this repo).
So, I took what I need from app_layer from rules_docker and created rule
binary_pkg_tar
<https://github.com/mvukov/rules_ros/blob/main/third_party/packaging.bzl#L306>.
This is interesting when one wants to cross-compile a binary, package it
(with all deps, data), transfer to a target device, unpack and run the
binary.
I just wanted to share this here in hope folks find it useful.
—
Reply to this email directly, view it on GitHub
<#579>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAXHHHGR26ABSHD4F3NO2FDVIWJADANCNFSM5VJLE2NQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
The goal of this little project was to create a rule that creates a valid runfiles folder for a packaged binary; simplest case: one wants to package a cc_binary/py_binary with a bit more complex deps, e.g. with data fields. At the time I created this (~1 year ago), pkg_tar would flatten the binary structure, which simply couldn't work -- in particular with py_binary targets which have external pip deps. On the other hand, rules_docker had exactly what I needed -- they basically copy+adjust runfiles folder of a binary target in My starting point was app_layer that, among other things, creates an archive (layer) given the binary. The logic inside that rule (that I copied) eventually calls build_tar.py script to build an archive. rules_pkg has a very similar build_tar.py, but I didn't have time to instigate the diffs and use that one. I think the script from rules_docker in fact reuses some logic from this repo (c.f. bazelbuild/rules_docker#1556). There is a high chance the code I put together could use build_tar.py from this repo and work equally well. If there is enough interest, the new rule I cooked could become a part of this repo. Please let me know if you need more info. |
A few thoughts
Consider a python binary that contains some SWIGed up C++ code and some data files.
Bazel would normally lay that out something like
which is a self extracting script that gives you
A pleasing packaging might be something like
where the binary parts go in .../bin and the data goes in .../lib. Bazel does not distinguish between the runfiles which are data vs those that are part of the binary. How would we remap things in a nice way? Now think of a real app, where the data dependencies might come in from hundreds of transitive deps. |
l have a very similar use-case and love your
Now I imagine the following, even more generic work flow :
I have only recently started to work with bazel, so maybe the above is totally crazy. But I'd love to hear your thoughts @aiuto @mvukov. I've also found https://github.com/dropbox/dbx_build_tools and they have |
I agree that generalization of binary_pkg_tar would be a rule that at some intermediate step returns a provider with all info to dump into a provider that can be fed into another function that assembles an archive. The rule as-is supports at the moment pip-deps and binaries. In fact, the use-case that I have in rules_ros repo is that the final app is a py_binary that has a number of pip-deps (via Regarding the "pleasing packaging" to /usr/bin and /usr/lib is something I didn't consider TBH. If am I not wrong, this would mean splitting the binary' runfiles tree into multiple folders.
I don't see any problem with this. Can you clarify, please? OK, all in all it looks like I would need to wrap my head around providers in rules_pkg. |
Yes, that's the gist :) I tested the rule with cc_binary and py_library, but I don't see why wouldn't this work with any
Yes, I envision something like this would do the job correctly. |
It looks like |
I'm hitting the same issue when trying to adopt rules_oci. My applications expects to be able to use the runfiles libs to locate runfiles but pkg_tar does not package them in a way that works for the runfiles libs. @thesayyn @alexeagle do you know of any workaround for this issue when using rules_oci? |
I can try to accelerate the PRs I have out to fold runfiles into tar and
zip. This has become a lower priority than SBOM support, so rules_license
gets all the love lately.
…On Tue, May 30, 2023 at 6:39 AM Daniel P. Purkhús ***@***.***> wrote:
I'm hitting the same issue when trying to adopt rules_oci. My applications
expect the be able to use the runfiles libs to locate runfiles but pkg_tar
does not package them in a way that works for the runfiles libs. @thesayyn
<https://github.com/thesayyn> @alexeagle <https://github.com/alexeagle>
do you know of any workaround for this issue when using rules_oci?
—
Reply to this email directly, view it on GitHub
<#579 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAXHHHD5AP34RZKWGBVSF23XIXE4LANCNFSM5VJLE2NQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@purkhusid I have been using https://gist.github.com/pauldraper/7bc811ffbef6d as a workaround. |
I've ben playing with runfiles over the weekend. I have a PR (#754) that does runfiles as per my example above. That is, you get something just like the bazel layout. For example.
And this is great, because it provides a layout where the runfiles from every app are isolated from each other. This is necessary for correctness. But... it's a breaking change from the existing runfiles, so I'm going to have to implement a legacy mode. That will be a phased migration of
Another approach I am exploring is doing legacy and correct at the same time. That will create multiple copies of the runfiles. One under the app .runfiles folder, and one at the package path. It might also be possible to just add symlinks from legacy location to the new one, so the file size does not explode. I have not looked yet. The first step will be some refactoring of code to make it easier to pick alternate behaviors. |
Since pkg_tar runfiles have been broken in the past, I'd expect approx. no one is using them, so changing the layout would not be a breaking change which requires that degree of care and a prolonged rollout period. Do you have some way to know who relies on the legacy mode? |
A few hundred instances inside Google rely on the legacy mode. Those are the only ones I know of. |
Wanted to point out that the issue of the repo mapping manifest(If you have bzlmod enabled) not being accessable in starlark will also have to handled for this feature to be useful for bzlmod users. More context here: |
The bulk of the change is to have pkg_tar use pkg_files%add_label_list to process srcs. That brings it in conformance with pkg_files and pkg_zip. This changes the behavior of runfiles to be useful, but it is a breaking change. Fixes: bazelbuild#153 Fixes: bazelbuild#579 Other bits: - do not fail verify_archive_test without a min_size or max_size - change `data` file in the sample executable from BUILD to foo.cc so that it is easier to disambiguate from other files. - fix bug in runfiles support where files were not added to file_deps list. - fix bug in runfiles support where the runfiles base was not computed correctly. - buildifier to make the linters happy.
* Bring tar runfiles up to feature parity with pkg_files.runfiles. The bulk of the change is to have pkg_tar use pkg_files%add_label_list to process `srcs`. That brings it in conformance with pkg_files and pkg_zip. This changes the behavior of runfiles to be useful, but it is a breaking change. Fixes: #153 Fixes: #579 Other bits: - do not fail verify_archive_test without a min_size or max_size - change `data` file in the sample executable from BUILD to foo.cc so that it is easier to disambiguate from other files. - fix bug in runfiles support where files were not added to file_deps list. - fix bug in runfiles support where the runfiles base was not computed correctly. - some buildifier fixes to make the linters happy.
I have a simple use-case (I believe) where I want to package a binary with runfiles tree correctly set up inside the archive -- pretty much exactly what rules_docker does to package a binary in a Docker layer. pkg_zip flattens everything and that doesn't work for me (at least that was the case when I tried to use an older version of this repo).
So, I took what I need from app_layer from rules_docker and created rule binary_pkg_tar. This is interesting when one wants to cross-compile a binary, package it (with all deps, data), transfer to a target device, unpack and run the binary.
I just wanted to share this here in hope folks find it useful.
The text was updated successfully, but these errors were encountered: