django-language-server/crates/djls-ipc/build.rs
Josh Thomas 0a6e975ca5
Get rid of all transport types and settle on Protobuf (#25)
* Get rid of all transport types and settle on Protobuf

hope i don't regret this

* Update Cargo.toml

* Update agent.py
2024-12-12 16:53:49 -06:00

38 lines
1 KiB
Rust

use std::fs;
use std::path::{Path, PathBuf};
struct Version(&'static str);
impl Version {
fn collect_protos(&self, proto_root: &Path) -> Vec<PathBuf> {
fs::read_dir(proto_root.join(self.0))
.unwrap()
.filter_map(Result::ok)
.filter(|entry| entry.path().extension().and_then(|s| s.to_str()) == Some("proto"))
.map(|entry| entry.path())
.collect()
}
}
const VERSIONS: &[Version] = &[Version("v1")];
fn main() {
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let workspace_root = manifest_dir.parent().unwrap().parent().unwrap();
let proto_dir = workspace_root.join("proto");
let mut protos = Vec::new();
for version in VERSIONS {
protos.extend(version.collect_protos(&proto_dir));
}
prost_build::Config::new()
.compile_protos(
&protos
.iter()
.map(|p| p.to_str().unwrap())
.collect::<Vec<_>>(),
&[proto_dir],
)
.unwrap();
}