File convertor

18 views
Skip to first unread message

Alexander Kornilov

unread,
Dec 19, 2024, 3:47:51 PM (7 days ago) Dec 19
to bazel-discuss
I am newbie in Bazel world and need some help.
My task is support of new kind of files in C++ project. I have file preprocessor: cxx2cpp <input *.cxx file> <output *.cpp> which can convert single .cxx to to .cpp file. So I need convert some set of *.cxx files and pass generated .cpp files to cc_binary/cc_library.
I have read about rules:
https://bazel.build/rules/rules-tutorial
https://bazel.build/extending/rules
https://bazel.build/reference/be/general#genrule

But still don't understand what is correct way to do it.
Could you please advise right way to solve my task?

Alexandre Rostovtsev

unread,
Dec 20, 2024, 3:55:58 AM (6 days ago) Dec 20
to Alexander Kornilov, bazel-discuss
There are 3 ways to solve this: you can write a symbolic macro which calls a genrule, a legacy macro which calls a genrule, or you can write your own rule. A macro would be shorter and easier to write; a rule is better if in future you want more complex behavior (such as changing the cxx2cpp command line depending on a flag you passed to bazel), and will give your users better error messages and `bazel query` support.

For symbolic macros (bazel 8 and newer only), see https://bazel.build/rules/macro-tutorial

For legacy macros (all bazel versions), see https://bazel.build/rules/legacy-macro-tutorial

For a simple example of a rule which calls a command-line tool, see https://github.com/bazelbuild/examples/blob/main/rules/actions_run/execute.bzl

--
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 visit https://groups.google.com/d/msgid/bazel-discuss/3a488b46-c6b3-4db3-a151-081a70331602n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages