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
cdinto 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 thesiftdirectory that you just cloned:
$ buf export protos --output=$PACKAGE_DIR/protos --config protos/buf.yamlThe Sift protos and its imports can now be found in your $PACKAGE_DIR/protos directory.
- Copy the
buftemplate for C++ to$PACKAGE_DIRand update theprotoc_pathvariable to point to theprotocexecutable.
$ cp buf_templates/buf.gen.cpp.yaml $PACKAGE_DIR/buf.gen.yaml-
cdinto$PACKAGE_DIR. -
Once inside of
$PACKAGE_DIR, ensure thatbuf.gen.yamlis at the root. -
Compile your protobufs.
$ buf generate protosThe 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
cdinto the example
$ cd $EXAMPLE
-
Ensure the environment variable
MY_INSTALL_DIRholds 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:
$ BASE_URI=<grpc_api_url>:443 SIFT_API_KEY=<api_key> SIFT_ORGANIZATION_ID=<organization_id> ./Example