Skip to content

Commit

Permalink
Redirect Protobuf-generated code
Browse files Browse the repository at this point in the history
The old method of generating protobuf code inside the src directory is
no longer supported in Rust 1.28:
https://blog.rust-lang.org/2018/08/02/Rust-1.28.html

Signed-off-by: Bridger Herman <bridger@bitwise.io>
  • Loading branch information
Bridger Herman committed Aug 31, 2018
1 parent d898aa6 commit ecda92a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ Cargo.lock
/target
**/*.rs.bk
*.swp
/src/protos
/docs/build
17 changes: 11 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,29 @@ extern crate protoc_rust;

use protoc_rust::Customize;

use std::env;
use std::fs;
use std::fs::File;
use std::io::prelude::*;
use std::io::Write;
use std::path::Path;

fn main() {
fs::create_dir_all("src/protos").unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("protos");
let proto_path = Path::new("./protos");
fs::create_dir_all(&dest_path).unwrap();

// Run protoc
protoc_rust::run(protoc_rust::Args {
out_dir: "src/protos",
input: &["protos/pbft_message.proto"],
includes: &["protos"],
out_dir: &dest_path.to_str().unwrap(),
input: &[proto_path.join("pbft_message.proto").to_str().unwrap()],
includes: &[proto_path.to_str().unwrap()],
customize: Customize {
..Default::default()
},
}).expect("Protoc Error");

// Create mod.rs accordingly
let mut mod_file = File::create("src/protos/mod.rs").unwrap();
let mut mod_file = File::create(dest_path.join("mod.rs")).unwrap();
mod_file.write_all(b"pub mod pbft_message;\n").unwrap();
}
19 changes: 19 additions & 0 deletions src/protos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2018 Bitwise IO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://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.
* -----------------------------------------------------------------------------
*/

// Includes the autogenerated protobuf messages
include!(concat!(env!("OUT_DIR"), "/protos/mod.rs"));

0 comments on commit ecda92a

Please sign in to comment.