-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a8ffbb
commit a25844d
Showing
7 changed files
with
601 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: v1 | ||
plugins: | ||
- name: grpc_cpp | ||
out: gen/proto/cpp | ||
# grpc_cpp_plugin must be installed and accessible in PATH environment variable | ||
path: grpc_cpp_plugin | ||
- name: cpp | ||
out: gen/proto/cpp | ||
# Add path to protoc | ||
protoc_path: <todo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Sift C++ | ||
|
||
This tutorial shows how to build a C++ application that uses the Sift gRPC API. | ||
|
||
## Installation | ||
|
||
##### Build gRPC and Protocol Buffers | ||
|
||
Follow the [official gRPC C++ tutorial](https://grpc.io/docs/languages/cpp/quickstart/#install-grpc) to build and locally install gRPC and Protocol Buffers. You should be able to build and run the [helloworld](https://grpc.io/docs/languages/cpp/quickstart/#build-the-example) 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](https://buf.build/docs/installation) installed. | ||
|
||
Verify that `$ which buf` generates a path to the executable, before proceeding to the compilation steps. | ||
|
||
##### C++ Protobuf Compilation | ||
|
||
1. Clone this repository onto your local machine and `cd` into it: | ||
|
||
```bash | ||
$ git clone https://github.com/sift-stack/sift | ||
$ cd sift | ||
``` | ||
|
||
2. Assuming the path to the directory where we'll build the package is `$PACKAGE_DIR`, run the following command in the `sift` directory that you just cloned: | ||
|
||
```bash | ||
$ 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. | ||
|
||
3. Copy the `buf` template for C++ to `$PACKAGE_DIR` and update the `protoc_path` variable to point to the `protoc` executable. | ||
|
||
```bash | ||
$ cp buf_templates/buf.gen.cpp.yaml $PACKAGE_DIR/buf.gen.yaml | ||
``` | ||
|
||
4. `cd` into `$PACKAGE_DIR`. | ||
|
||
5. Once inside of `$PACKAGE_DIR`, ensure that `buf.gen.yaml` is at the root. | ||
|
||
6. Compile your protobufs. | ||
|
||
```bash | ||
$ 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. | ||
|
||
|
||
## Examples | ||
|
||
Various examples can be found in the [examples](./examples) directory. To run any of those examples clone this repo, follow the steps above, then do the following: | ||
|
||
1. Copy the generated code into the example directory that you want to build: | ||
``` | ||
$ cp -r $PACKAGE_DIR/gen $EXAMPLE | ||
``` | ||
|
||
2. `cd` into the example | ||
``` | ||
$ cd $EXAMPLE | ||
``` | ||
|
||
3. Ensure the environment variable `MY_INSTALL_DIR` holds the path to [locally installed packages](https://grpc.io/docs/languages/cpp/quickstart/#setup). | ||
|
||
4. Build the example using `cmake`: | ||
``` | ||
mkdir build | ||
cd build | ||
cmake -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR .. | ||
cmake --build . -j 4 | ||
``` | ||
|
||
5. Run the example with required environment variables: | ||
``` | ||
$ SIFT_URL=<grpc_api_url>:443 SIFT_API_KEY=<api_key> SIFT_ORGANIZATION_ID=<organization_id> ./Example | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(IngestionExample) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
find_package(Protobuf CONFIG REQUIRED) | ||
find_package(gRPC CONFIG REQUIRED) | ||
|
||
# Include the generated files directory | ||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/gen/proto/cpp) | ||
|
||
# Gather all generated .pb.cc and .grpc.pb.cc files | ||
file(GLOB_RECURSE PROTO_SRC "${CMAKE_CURRENT_SOURCE_DIR}/gen/proto/cpp/*.pb.cc" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/gen/proto/cpp/*.grpc.pb.cc") | ||
file(GLOB_RECURSE PROTO_HDR "${CMAKE_CURRENT_SOURCE_DIR}/gen/proto/cpp/*.pb.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/gen/proto/cpp/*.grpc.pb.h") | ||
|
||
# Add your application source files here | ||
set(SOURCE_FILES ingest.cc ${PROTO_SRC} ${PROTO_HDR}) | ||
|
||
add_executable(IngestionExample ${SOURCE_FILES}) | ||
|
||
target_link_libraries(IngestionExample PRIVATE gRPC::grpc++ protobuf::libprotobuf) |
Oops, something went wrong.