Compilation

Prerequisites

Be sure to have read the previous section before proceeding.

This section will use Python as an example but the process can be adapted for any programming language when generating code from Sift's protocol buffers.

Selecting Plugins

The Buf Schema Registry hosts various plugins that you can use to generate code for your language of choice. The plugins can be found at this link.

  1. Identify plugins for your chosen programming language
  2. Create a buf.gen.yaml file to specify your selected plugins
# buf.gen.yaml
version: v1
managed:
  enabled: true
plugins:
  - plugin: buf.build/grpc/python:v1.62.1
    out: gen
  - plugin: buf.build/protocolbuffers/python
    out: gen
  - plugin: buf.build/protocolbuffers/pyi:v26.1
    out: gen

You can modify the out field for each plugin to change where the generated code gets emitted.

Runtime Dependencies

For many of these plugins to work properly after the code has been generated, additional runtime dependencies may be required. Visit the documentation for each plugin you're using for more information on what is needed.

Generating Code

After creating your buf.gen.yaml, follow these steps to generate code from Sift's protocol buffers:

  1. Export Sift's protocol buffers to your project directory:

    buf export protos --output=<OUTPUT_DIR> --config <PATH_TO_SIFT_BUF_CONFIG>

    Replace:

    • <OUTPUT_DIR> with the path to where protocol buffers will be emitted
    • <PATH_TO_SIFT_BUF_CONFIG> should be replaced with the path to the cloned buf.yaml
  2. Verify that Sift's protocol buffers are now in your <OUTPUT_DIR>

  3. Ensure that you are in the same directory as your buf.gen.yaml

  4. Run the following command:

    buf generate <OUTPUT_DIR>

OUTPUT_DIR is the same directory containing Sift's protocol buffers. If successful, the generated code will be emitted in the directory specified in your buf.gen.yaml.

On this page