3

All of the bazel rules put the build targets in a specific place.
I can find the targets through bazel-bin/, but they are all scattered recursively with other non-target files I don't care about.

How do I write a build rule that puts all my programs in a single bin/ directory?

Am I suppose to write my own program that traverses bazel-bin/ and rsyncs all the programs to something like usr/local/bin, or is there a query I can do? I'd like it to just be part of the build rule, but it doesn't seem like the default rules support anything like this. And I don't like the idea of having to run the build, and then run a 2nd step that syncs all my binaries to the same folder.

What is the recommended way of doing this? Its very common to want all your programs and all your tests in the same specific directories.

Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
  • Did you ever find a good solution for this? I'm trying to do the exact same thing. – gph Apr 06 '21 at 14:47
  • The accepted answer of using `pkg_tar` is what I currently do. You can also make programs that output files elsewhere on the system using `--sandbox_writable_path` with `bazel build`. That seems like an okay solution assuming you have have the artifacts you want to publish as `data` of a build rule. – Trevor Hickey Apr 12 '21 at 00:53

1 Answers1

1

Look into using pkg_tar, you can use this to declare the files/outputs you actually want to distribute and the package_dir attribute to put the files in usr/local/bin or wherever you want within the tarball.

zlalanne
  • 894
  • 5
  • 11
  • But then we would need to "tar" and "untar" everything every time. I just want my binaries all in the same place, and updated as I develop. – Trevor Hickey Dec 17 '17 at 02:44
  • I've learned to just use `bazel run` instead of needing to move binaries around. Your solution is the best for packaging and deploying after development. – Trevor Hickey May 22 '19 at 17:20