mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 18:20:34 +00:00
4c2017c757
This crate is effectively a collection of stubs in this repo, but will allow a downstream repo to implement those stubs. BUG=b:213152497 FIXED=b:213152497 TEST=build + kokoro Change-Id: I3c544644ec3d7917f9ebb2e8621042c35b556db8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3622799 Reviewed-by: Noah Gold <nkgold@google.com> Commit-Queue: Michael Hoyle <mikehoyle@google.com> Tested-by: kokoro <noreply+kokoro@google.com>
52 lines
1.6 KiB
Rust
52 lines
1.6 KiB
Rust
// Copyright 2022 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.
|
|
|
|
use protoc_rust::{Codegen, Customize};
|
|
use std::fs::File;
|
|
use std::io::Write;
|
|
use std::path::PathBuf;
|
|
use std::{env, fs};
|
|
|
|
fn main() {
|
|
build_protos();
|
|
}
|
|
|
|
// TODO(mikehoyle): Unify all proto-building logic across crates into a common build dependency.
|
|
fn build_protos() {
|
|
let proto_files = vec!["protos/event_details.proto"];
|
|
let out_dir = format!(
|
|
"{}/metrics_protos",
|
|
env::var("OUT_DIR").expect("OUT_DIR env does not exist.")
|
|
);
|
|
fs::create_dir_all(&out_dir).unwrap();
|
|
|
|
Codegen::new()
|
|
.out_dir(&out_dir)
|
|
.inputs(&proto_files)
|
|
.customize(Customize {
|
|
serde_derive: Some(true),
|
|
..Default::default()
|
|
})
|
|
.run()
|
|
.unwrap();
|
|
create_gen_file(proto_files, &out_dir);
|
|
}
|
|
|
|
fn create_gen_file(proto_files: Vec<&str>, out_dir: &str) {
|
|
let generated = PathBuf::from(&out_dir).join("generated.rs");
|
|
let out = File::create(generated).expect("Failed to create generated file.");
|
|
|
|
for proto in proto_files {
|
|
let file_stem = PathBuf::from(proto)
|
|
.file_stem()
|
|
.unwrap()
|
|
.to_str()
|
|
.unwrap()
|
|
.to_owned();
|
|
let out_dir = out_dir.replace("\\", "/");
|
|
writeln!(&out, "#[path = \"{}/{}.rs\"]", out_dir, file_stem)
|
|
.expect("failed to write to generated.");
|
|
writeln!(&out, "pub mod {}_proto;", file_stem).expect("failed to write to generated.");
|
|
}
|
|
}
|