From c9a22f35e1de91e5e225d97c61baa7266890edb4 Mon Sep 17 00:00:00 2001 From: Kyrylo Baybula <64193423+Velnbur@users.noreply.github.com> Date: Fri, 31 Mar 2023 08:57:14 +0300 Subject: [PATCH] Release of 0.1.0-alpha (#1) * Init project * Make v1 module as public * Add check, lint action * Remove push * Add recursive submodules to ci * Small refactor * Fix dependencies to compile for wasm * Remove onw macro + add optional transport for client * Fix transport issue * Update protobuf * Update protobufs fix * Update README.md * Update .gitmodules * Update rust.yml * Update rust.yml --- .github/workflows/rust.yml | 84 ++++++++++++++++++++++++++++++++++++++ .gitmodules | 4 ++ Cargo.toml | 24 +++++++++++ README.md | 5 ++- build.rs | 27 ++++++++++++ protobuf | 1 + src/lib.rs | 1 + src/v1/mod.rs | 1 + 8 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/rust.yml create mode 100644 .gitmodules create mode 100644 Cargo.toml create mode 100644 build.rs create mode 160000 protobuf create mode 100644 src/lib.rs create mode 100644 src/v1/mod.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..57ebf19 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,84 @@ +on: [pull_request] + +name: Rust + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Install Protoc + uses: arduino/setup-protoc@v1 + + - name: Run cargo check + uses: actions-rs/cargo@v1 + with: + command: check + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Install Protoc + uses: arduino/setup-protoc@v1 + + - name: Run cargo test + uses: actions-rs/cargo@v1 + with: + command: test + + lints: + name: Lints + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: rustfmt, clippy + + - name: Install Protoc + uses: arduino/setup-protoc@v1 + + - name: Run cargo fmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + - name: Run cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0682393 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "protobuf"] + path = protobuf + url = git@github.com:coin-shuffle/protobuf.git + branch = v0.1.0-alpha diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..cfbb477 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "coin-shuffle-protos" +version = "0.1.0" +edition = "2021" + +[features] +default = ["server", "client", "transport"] +transport = ["tonic/transport", "tonic-build/transport"] +server = ["transport"] +client = [] + +[dependencies] +prost = "0.11.5" +tonic = { version = "0.8.3", default-features = false, features = [ + "prost", + "codegen", +] } + + +[build-dependencies] +tonic-build = { version = "0.8.4", default-features = false, features = [ + "prost", +] } +eyre = "0.6.8" diff --git a/README.md b/README.md index 53b87bd..fb8a518 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # protos -A crate for all `coin-shuffle` proto definitions in rust code + +A crate for all `coin-shuffle` proto definitions in rust code. + +Uses `protobuf` repo as protos source diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..9580c48 --- /dev/null +++ b/build.rs @@ -0,0 +1,27 @@ +use eyre::Context; + +fn main() -> eyre::Result<()> { + tonic_build::configure() + .build_client(cfg!(feature = "client")) + .build_server(cfg!(feature = "server")) + .compile( + &[ + proto_path("v1", "shuffle_service"), + proto_path("v1", "events"), + proto_path("v1", "types"), + ], + &[COIN_SHUFFLE_PROTO], + ) + .context("failed to build protos")?; + + Ok(()) +} + +const COIN_SHUFFLE_PROTO: &str = "./protobuf/"; + +fn proto_path(version: &str, proto_file: &str) -> String { + format!( + "{}/coin_shuffle/{version}/{proto_file}.proto", + COIN_SHUFFLE_PROTO + ) +} diff --git a/protobuf b/protobuf new file mode 160000 index 0000000..2256103 --- /dev/null +++ b/protobuf @@ -0,0 +1 @@ +Subproject commit 2256103ef29994e1df331f6b6f1415b07d677199 diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a3a6d96 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod v1; diff --git a/src/v1/mod.rs b/src/v1/mod.rs new file mode 100644 index 0000000..1c56571 --- /dev/null +++ b/src/v1/mod.rs @@ -0,0 +1 @@ +tonic::include_proto!("coin_shuffle.v1");