#[cfg(feature = "with-mvt")]
use std::{
env,
fs::OpenOptions,
io::{Read, Write},
path::Path,
};
#[cfg(feature = "with-mvt")]
fn compile_protos() -> Result<(), Box<dyn std::error::Error>> {
env::set_var("OUT_DIR", "src/mvt");
if !Path::new("src/mvt/vector_tile.rs").exists() {
prost_build::compile_protos(&["src/mvt/vector_tile.proto"], &["src/mvt/"])?;
let mut file = OpenOptions::new()
.read(true)
.open("src/mvt/vector_tile.rs")?;
let mut buffer = String::new();
file.read_to_string(&mut buffer)?;
let mut file = OpenOptions::new()
.write(true)
.truncate(true)
.open("src/mvt/vector_tile.rs")?;
file.write_all("// This file was automatically generated through the build.rs script, and should not be edited.\n// Remove this file to force a rebuild.\n\n".as_bytes())?;
file.write_all(buffer.as_bytes())?;
}
Ok(())
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "with-mvt")]
compile_protos()?;
Ok(())
}