Skip to content

Commit

Permalink
feat: vendor pbjson-types descriptor set (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Oct 20, 2022
1 parent 464915c commit 1f1fa9f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions pbjson-types/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@ type Error = Box<dyn std::error::Error>;
type Result<T, E = Error> = std::result::Result<T, E>;

fn main() -> Result<()> {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("protos");
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let protos = root.join("protos");
let descriptor_path = root.join("descriptors.bin");
println!("cargo:rerun-if-changed={}", descriptor_path.display());

let proto_files = vec![root.join("google/protobuf/types.proto")];

// Tell cargo to recompile if any of these proto files are changed
for proto_file in &proto_files {
println!("cargo:rerun-if-changed={}", proto_file.display());
}

let descriptor_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("proto_descriptor.bin");
prost_build::Config::new()
let mut config = prost_build::Config::new();
config
.file_descriptor_set_path(&descriptor_path)
.compile_well_known_types()
.disable_comments(&["."])
.bytes(&[".google"])
.compile_protos(&proto_files, &[root])?;
.bytes(&[".google"]);

// Don't regenerate descriptors if already exists, this avoids needing protoc
// in order to compile this crate
if descriptor_path.exists() {
config.skip_protoc_run();
}

let proto_files = vec![protos.join("google/protobuf/types.proto")];
config.compile_protos(&proto_files, &[protos])?;

let descriptor_set = std::fs::read(descriptor_path)?;
pbjson_build::Builder::new()
Expand Down
Binary file added pbjson-types/descriptors.bin
Binary file not shown.

0 comments on commit 1f1fa9f

Please sign in to comment.