Skip to content

Commit

Permalink
Moved proto-compiler under tools and fixed main.rs paths (#754)
Browse files Browse the repository at this point in the history
* Moved proto-compiler under tools and fixed main.rs paths

* Fixed folder separators
  • Loading branch information
greg-szabo authored Jan 11, 2021
1 parent 4356b39 commit 4000253
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 18 deletions.
1 change: 0 additions & 1 deletion proto-compiler/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

members = [
"kvstore-test",
"proto-compiler",
"rpc-probe"
]
2 changes: 0 additions & 2 deletions proto-compiler/Cargo.toml → tools/proto-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ prost-build = { version = "0.6" }
git2 = { version = "0.13" }
tempdir = { version = "0.3" }
subtle-encoding = { version = "0.5" }

[workspace]
3 changes: 1 addition & 2 deletions proto-compiler/README.md → tools/proto-compiler/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## 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 `proto/src/prost` folder.
Build the `tendermint-proto` library.
Build the `tendermint-proto` crate.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub fn copy_files(src_dir: &PathBuf, target_dir: &PathBuf) {
}

/// Walk through the list of directories and gather all *.proto files
pub fn find_proto_files(proto_paths: Vec<String>) -> Vec<PathBuf> {
pub fn find_proto_files(proto_paths: Vec<PathBuf>) -> Vec<PathBuf> {
let mut protos: Vec<PathBuf> = vec![];
for proto_path in &proto_paths {
protos.append(
Expand Down
39 changes: 27 additions & 12 deletions proto-compiler/src/main.rs → tools/proto-compiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,33 @@ use constants::{

fn main() {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let tendermint_lib_target = root.join("../proto/src/tendermint.rs");
let target_dir = root.join("../proto/src/prost");
let tendermint_lib_target = root
.join("..")
.join("..")
.join("proto")
.join("src")
.join("tendermint.rs");
let target_dir = root
.join("..")
.join("..")
.join("proto")
.join("src")
.join("prost");
let out_dir = var("OUT_DIR")
.map(PathBuf::from)
.or_else(|_| TempDir::new("tendermint_proto_out").map(|d| d.into_path()))
.unwrap();
let tendermint_dir = var("TENDERMINT_DIR").unwrap_or_else(|_| "target/tendermint".to_string());
let tendermint_dir = PathBuf::from(var("TENDERMINT_DIR").unwrap_or_else(|_| {
root.join("..")
.join("target")
.join("tendermint")
.to_str()
.unwrap()
.to_string()
}));

println!(
"[info] => Fetching {} at {} into {}",
"[info] => Fetching {} at {} into {:?}",
TENDERMINT_REPO, TENDERMINT_COMMITISH, tendermint_dir
);
get_commitish(
Expand All @@ -30,15 +47,13 @@ fn main() {
TENDERMINT_COMMITISH,
); // This panics if it fails.

let proto_paths = [format!("{}/proto", tendermint_dir)];
let proto_includes_paths = [
format!("{}/proto", tendermint_dir),
format!("{}/third_party/proto", tendermint_dir),
let proto_paths = vec![tendermint_dir.join("proto")];
let proto_includes_paths = vec![
tendermint_dir.join("proto"),
tendermint_dir.join("third_party").join("proto"),
];
// List available proto files
let protos = find_proto_files(proto_paths.to_vec());
// List available paths for dependencies
let includes: Vec<PathBuf> = proto_includes_paths.iter().map(PathBuf::from).collect();
let protos = find_proto_files(proto_paths);

// Compile proto files with added annotations, exchange prost_types to our own
let mut pb = prost_build::Config::new();
Expand All @@ -62,7 +77,7 @@ fn main() {
"super::super::google::protobuf::Timestamp",
);
println!("[info] => Creating structs.");
pb.compile_protos(&protos, &includes).unwrap();
pb.compile_protos(&protos, &proto_includes_paths).unwrap();

println!("[info] => Removing old structs and copying new structs.");
copy_files(&out_dir, &target_dir); // This panics if it fails.
Expand Down

0 comments on commit 4000253

Please sign in to comment.