Skip to content

Commit

Permalink
Add ./rust_fmt.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
allada committed Dec 25, 2020
1 parent d845d40 commit 5c65005
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
41 changes: 21 additions & 20 deletions proto/gen_protos_tool.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
use tonic_build;
use clap::{Arg, App};
use clap::{App, Arg};
use std::path::PathBuf;
use std::vec::Vec;
use tonic_build;

fn main() -> std::io::Result<()> {
let matches = App::new("Rust gRPC Codegen")
.about("Codegen grpc/protobuf bindings for rust")
.arg(Arg::with_name("input")
.short("i")
.long("input")
.required(true)
.multiple(true)
.takes_value(true)
.help("Input proto file"))
.arg(Arg::with_name("output_dir")
.short("o")
.required(true)
.long("output_dir")
.takes_value(true)
.help("Output directory"))
.arg(
Arg::with_name("input")
.short("i")
.long("input")
.required(true)
.multiple(true)
.takes_value(true)
.help("Input proto file"),
)
.arg(
Arg::with_name("output_dir")
.short("o")
.required(true)
.long("output_dir")
.takes_value(true)
.help("Output directory"),
)
.get_matches();
let paths = matches.values_of("input").unwrap().collect::<Vec<&str>>();
let output_dir = PathBuf::from(matches.value_of("output_dir").unwrap());

tonic_build::configure()
.out_dir(&output_dir)
.format(true) // don't run `rustfmt`; shouldn't be needed to build
.compile(
&paths,
&["proto"],
)?;
.compile(&paths, &["proto"])?;
Ok(())
}
}
1 change: 0 additions & 1 deletion proto/genproto/google.protobuf.pb.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// Copyright 2020 Nathan (Blaise) Bruer. All rights reserved.

14 changes: 14 additions & 0 deletions rust_fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# Copyright 2020 Nathan (Blaise) Bruer. All rights reserved.

set -eu -o pipefail

cd "$(dirname $(realpath $0))"

RUST_FMT="./bazel-bin/external/raze__rustfmt_nightly__1_4_21/cargo_bin_rustfmt"
if [ "${1:-}" != "" ]; then
FILES="$@"
else
FILES="$(find . -name '*.rs')"
fi
echo "$FILES" | xargs $RUST_FMT --emit files --edition 2018

0 comments on commit 5c65005

Please sign in to comment.