2020-07-25 03:43:01 +00:00
|
|
|
use std::{
|
|
|
|
env, fs,
|
|
|
|
ops::Deref,
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
};
|
2015-05-09 10:07:24 +00:00
|
|
|
|
2020-07-25 03:43:01 +00:00
|
|
|
fn out_dir() -> PathBuf {
|
|
|
|
Path::new(&env::var("OUT_DIR").expect("env")).to_path_buf()
|
|
|
|
}
|
2016-11-21 02:48:17 +00:00
|
|
|
|
2020-07-25 03:43:01 +00:00
|
|
|
fn cleanup() {
|
|
|
|
let _ = fs::remove_dir_all(&out_dir());
|
|
|
|
}
|
2016-11-21 02:48:17 +00:00
|
|
|
|
2020-07-25 03:43:01 +00:00
|
|
|
fn compile() {
|
|
|
|
let proto_dir = Path::new(&env::var("CARGO_MANIFEST_DIR").expect("env")).join("proto");
|
2016-11-21 02:48:17 +00:00
|
|
|
|
2020-07-25 03:43:01 +00:00
|
|
|
let files = &[
|
2021-06-19 20:29:48 +00:00
|
|
|
proto_dir.join("metadata.proto"),
|
|
|
|
// TODO: remove these legacy protobufs when we are on the new API completely
|
2020-07-25 03:43:01 +00:00
|
|
|
proto_dir.join("authentication.proto"),
|
|
|
|
proto_dir.join("keyexchange.proto"),
|
|
|
|
proto_dir.join("mercury.proto"),
|
|
|
|
proto_dir.join("playlist4changes.proto"),
|
|
|
|
proto_dir.join("playlist4content.proto"),
|
|
|
|
proto_dir.join("playlist4issues.proto"),
|
|
|
|
proto_dir.join("playlist4meta.proto"),
|
|
|
|
proto_dir.join("playlist4ops.proto"),
|
|
|
|
proto_dir.join("pubsub.proto"),
|
|
|
|
proto_dir.join("spirc.proto"),
|
|
|
|
];
|
2019-12-16 11:47:52 +00:00
|
|
|
|
2020-07-25 03:43:01 +00:00
|
|
|
let slices = files.iter().map(Deref::deref).collect::<Vec<_>>();
|
2019-09-08 12:07:45 +00:00
|
|
|
|
2020-07-25 03:43:01 +00:00
|
|
|
let out_dir = out_dir();
|
|
|
|
fs::create_dir(&out_dir).expect("create_dir");
|
|
|
|
|
|
|
|
protobuf_codegen_pure::Codegen::new()
|
|
|
|
.out_dir(&out_dir)
|
|
|
|
.inputs(&slices)
|
|
|
|
.include(&proto_dir)
|
|
|
|
.run()
|
|
|
|
.expect("Codegen failed.");
|
|
|
|
}
|
2020-07-24 02:11:14 +00:00
|
|
|
|
2020-07-25 03:43:01 +00:00
|
|
|
fn generate_mod_rs() {
|
|
|
|
let out_dir = out_dir();
|
2016-11-21 02:48:17 +00:00
|
|
|
|
2020-07-25 03:43:01 +00:00
|
|
|
let mods = glob::glob(&out_dir.join("*.rs").to_string_lossy())
|
|
|
|
.expect("glob")
|
|
|
|
.filter_map(|p| {
|
|
|
|
p.ok()
|
|
|
|
.map(|p| format!("pub mod {};", p.file_stem().unwrap().to_string_lossy()))
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join("\n");
|
2019-09-08 12:07:45 +00:00
|
|
|
|
2020-07-25 03:43:01 +00:00
|
|
|
let mod_rs = out_dir.join("mod.rs");
|
|
|
|
fs::write(&mod_rs, format!("// @generated\n{}\n", mods)).expect("write");
|
|
|
|
|
|
|
|
println!("cargo:rustc-env=PROTO_MOD_RS={}", mod_rs.to_string_lossy());
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
cleanup();
|
|
|
|
compile();
|
|
|
|
generate_mod_rs();
|
2016-11-21 02:48:17 +00:00
|
|
|
}
|