-
Notifications
You must be signed in to change notification settings - Fork 224
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
proto: bootstrap crate #508
Changes from all commits
7023841
ddd7736
2048fb3
56d735d
6323d57
48a55a6
3a49059
39e73b8
694bef2
4e3bef7
3930812
0ce1ea0
a86549a
6a7cfa3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "tendermint-proto-compiler" | ||
version = "0.1.0" | ||
authors = ["Greg Szabo <greg@informal.systems>"] | ||
edition = "2018" | ||
|
||
|
||
[dependencies] | ||
walkdir = { version = "2.3" } | ||
|
||
[build-dependencies] | ||
prost-build = { version = "0.6" } | ||
walkdir = { version = "2.3" } | ||
git2 = { version = "0.13" } | ||
|
||
[workspace] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## How to compile fresh proto structs | ||
|
||
* `git clone https://github.com/tendermint/tendermint` into the repository `target/` folder. | ||
* `cargo run` in the compiler folder. | ||
|
||
The resultant structs will be created in the `tendermint-proto/src/prost` folder. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasn't the folder renamed from tendermint-proto to proto? Would be good to double check if the above still makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, good point. Opened a quick issue about it. |
||
Build the `tendermint-proto` library. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use git2::Repository; | ||
use prost_build::compile_protos; | ||
use std::env::var; | ||
use std::path::{Path, PathBuf}; | ||
use walkdir::WalkDir; | ||
|
||
fn main() { | ||
let tendermint_dir = var("TENDERMINT_DIR").unwrap_or_else(|_| "target/tendermint".to_string()); | ||
if !Path::new(&tendermint_dir).exists() { | ||
let url = "https://github.com/tendermint/tendermint"; | ||
Repository::clone(url, &tendermint_dir).unwrap(); | ||
} | ||
let proto_paths = [format!("{}/proto", tendermint_dir)]; | ||
let proto_includes_paths = [ | ||
format!("{}/proto", tendermint_dir), | ||
format!("{}/third_party/proto", tendermint_dir), | ||
]; | ||
|
||
// List available proto files | ||
let mut protos: Vec<PathBuf> = vec![]; | ||
for proto_path in &proto_paths { | ||
protos.append( | ||
&mut WalkDir::new(proto_path) | ||
.into_iter() | ||
.filter_map(|e| e.ok()) | ||
.filter(|e| { | ||
e.file_type().is_file() | ||
&& e.path().extension().is_some() | ||
&& e.path().extension().unwrap() == "proto" | ||
}) | ||
.map(|e| e.into_path()) | ||
.collect(), | ||
); | ||
} | ||
|
||
// List available paths for dependencies | ||
let includes: Vec<PathBuf> = proto_includes_paths.iter().map(PathBuf::from).collect(); | ||
|
||
// Compile all proto files | ||
compile_protos(&protos, &includes).unwrap(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::fs::remove_dir_all; | ||
use std::fs::{copy, create_dir_all}; | ||
use walkdir::WalkDir; | ||
|
||
fn main() { | ||
let tendermint_proto_path = "../proto/src/prost"; | ||
|
||
// Remove old compiled files | ||
remove_dir_all(tendermint_proto_path).unwrap_or_default(); | ||
create_dir_all(tendermint_proto_path).unwrap(); | ||
|
||
// Copy new compiled files (prost does not use folder structures) | ||
let err: Vec<std::io::Error> = WalkDir::new(env!("OUT_DIR")) | ||
.into_iter() | ||
.filter_map(|e| e.ok()) | ||
.filter(|e| e.file_type().is_file()) | ||
.map(|e| { | ||
copy( | ||
e.path(), | ||
std::path::Path::new(&format!( | ||
"{}/{}", | ||
tendermint_proto_path, | ||
&e.file_name().to_os_string().to_str().unwrap() | ||
)), | ||
) | ||
}) | ||
.filter_map(|e| e.err()) | ||
.collect(); | ||
|
||
if !err.is_empty() { | ||
for e in err { | ||
dbg!(e); | ||
} | ||
panic!("error while copying compiled files") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "tendermint-proto" | ||
version = "0.1.0" | ||
authors = ["Greg Szabo <greg@informal.systems>"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
repository = "https://github.com/informalsystems/tendermint-rs/tree/master/tendermint-proto" | ||
readme = "README.md" | ||
categories = ["cryptography", "cryptography::cryptocurrencies", "database"] | ||
keywords = ["blockchain", "tendermint", "proto"] | ||
|
||
description = """ | ||
tendermint-proto is a the Rust implementation of the Tendermint proto structs. | ||
""" | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
|
||
[dependencies] | ||
prost = { version = "0.6" } | ||
prost-types = { version = "0.6" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
## tendermint-proto | ||
|
||
[![Crate][crate-image]][crate-link] | ||
[![Docs][docs-image]][docs-link] | ||
[![Build Status][build-image]][build-link] | ||
[![Audit Status][audit-image]][audit-link] | ||
[![Apache 2.0 Licensed][license-image]][license-link] | ||
![Rust 1.39+][rustc-image] | ||
|
||
Crate for interacting with Tendermint [proto structs][tendermint-go-proto-link]. | ||
|
||
[Documentation][docs-link] | ||
|
||
## Requirements | ||
|
||
- Rust 1.39+ | ||
|
||
## License | ||
|
||
Copyright © 2020 Informal Systems | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use the files in this repository except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
[//]: # (badges) | ||
|
||
[crate-image]: https://img.shields.io/crates/v/tendermint-proto.svg | ||
[crate-link]: https://crates.io/crates/tendermint-proto | ||
[docs-image]: https://docs.rs/tendermint-proto/badge.svg | ||
[docs-link]: https://docs.rs/tendermint-proto/ | ||
[build-image]: https://github.com/informalsystems/tendermint-rs/workflows/Rust/badge.svg | ||
[build-link]: https://github.com/informalsystems/tendermint-rs/actions?query=workflow%3ARust | ||
[audit-image]: https://github.com/informalsystems/tendermint-rs/workflows/Audit-Check/badge.svg | ||
[audit-link]: https://github.com/informalsystems/tendermint-rs/actions?query=workflow%3AAudit-Check | ||
[license-image]: https://img.shields.io/badge/license-Apache2.0-blue.svg | ||
[license-link]: https://github.com/informalsystems/tendermint-rs/blob/master/LICENSE | ||
[rustc-image]: https://img.shields.io/badge/rustc-1.39+-blue.svg | ||
|
||
[//]: # (general links) | ||
|
||
[tendermint-go-proto-link]: https://github.com/tendermint/tendermint/tree/master/proto/tendermint |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//! tendermint-proto library gives the developer access to the Tendermint proto-defined structs. | ||
|
||
// This module setup is necessary because the generated code contains "super::" calls for | ||
// dependencies. Unfortunately, prost doesn't create this for us automatically. | ||
|
||
#![deny( | ||
warnings, | ||
missing_docs, | ||
trivial_casts, | ||
trivial_numeric_casts, | ||
unused_import_braces | ||
)] | ||
#![forbid(unsafe_code)] | ||
#![doc(html_root_url = "https://docs.rs/tendermint-proto/0.1.0")] | ||
|
||
mod tendermint { | ||
pub mod abci { | ||
#![allow(missing_docs)] | ||
#![allow(clippy::large_enum_variant)] | ||
include!("prost/tendermint.abci.rs"); | ||
} | ||
pub mod blockchain { | ||
#![allow(missing_docs)] | ||
#![allow(clippy::large_enum_variant)] | ||
include!("prost/tendermint.blockchain.rs"); | ||
} | ||
pub mod consensus { | ||
#![allow(missing_docs)] | ||
include!("prost/tendermint.consensus.rs"); | ||
} | ||
pub mod crypto { | ||
#![allow(missing_docs)] | ||
include!("prost/tendermint.crypto.rs"); | ||
} | ||
pub mod evidence { | ||
#![allow(missing_docs)] | ||
include!("prost/tendermint.evidence.rs"); | ||
} | ||
pub mod libs { | ||
#![allow(missing_docs)] | ||
pub mod bits { | ||
#![allow(missing_docs)] | ||
include!("prost/tendermint.libs.bits.rs"); | ||
} | ||
} | ||
pub mod mempool { | ||
#![allow(missing_docs)] | ||
include!("prost/tendermint.mempool.rs"); | ||
} | ||
pub mod p2p { | ||
#![allow(missing_docs)] | ||
include!("prost/tendermint.p2p.rs"); | ||
} | ||
pub mod privval { | ||
#![allow(missing_docs)] | ||
include!("prost/tendermint.privval.rs"); | ||
} | ||
pub mod rpc { | ||
#![allow(missing_docs)] | ||
pub mod grpc { | ||
#![allow(missing_docs)] | ||
include!("prost/tendermint.rpc.grpc.rs"); | ||
} | ||
} | ||
pub mod state { | ||
#![allow(missing_docs)] | ||
include!("prost/tendermint.state.rs"); | ||
} | ||
pub mod statesync { | ||
#![allow(missing_docs)] | ||
include!("prost/tendermint.statesync.rs"); | ||
} | ||
pub mod store { | ||
#![allow(missing_docs)] | ||
include!("prost/tendermint.store.rs"); | ||
} | ||
pub mod types { | ||
#![allow(missing_docs)] | ||
#![allow(clippy::large_enum_variant)] | ||
include!("prost/tendermint.types.rs"); | ||
} | ||
pub mod version { | ||
#![allow(missing_docs)] | ||
include!("prost/tendermint.version.rs"); | ||
} | ||
} | ||
|
||
pub use tendermint::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to explicitly mention that this is not meant to be published (yet) via: https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened an issue for that, good point.