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 LocalProto {
24 module: "registered_events",
25 },
26 ];
27
main() -> Result<()>28 fn main() -> Result<()> {
29 let out_dir = PathBuf::from(env::var("OUT_DIR")?);
30
31 // Compile protos from the local src directory.
32 let mut proto_paths = Vec::new();
33 for proto in LOCAL_PROTOS {
34 proto_paths.push(
35 ["src", &format!("{}.proto", proto.module)]
36 .iter()
37 .collect::<PathBuf>(),
38 );
39 }
40 proto_build_tools::build_protos(&out_dir, proto_paths.as_slice());
41
42 Ok(())
43 }
44