diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 258a2b0..a3da71e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: @@ -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: @@ -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: @@ -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 @@ -177,7 +189,6 @@ jobs: - build - test - doc - - coverage steps: - name: Notify Discord on failure uses: sarisia/actions-status-discord@v1 diff --git a/mobilecoinfoundation/attestation/messages/Cargo.toml b/mobilecoinfoundation/attestation/messages/Cargo.toml index 1ff9019..2fe13db 100644 --- a/mobilecoinfoundation/attestation/messages/Cargo.toml +++ b/mobilecoinfoundation/attestation/messages/Cargo.toml @@ -12,3 +12,7 @@ categories = ["encoding"] keywords = ["protobuf"] [dependencies] +prost = "0.11.6" + +[build-dependencies] +prost-build = "0.11.6" diff --git a/mobilecoinfoundation/attestation/messages/build.rs b/mobilecoinfoundation/attestation/messages/build.rs new file mode 100644 index 0000000..ab36654 --- /dev/null +++ b/mobilecoinfoundation/attestation/messages/build.rs @@ -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> { + 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(()) +} diff --git a/mobilecoinfoundation/attestation/messages/src/lib.rs b/mobilecoinfoundation/attestation/messages/src/lib.rs index 90b9378..c690e4a 100644 --- a/mobilecoinfoundation/attestation/messages/src/lib.rs +++ b/mobilecoinfoundation/attestation/messages/src/lib.rs @@ -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" +)); diff --git a/mobilecoinfoundation/attestation/tonic/Cargo.toml b/mobilecoinfoundation/attestation/tonic/Cargo.toml index fcf2263..f7ef43b 100644 --- a/mobilecoinfoundation/attestation/tonic/Cargo.toml +++ b/mobilecoinfoundation/attestation/tonic/Cargo.toml @@ -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" diff --git a/mobilecoinfoundation/attestation/tonic/build.rs b/mobilecoinfoundation/attestation/tonic/build.rs new file mode 100644 index 0000000..9aa0beb --- /dev/null +++ b/mobilecoinfoundation/attestation/tonic/build.rs @@ -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> { + 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(()) +} diff --git a/mobilecoinfoundation/attestation/tonic/src/lib.rs b/mobilecoinfoundation/attestation/tonic/src/lib.rs index 90b9378..e5e00cb 100644 --- a/mobilecoinfoundation/attestation/tonic/src/lib.rs +++ b/mobilecoinfoundation/attestation/tonic/src/lib.rs @@ -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" +));