Does bazel support preprocessing?

105 views
Skip to first unread message

zero

unread,
Jun 29, 2022, 9:15:46 PM6/29/22
to bazel-discuss
I want to automatically generate proto build files and write a python script to automatically generate build files. It works well and next step I want to integrate it into bazel.

I can think of the following ways
1. genrule, the questions is how can I ensue it will run before compile the proto files
2. create a rule and  use like "bazel run //:buildifier"

Thanks for any advice!

Xudong Yang

unread,
Jun 30, 2022, 4:17:33 AM6/30/22
to zero, bazel-discuss
Bazel doesn't touch files in the source tree during a build, so this is by design impossible.

However, bazel-gazelle could very much meet your needs. It originated as a BUILD file generator for Go, but can be extended for many other languages.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/7a54a072-091e-4b7d-be67-5b1015e975ban%40googlegroups.com.

Kirill Zabelin

unread,
Jun 30, 2022, 4:31:52 AM6/30/22
to Xudong Yang, zero, bazel-discuss
If you want to automatically generate bazel BUILD files you also probably can take a look at repository_rule, which allows you to generate a new workspace and then reference it in the main workspace. But since repository_rule works in load phase in impl function you can't use any target/Providers from analysis phase.

Thanks,
Kirill

zero

unread,
Jun 30, 2022, 11:38:30 AM6/30/22
to bazel-discuss
Hi Kirill, The method you say is something like "create a rule and  use like "bazel run //:buildifier"". And yes, I need to analysis dependency for the proto. It's not complicated because its dependencies are simple.

bazel-gazelle seems to be an implemented tool, which is support protobuf. I will learn if it meets my needs.

Thanks for your advice!

Reply all
Reply to author
Forward
0 new messages