I have set up bazel to build a number of CLI tools that perform various database maintenance tasks. Each one is a py_binary
or cc_binary
target that is called from the command line with the path to some data file: it processes that file and stores the results in a database.
Now, I need to create a dependent package that contains data files and shell scripts that call these CLI tools to perform application-specific database operations.
However, there doesn't seem to be a way to depend on the existing py_binary
or cc_binary
targets from a new package that only contains sh_binary
targets and data files. Trying to do so results in an error like:
ERROR: /workspace/shbin/BUILD.bazel:5:12: in deps attribute of sh_binary rule //shbin:run: py_binary rule '//pybin:counter' is misplaced here (expected sh_library)
Is there a way to call/depend on an existing bazel binary target from a shell script using sh_binary
?
I have implemented a full example here: https://github.com/psigen/bazel-mixed-binaries
Notes:
I cannot use py_library
and cc_library
instead of py_binary
and cc_binary
. This is because (a) I need to call mixes of the two languages to process my data files and (b) these tools are from an upstream repository where they are already designed as CLI tools.
I also cannot put all the data files into the CLI tool packages -- there are multiple application-specific packages and they cannot be mixed.