Skip to content

Commit

Permalink
feat: Add Rust protobuf bindings (#765)
Browse files Browse the repository at this point in the history
## Description:
<!-- Describe this change, how it works, and the motivation behind it.
-->

## Is this change user facing?
YES/NO
<!-- If yes, please add the "user facing" label to the PR -->
<!-- If yes, don't forget to include docs changes where relevant -->

## References (if applicable):
<!-- Add relevant Github Issues, Discord threads, or other helpful
information. -->
  • Loading branch information
victorcolombo committed Jun 26, 2023
1 parent fb3e922 commit 0e47003
Show file tree
Hide file tree
Showing 10 changed files with 4,059 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .circleci/config.yml
Expand Up @@ -114,6 +114,9 @@ parameters:
server-go-version:
type: string
default: "1.19"
rust-version:
type: string
default: 1.68.2
api-node-version:
type: string
default: 16.13.0
Expand Down Expand Up @@ -812,6 +815,21 @@ jobs:

# -- Publish jobs --------------------------------------------

publish_kurtosis_sdk_rust:
docker:
- image: "cimg/rust:<< pipeline.parameters.rust-version>>"
steps:
- slack/notify:
channel: engineering
event: fail
# You can preview this template and know more about templates here: https://github.com/CircleCI-Public/slack-orb/wiki#templates
template: basic_fail_1

- checkout
- run: |
cd api/rust/
cargo publish
publish_kurtosis_api_typescript:
docker:
- image: "cimg/node:<< pipeline.parameters.api-node-version>>"
Expand Down Expand Up @@ -1179,6 +1197,16 @@ workflows:
<<: *filters_ignore_main

# -- Artifact-publishing jobs --------------------------------
- publish_kurtosis_sdk_rust:
context:
- crates-publisher
- slack-secrets
filters:
branches:
ignore: /.*/
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+$/

- publish_kurtosis_api_typescript:
context:
- npmjs-user
Expand Down
17 changes: 17 additions & 0 deletions .gitignore
Expand Up @@ -100,3 +100,20 @@ tsconfig.tsbuildinfo
# meant separate and conflicting lockfiles
# We don't want NPM lockfiles for Docusaurus - just Yarn
docs/package-lock.json

# Rust SDK

# Generated by Cargo
# will have compiled files and executables
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
21 changes: 21 additions & 0 deletions api/rust/Cargo.toml
@@ -0,0 +1,21 @@
[package]
name = "kurtosis-sdk"
version = "0.0.0"
license = "BUSL-1.1"
description = "Rust SDK for Kurtosis"
edition = "2021"
readme = "README.md"
homepage = "https://kurtosis.com"
repository = "https://github.com/kurtosis-tech/kurtosis"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
prost = "0.11.9"
prost-types = "0.11.9"
tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"] }
tonic = "0.9.2"


[build-dependencies]
tonic-build = "0.9.2"
5 changes: 5 additions & 0 deletions api/rust/README.md
@@ -0,0 +1,5 @@
# Kurtosis Rust SDK

This is an SDK for [Kurtosis](https://github.com/kurtosis-tech/kurtosis), based on the protobufs available [here](https://github.com/kurtosis-tech/kurtosis/tree/main/api/protobuf);

More details can be found on the [docs](https://docs.kurtosis.com/).
21 changes: 21 additions & 0 deletions api/rust/build.rs
@@ -0,0 +1,21 @@
use std::io::Result;
use std::str;
use std::process::Command;

fn main() -> Result<()> {
// Protobuf compilation only happens inside Kurtosis monorepo
let regenerate_protobuf_bindings = option_env!("KURTOSIS_REGENERATE_BINDINGS");
if regenerate_protobuf_bindings.is_some() {
let mut kurtosis_folder_command = Command::new("git");
kurtosis_folder_command.arg("rev-parse").arg("--show-toplevel");
let kurtosis_folder = kurtosis_folder_command.output()?;
let kurtosis_folder_str = str::from_utf8(&kurtosis_folder.stdout).unwrap().trim();
return tonic_build::configure()
.out_dir("src")
.compile(&[
format!("{}/api/protobuf/engine/engine_service.proto", kurtosis_folder_str),
format!("{}/api/protobuf/core/api_container_service.proto", kurtosis_folder_str)
], &[kurtosis_folder_str])
}
Ok(())
}

0 comments on commit 0e47003

Please sign in to comment.