-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
587 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Check | ||
|
||
on: | ||
push: | ||
branches: | ||
- "master" | ||
pull_request: | ||
branches: | ||
- "master" | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install clippy | ||
run: rustup component add clippy | ||
- name: Run clippy | ||
run: cargo clippy --verbose | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Build | ||
run: cargo build --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Release | ||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install clippy | ||
run: rustup component add clippy | ||
- name: Run clippy | ||
run: cargo clippy --verbose | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Build | ||
run: cargo build | ||
|
||
publish: | ||
needs: [lint, build, test] | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
|
||
- name: Publish to crates.io | ||
env: | ||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | ||
run: cargo publish --token ${CARGO_REGISTRY_TOKEN} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/rust,visualstudiocode,macos | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=rust,visualstudiocode,macos | ||
|
||
### macOS ### | ||
# General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### macOS Patch ### | ||
# iCloud generated files | ||
*.icloud | ||
|
||
### Rust ### | ||
# 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 | ||
|
||
### VisualStudioCode ### | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
!.vscode/*.code-snippets | ||
|
||
# Local History for Visual Studio Code | ||
.history/ | ||
|
||
# Built Visual Studio Code Extensions | ||
*.vsix | ||
|
||
### VisualStudioCode Patch ### | ||
# Ignore all local history of files | ||
.history | ||
.ionide | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/rust,visualstudiocode,macos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "tonic-buf-build" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "A build helper that integrates buf.build to tonic-build." | ||
license = "MIT" | ||
repository = "https://github.com/Valensas/tonic-buf-build" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
tonic-build = "0.9.2" | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_yaml = "0.9.22" | ||
uuid = { version = "1.2.2", features = ["v4", "fast-rng"] } | ||
prost-build = "*" | ||
scopeguard = "1.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Valensas | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,27 @@ | ||
# tonic-buf-build | ||
A build helper that integrates buf.build to tonic-build | ||
|
||
A build helper that allows you to integrate [buf.build](https://buf.build) with [tonic-build](https://github.com/hyperium/tonic/tree/master/tonic-build). | ||
Using buf.build and tonic, you can easily manage third party dependencies for proto files and generate code for your proto files in Rust. | ||
Works with both [buf.yaml](https://buf.build/docs/configuration/v1/buf-yaml) and [buf.work.yaml](https://buf.build/docs/configuration/v1/buf-work-yaml). | ||
|
||
## Usage | ||
|
||
Add the following to your Cargo.toml: | ||
|
||
```toml | ||
tonic_buf_build = {path = "../../"} | ||
tonic-build = "*" | ||
``` | ||
|
||
Then, in your build.rs: | ||
|
||
```rust | ||
fn main() -> Result<(), tonic_buf_build::error::TonicBufBuildError> { | ||
tonic_buf_build::compile_from_buf(tonic_build::configure(), None)?; | ||
Ok(()) | ||
} | ||
``` | ||
|
||
To use buf workspaces, simply call `tonic_buf_build::compile_from_buf_workspace` instead. | ||
|
||
For complete and working examples, take a look at the examples folder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "buf-work-yaml" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
tonic = {version = "0.9.2", features = ["tls"]} | ||
tokio = {version = "1.28.2", features = ["full"]} | ||
prost = "0.11.9" | ||
|
||
[build-dependencies] | ||
tonic_buf_build = {path = "../../"} | ||
tonic-build = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Generated by buf. DO NOT EDIT. | ||
version: v1 | ||
deps: | ||
- remote: buf.build | ||
owner: googleapis | ||
repository: googleapis | ||
commit: 711e289f6a384c4caeebaff7c6931ade | ||
digest: shake256:e08fb55dad7469f69df00304eed31427d2d1576e9aab31e6bf86642688e04caaf0372f15fe6974cf79432779a635b3ea401ca69c943976dc42749524e4c25d94 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: v1 | ||
deps: | ||
- buf.build/googleapis/googleapis | ||
lint: | ||
except: | ||
- PACKAGE_VERSION_SUFFIX | ||
- PACKAGE_DIRECTORY_MATCH | ||
rpc_allow_google_protobuf_empty_requests: true | ||
rpc_allow_google_protobuf_empty_responses: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
syntax = "proto3"; | ||
package tonic_buf_build_sample; | ||
|
||
import "google/api/annotations.proto"; | ||
import "google/protobuf/empty.proto"; | ||
|
||
service HelloService { | ||
rpc SayHello(google.protobuf.Empty) returns (SayHelloResponse) { | ||
option (google.api.http) = {get: "/hello"}; | ||
} | ||
} | ||
|
||
message SayHelloResponse { | ||
string value = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version: v1 | ||
directories: | ||
- buf-module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() -> Result<(), tonic_buf_build::error::TonicBufBuildError> { | ||
tonic_buf_build::compile_from_buf_workspace(tonic_build::configure(), None)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::result::Result; | ||
|
||
use proto::{hello_service_server::HelloServiceServer, SayHelloResponse}; | ||
use tonic::{transport::Server, Request, Response, Status}; | ||
|
||
pub mod proto { | ||
tonic::include_proto!("tonic_buf_build_sample"); | ||
} | ||
|
||
#[derive(Clone)] | ||
struct HelloServer {} | ||
|
||
#[tonic::async_trait] | ||
impl proto::hello_service_server::HelloService for HelloServer { | ||
async fn say_hello(&self, _: Request<()>) -> Result<Response<SayHelloResponse>, Status> { | ||
Ok(Response::new(SayHelloResponse { | ||
value: "Hello world!".into(), | ||
})) | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let hello_server = HelloServer {}; | ||
|
||
Server::builder() | ||
.add_service(HelloServiceServer::new(hello_server)) | ||
.serve("127.0.0.1:10000".parse().unwrap()) | ||
.await | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "buf-yaml" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
tonic = {version = "0.9.2", features = ["tls"]} | ||
tokio = {version = "1.28.2", features = ["full"]} | ||
prost = "0.11.9" | ||
|
||
[build-dependencies] | ||
tonic_buf_build = {path = "../../"} | ||
tonic-build = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Generated by buf. DO NOT EDIT. | ||
version: v1 | ||
deps: | ||
- remote: buf.build | ||
owner: googleapis | ||
repository: googleapis | ||
commit: 711e289f6a384c4caeebaff7c6931ade | ||
digest: shake256:e08fb55dad7469f69df00304eed31427d2d1576e9aab31e6bf86642688e04caaf0372f15fe6974cf79432779a635b3ea401ca69c943976dc42749524e4c25d94 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: v1 | ||
deps: | ||
- buf.build/googleapis/googleapis | ||
lint: | ||
except: | ||
- PACKAGE_VERSION_SUFFIX | ||
- PACKAGE_DIRECTORY_MATCH | ||
rpc_allow_google_protobuf_empty_requests: true | ||
rpc_allow_google_protobuf_empty_responses: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() -> Result<(), tonic_buf_build::error::TonicBufBuildError> { | ||
tonic_buf_build::compile_from_buf(tonic_build::configure(), None)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
syntax = "proto3"; | ||
package tonic_buf_build_sample; | ||
|
||
import "google/api/annotations.proto"; | ||
import "google/protobuf/empty.proto"; | ||
|
||
service HelloService { | ||
rpc SayHello(google.protobuf.Empty) returns (SayHelloResponse) { | ||
option (google.api.http) = {get: "/hello"}; | ||
} | ||
} | ||
|
||
message SayHelloResponse { | ||
string value = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::result::Result; | ||
|
||
use proto::{hello_service_server::HelloServiceServer, SayHelloResponse}; | ||
use tonic::{transport::Server, Request, Response, Status}; | ||
|
||
pub mod proto { | ||
tonic::include_proto!("tonic_buf_build_sample"); | ||
} | ||
|
||
#[derive(Clone)] | ||
struct HelloServer {} | ||
|
||
#[tonic::async_trait] | ||
impl proto::hello_service_server::HelloService for HelloServer { | ||
async fn say_hello(&self, _: Request<()>) -> Result<Response<SayHelloResponse>, Status> { | ||
Ok(Response::new(SayHelloResponse { | ||
value: "Hello world!".into(), | ||
})) | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let hello_server = HelloServer {}; | ||
|
||
Server::builder() | ||
.add_service(HelloServiceServer::new(hello_server)) | ||
.serve("127.0.0.1:10000".parse().unwrap()) | ||
.await | ||
.unwrap(); | ||
} |
Oops, something went wrong.