• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use std::env;
6 use std::error::Error;
7 use std::path::PathBuf;
8 
9 type Result<T> = std::result::Result<T, Box<dyn Error>>;
10 
11 struct LocalProto {
12     // Corresponding to the input file src/$module.proto.
13     module: &'static str,
14 }
15 
16 static LOCAL_PROTOS: &[LocalProto] = &[
17     #[cfg(feature = "plugin")]
18     LocalProto { module: "plugin" },
19     #[cfg(feature = "composite-disk")]
20     LocalProto {
21         module: "cdisk_spec",
22     },
23 ];
24 
main() -> Result<()>25 fn main() -> Result<()> {
26     let out_dir = PathBuf::from(env::var("OUT_DIR")?);
27 
28     // Compile protos from the local src directory.
29     let mut proto_paths = Vec::new();
30     for proto in LOCAL_PROTOS {
31         proto_paths.push(
32             ["src", &format!("{}.proto", proto.module)]
33                 .iter()
34                 .collect::<PathBuf>(),
35         );
36     }
37     proto_build_tools::build_protos(&out_dir, proto_paths.as_slice());
38 
39     Ok(())
40 }
41