This tutorial shows how to build a C++ application that uses the Sift gRPC API.
Follow the official gRPC C++ tutorial to build and locally install gRPC and Protocol Buffers. You should be able to build and run the helloworld example before continuing with the next section.
Ensure that $ which grpc_cpp_plugin
and $ which protoc
generate a path to executables.
You will also need to ensure that you have the buf CLI installed.
Verify that $ which buf
generates a path to the executable, before proceeding to the compilation steps.
- Clone this repository onto your local machine and
cd
into it:
$ git clone https://github.com/sift-stack/sift
$ cd sift
- Assuming the path to the directory where we'll build the package is
$PACKAGE_DIR
, run the following command in thesift
directory that you just cloned:
$ buf export protos --output=$PACKAGE_DIR/protos --config protos/buf.yaml
The Sift protos and its imports can now be found in your $PACKAGE_DIR/protos
directory.
- Copy the
buf
template for C++ to$PACKAGE_DIR
and update theprotoc_path
variable to point to theprotoc
executable.
$ cp buf_templates/buf.gen.cpp.yaml $PACKAGE_DIR/buf.gen.yaml
-
cd
into$PACKAGE_DIR
. -
Once inside of
$PACKAGE_DIR
, ensure thatbuf.gen.yaml
is at the root. -
Compile your protobufs.
$ buf generate protos
The generated code will be in the gen
directory. Copy gen
into to any C++ projects that you want to build against.
Various examples can be found in the examples directory. To run any of those examples clone this repo, follow the steps above, then do the following:
- Copy the generated code into the example directory that you want to build:
$ cp -r $PACKAGE_DIR/gen $EXAMPLE
cd
into the example
$ cd $EXAMPLE
-
Ensure the environment variable
MY_INSTALL_DIR
holds the path to locally installed packages. -
Build the example using
cmake
:
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR ..
cmake --build . -j 4
- Run the example with required environment variables:
$ SIFT_URL=<grpc_api_url>:443 SIFT_API_KEY=<api_key> SIFT_ORGANIZATION_ID=<organization_id> ./Example