X Tutup
Skip to content

Latest commit

 

History

History

Readme.md

Basic example that combines Python and C++ to create a simple executable

Goal

Show how you can use multiple programming languages to create an executable. It also demostrates how to create Bazel macros.

About the example

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 this bzl file we define a macro called hello_world, and contains the glue code to invoke the py_binary mentioned above.

  • //:code_dive, //:ndc_techtown, and everyone: Are instantiations of the hello_world macro. 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.

How to try it out

To run the different executables you call:

bazel run //:hello_world_everyone
bazel run //:hello_world_code_dive
bazel run //:hello_world_ndc_techtown

If 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
X Tutup