When I first started writing custom Bazel rules, I often created
separate rules for the build and run commands in Bazel.
For example, I once wrote rules that looked something like:
1
2
3
4
5
6
7
8
9
azure_function_app_build(
name ="my_app",
srcs = ["..."],
)
azure_function_app_run(
name ="run_app",
app =":my_app",
)
My expectation that users would bazel build //:my_app and
bazel run //:run_app.
This separation is silly and unnecessary. A Bazel rule can support
both build and run at the same time. All you have to do is declare
the rule as executable and have it return a DefaultInfo() object with
both an executable and a files attribute.
For example, here is an example of a extremely simplistic cc_binary()
rule: