Skip to content

Commit

Permalink
Generate attestation tonic and message committed
Browse files Browse the repository at this point in the history
Add build steps to generate the attestation tonic services and messages
  • Loading branch information
nick-mobilecoin committed Feb 15, 2023
1 parent dfc282a commit 89f6dac
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 32 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,6 @@ jobs:
- 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
with:
files: lcov.info

notify:
runs-on: ubuntu-latest
if: failure() && ${{ github.event_name }} == 'push'
Expand All @@ -177,7 +161,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

//! 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"
));

0 comments on commit 89f6dac

Please sign in to comment.