From 70339e07f9ad3d7e38e026a30790525a3aa90870 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Thu, 3 Sep 2020 14:45:18 +1000 Subject: [PATCH] rslib: auto-format protobuf code prost-build doesn't generate rustfmt-safe code, so we had to add it to the ignore list for rustfmt on "make check". However, the ignore list isn't supported by stable rustfmt, so we have to work around this some other way -- in this case, just do "rustfmt" on the generated file in "build.rs" (this way, formatting errors in checked-in source code are still caught but generated code doesn't cause spurrious errors). Signed-off-by: Aleksa Sarai --- rslib/build.rs | 14 ++++++++++---- rslib/rustfmt.toml | 1 - 2 files changed, 10 insertions(+), 5 deletions(-) delete mode 100644 rslib/rustfmt.toml diff --git a/rslib/build.rs b/rslib/build.rs index 9722afc41..5c044fcc6 100644 --- a/rslib/build.rs +++ b/rslib/build.rs @@ -1,6 +1,7 @@ use std::fmt::Write; use std::fs; use std::path::Path; +use std::process::Command; use fluent_syntax::ast::{Entry::Message, ResourceEntry}; use fluent_syntax::parser::parse; @@ -200,15 +201,20 @@ fn main() -> std::io::Result<()> { fs::write(rust_string_path, rust_string_vec(&idents))?; // output protobuf generated code - // we avoid default OUT_DIR for now, as it breaks code completion - std::env::set_var("OUT_DIR", "src"); println!("cargo:rerun-if-changed=../proto/backend.proto"); - let mut config = prost_build::Config::new(); - config.service_generator(service_generator()); config + // we avoid default OUT_DIR for now, as it breaks code completion + .out_dir("src") + .service_generator(service_generator()) .compile_protos(&["../proto/backend.proto"], &["../proto"]) .unwrap(); + // rustfmt the protobuf code + let rustfmt = Command::new("rustfmt") + .arg(Path::new("src/backend_proto.rs")) + .status() + .unwrap(); + assert!(rustfmt.success(), "rustfmt backend_proto.rs failed"); // write the other language ftl files let mut ftl_lang_dirs = vec!["./ftl/repo/core".to_string()]; diff --git a/rslib/rustfmt.toml b/rslib/rustfmt.toml deleted file mode 100644 index bd0ab67a8..000000000 --- a/rslib/rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -ignore = ["backend_proto.rs"]