Show how you can use multiple programming languages to create an executable. It also demostrates how to create Bazel macros.
The example is structured as follows:
-
//hello_world:generator: A Python application (py_binary) that given a text file, generates a hello world C++ source file with the content of the input text file. -
//hello_world:generator.bzl: In thisbzlfile we define a macro calledhello_world, and contains the glue code to invoke thepy_binarymentioned above. -
//:code_dive,//:ndc_techtown, andeveryone: Are instantiations of thehello_worldmacro. The input file is deduced from the target name. -
//:hello_world_code_dive,//hello_world_ndc_techtown, and//:hello_world_everyone: C++ binaries that use as a source file the C++ file generated by the Python application given the input file.
To run the different executables you call:
bazel run //:hello_world_everyone
bazel run //:hello_world_code_dive
bazel run //:hello_world_ndc_techtownIf you modify the content of the different txt files and you run them again, you will see that the output displayed to the terminal changes.
You can also just generate the C++ source file that is used to create the executable as follows:
bazel build //:everyone
bazel build //:code_dive
bazel build //:ndc_techtown