blob: 9cc56ef041029fe0b185640cd0c5acae898b009c [file] [log] [blame]
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
extern crate protoc_rust;
use std::env;
use std::fs;
use std::io::Write;
use std::path::{Path, PathBuf};
use protoc_rust::Customize;
/// Outputs rerun-if-changed directives to cargo, as described
/// in These are required if we want
/// `cargo` to rerun this script when external dependencies (e.g., proto files) get updated.
fn note_rerun_if_changed(p: &Path) {
println!("cargo:rerun-if-changed={}", p.display());
if p.is_dir() {
let error_message = format!("reading dir {}", p.display());
for ent in p.read_dir().expect(&error_message) {
fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let proto_root = match env::var("SYSROOT") {
Ok(dir) => PathBuf::from(dir).join("usr/include/chromeos"),
// Make this work when typing "cargo build" in platform2/metrics/memd
Err(_) => PathBuf::from("../../system_api"),
let proto_dir = proto_root.join("dbus/metrics_event");
let proto_file = proto_dir.join("metrics_event.proto");
let input_files = &[proto_file];
for file in input_files {
let includes_files = &[proto_dir];
for file in includes_files {
protoc_rust::run(protoc_rust::Args {
out_dir: out_dir.as_os_str().to_str().unwrap(),
input: &input_files
.map(|x| x.to_str().unwrap())
includes: &includes_files
.map(|x| x.to_str().unwrap())
customize: Customize {
let mut mod_out = fs::File::create(out_dir.join("")).unwrap();
"#[path = \"{}\"] pub mod plugin_proto;\npub use plugin_proto::*;",