Before proceeding with installation, you will need to ensure that you have the buf CLI installed.
If $ which buf
generates a path to the executable, you may proceed to the installation steps.
To install Sift protobufs in your project:
- 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 root of your Rust project is
$PROJECT_DIR
, run the following command in thesift
directory that you just cloned:
$ buf export protos --output=$PROJECT_DIR/protos --config protos/buf.yaml
The Sift protos can and its imports can now be found in your $PROJECT_DIR/protos
directory.
- Copy the
buf
template for Rust to your project directory:
$ cp buf_templates/buf.gen.go.yaml $PROJECT_DIR/buf.gen.yaml
-
cd
into your Rust project at$PROJECT_DIR
. -
Once inside of your Rust project, declare a module called
gen
in yourmain.rs
(unless you're crate is a lib-crate) and create asrc/gen/mod.rs
file.
// main.go
/// Sift generated code
mod gen;
Refer to the buf.gen.yaml
in your project root if you need to modify the output path for the compiled protos.
- Inside of the root of your project directory you may now compile your protobufs:
$ buf generate protos
Your project up to this point should look like the following (full depth not shown):
example_project
├─ src
│ ├─ main.rs
│ └─ gen
│ ├─ sift.common.type.v1.rs
│ ├─ sift.runs.v2.rs
│ ├─ sift.annotation_logs.v1.rs
│ ├─ sift.runs.v2.tonic.rs
│ ├─ sift.users.v2.rs
│ ├─ mod.rs
│ ├─ sift.tags.v1.rs
│ ├─ sift.assets.v1.tonic.rs
│ ├─ sift.assets.v1.rs
│ ├─ sift.notifications.v1.tonic.rs
│ ├─ sift.users.v2.tonic.rs
│ ├─ sift.annotation_logs.v1.tonic.rs
│ ├─ grpc.gateway.protoc_gen_openapiv2.options.rs
│ ├─ sift.notifications.v1.rs
│ ├─ sift.annotations.v1.tonic.rs
│ ├─ google.api.rs
│ └─ sift.annotations.v1.rs
├─ buf.gen.yaml
├─ README.md
├─ Cargo.lock
└─ Cargo.toml
2 directories, 22 files
- Ensure you have the following dependencies installed:
[package]
name = "sift_cli"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
async-trait = "0.1.79"
prost = "0.12.4"
prost-types = "0.12.4"
tonic = { version = "0.11.0", features = ["tls", "tls-roots", "tls-webpki-roots"] }
- Declare the modules that will import the generated code in your
src/gen/mod.rs
. For example, we wish to use the generatedannotations
code for this example:
#[path = "sift.annotations.v1.rs"]
pub mod annotations;
- Now your project should be ready to use the generated Rust code to interact with Sift's gRPC API. Please refer to the example code for usage.