github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/sdk/rust/build.rs (about) 1 /* 2 * Copyright 2017 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * ------------------------------------------------------------------------------ 16 */ 17 18 extern crate cc; 19 extern crate glob; 20 extern crate protoc_rust; 21 22 use std::fs; 23 24 use protoc_rust::Customize; 25 26 fn main() { 27 // Compile C PEM loader file 28 if cfg!(feature = "pem") { 29 println!("cargo:rustc-link-lib={}={}", "dylib", "crypto"); 30 cc::Build::new() 31 .file("../c/loader.c") 32 .file("../c/c11_support.c") 33 .include("../c") 34 .compile("libloader.a"); 35 } 36 37 // Generate protobuf files 38 let proto_src_files = glob_simple("../../protos/*.proto"); 39 println!("{:?}", proto_src_files); 40 41 fs::create_dir_all("src/messages").unwrap(); 42 43 protoc_rust::run(protoc_rust::Args { 44 out_dir: "src/messages", 45 input: &proto_src_files 46 .iter() 47 .map(|a| a.as_ref()) 48 .collect::<Vec<&str>>(), 49 includes: &["src", "../../protos"], 50 customize: Customize { 51 ..Default::default() 52 }, 53 }).expect("unable to run protoc"); 54 } 55 56 fn glob_simple(pattern: &str) -> Vec<String> { 57 glob::glob(pattern) 58 .expect("glob") 59 .map(|g| { 60 g.expect("item") 61 .as_path() 62 .to_str() 63 .expect("utf-8") 64 .to_owned() 65 }) 66 .collect() 67 }