Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

During 'bazel build', when is `target.runfiles` directory properly set up?

Tags:

bazel

For a cc_binary (or py_binary, sh_binary), when does bazel create its runfiles directory and have all symlinks correctly set up?

  • Is it created right after the cc_binary is built, and before any rule that takes this cc_binary as input, OR
  • Is it created after the whole build process of all targets is finished?

I'm trying to write a custom rule to pack the contents in the runfiles directory of a cc_binary into a tarball. This custom rule takes the cc_binary and all targets in its runfiles as input. If the runfiles directory is properly set up right after the cc_binary is built, then I just need to directly pack this directory. If not, I probably need to set up a tmp runfiles directory by myself in my custom rule.

Also, is this behavior guaranteed to keep in the future releases?

Thanks a lot!

like image 707
steiner Avatar asked Dec 05 '25 18:12

steiner


1 Answers

Bazel does not guarantee any ordering; all it guarantees is that by the end of the build, both the binary and the runfiles tree should be there.

If you want an action to be executed after both of these have been built, you need to depend on both the binary and its runfiles manifest. This doesn't guarantee, though, that the runfiles tree will be in the sandbox the packing action rules on.

I think it's possibly to craft something from ctx.actions.run(input_manifests=) and ctx.resolve_command that does that, although it's very arcane at the moment.

like image 55
lberki Avatar answered Dec 10 '25 08:12

lberki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!