Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tonic and message rust generation #7

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ jobs:
toolchain: ${{ matrix.rust }}
components: clippy
- uses: r7kamura/rust-problem-matchers@v1
- uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: install protoc plugins
run: |
cargo +${{ matrix.rust }} install protoc-gen-prost
cargo +${{ matrix.rust }} install protoc-gen-tonic
- run: cargo +${{ matrix.rust }} clippy --all --all-features -- -D warnings

build:
Expand All @@ -107,6 +114,13 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
- uses: r7kamura/rust-problem-matchers@v1
- uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: install protoc plugins
run: |
cargo +${{ matrix.rust }} install protoc-gen-prost
cargo +${{ matrix.rust }} install protoc-gen-tonic
- run: cargo +${{ matrix.rust }} build --release

test:
Expand All @@ -126,6 +140,13 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
- uses: r7kamura/rust-problem-matchers@v1
- uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: install protoc plugins
run: |
cargo +${{ matrix.rust }} install protoc-gen-prost
cargo +${{ matrix.rust }} install protoc-gen-tonic
- run: cargo +${{ matrix.rust }} test --release

doc:
Expand All @@ -146,23 +167,14 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
- uses: r7kamura/rust-problem-matchers@v1
- run: cargo +${{ matrix.rust }} doc --release --no-deps

coverage:
runs-on: ubuntu-22.04
needs:
- "rustfmt"
- "markdown-lint"
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- uses: taiki-e/install-action@cargo-llvm-cov
- run: cargo llvm-cov --workspace --lcov --output-path lcov.info
- uses: codecov/codecov-action@v3
- uses: arduino/setup-protoc@v1
with:
files: lcov.info
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: install protoc plugins
run: |
cargo +${{ matrix.rust }} install protoc-gen-prost
cargo +${{ matrix.rust }} install protoc-gen-tonic
- run: cargo +${{ matrix.rust }} doc --release --no-deps

notify:
runs-on: ubuntu-latest
Expand All @@ -177,7 +189,6 @@ jobs:
- build
- test
- doc
- coverage
steps:
- name: Notify Discord on failure
uses: sarisia/actions-status-discord@v1
Expand Down
4 changes: 4 additions & 0 deletions mobilecoinfoundation/attestation/messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ categories = ["encoding"]
keywords = ["protobuf"]

[dependencies]
prost = "0.11.6"

[build-dependencies]
prost-build = "0.11.6"
40 changes: 40 additions & 0 deletions mobilecoinfoundation/attestation/messages/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2023 The MobileCoin Foundation

//! Generate the prost messages for the gRPC service.

use std::{
env,
io::{Error, ErrorKind},
path::PathBuf,
process::Command,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
let protoc = prost_build::protoc_from_env();
let mut cmd = Command::new(protoc);
cmd.arg(format!("--prost_out={}", out_dir.display()));

let protos = &["../v1/attest.proto"];
let includes = &["../../../", "../"];

for i in includes {
cmd.arg("-I").arg(i);
}

for p in protos {
cmd.arg(p);
}

let output = cmd.output()?;

if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
return Err(Error::new(
ErrorKind::Other,
format!("Failed building gRPC messages: {stderr}"),
))?;
}

Ok(())
}
13 changes: 5 additions & 8 deletions mobilecoinfoundation/attestation/messages/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// Copyright (c) 2023 The MobileCoin Foundation

#![doc = include_str!("../README.md")]
#![deny(missing_docs, missing_debug_implementations, unsafe_code)]
#![deny(missing_debug_implementations, unsafe_code)]

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
include!(concat!(
env!("OUT_DIR"),
"/mobilecoinfoundation.attestation.v1.rs"
));
4 changes: 4 additions & 0 deletions mobilecoinfoundation/attestation/tonic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ keywords = ["grpc", "protobuf", "rpc"]

[dependencies]
mc-attestation-messages = { path = "../messages", version = "0.1.0" }
tonic = "0.8.3"

[build-dependencies]
prost-build = "0.11.6"
41 changes: 41 additions & 0 deletions mobilecoinfoundation/attestation/tonic/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2023 The MobileCoin Foundation
nick-mobilecoin marked this conversation as resolved.
Show resolved Hide resolved

//! Generate the tonic code for the gRPC service.

use std::{
env,
io::{Error, ErrorKind},
path::PathBuf,
process::Command,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
let protoc = prost_build::protoc_from_env();
let mut cmd = Command::new(protoc);
cmd.arg(format!("--tonic_out={}", out_dir.display()))
.arg("--tonic_opt=no_include");

let protos = &["../v1/services.proto"];
let includes = &["../../../", "../"];

for i in includes {
cmd.arg("-I").arg(i);
}

for p in protos {
cmd.arg(p);
}

let output = cmd.output()?;

if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
return Err(Error::new(
ErrorKind::Other,
format!("Failed building tonic gRPC service: {stderr}"),
))?;
}

Ok(())
}
13 changes: 6 additions & 7 deletions mobilecoinfoundation/attestation/tonic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#![doc = include_str!("../README.md")]
#![deny(missing_docs, missing_debug_implementations, unsafe_code)]

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
use mc_attestation_messages::*;

include!(concat!(
env!("OUT_DIR"),
"/mobilecoinfoundation.attestation.v1.tonic.rs"
));