Don't require DESCRIPTORS_BIN in an external workspace

Consumers may not require it
This commit is contained in:
Damien Elmes 2023-06-15 22:32:16 +10:00
parent ffac5e0d14
commit 02a1c891a6
2 changed files with 11 additions and 10 deletions

View file

@ -9,13 +9,12 @@ pub mod utils;
use std::env;
use std::path::PathBuf;
use anyhow::Context;
use anyhow::Result;
fn main() -> Result<()> {
let descriptors_path = PathBuf::from(env::var("DESCRIPTORS_BIN").context("DESCRIPTORS_BIN")?);
let descriptors_path = env::var("DESCRIPTORS_BIN").ok().map(PathBuf::from);
let pool = rust::write_backend_proto_rs(&descriptors_path)?;
let pool = rust::write_backend_proto_rs(descriptors_path)?;
python::write_python_interface(&pool)?;
ts::write_ts_interface(&pool)?;

View file

@ -14,16 +14,11 @@ use anyhow::Result;
use prost_build::ServiceGenerator;
use prost_reflect::DescriptorPool;
pub fn write_backend_proto_rs(descriptors_path: &Path) -> Result<DescriptorPool> {
pub fn write_backend_proto_rs(descriptors_path: Option<PathBuf>) -> Result<DescriptorPool> {
set_protoc_path();
let proto_dir = PathBuf::from("../../proto");
let paths = gather_proto_paths(&proto_dir)?;
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
create_dir_all(
descriptors_path
.parent()
.context("missing parent of descriptor")?,
)?;
let tmp_descriptors = out_dir.join("descriptors.tmp");
prost_build::Config::new()
.out_dir(&out_dir)
@ -55,7 +50,14 @@ pub fn write_backend_proto_rs(descriptors_path: &Path) -> Result<DescriptorPool>
.context("prost build")?;
let descriptors = read_file(&tmp_descriptors)?;
write_file_if_changed(descriptors_path, &descriptors)?;
if let Some(descriptors_path) = descriptors_path {
create_dir_all(
descriptors_path
.parent()
.context("missing parent of descriptor")?,
)?;
write_file_if_changed(descriptors_path, &descriptors)?;
}
write_service_index(&out_dir, descriptors)
}