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 26, 2022
1 parent 5fa7d4d commit 901fe13
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ jobs:
- checkout
- rust_components
- cache_restore
- run:
name: Regenerate descriptor set
command: rm pbjson-types/descriptors.bin
- run:
name: Cargo test
command: cargo test --workspace
Expand All @@ -140,6 +143,9 @@ jobs:
- run:
name: Cargo test (preserve proto field names)
command: cargo test --workspace --features preserve-proto-field-names
- run:
name: Verify working directory clean
command: git diff --exit-code
- cache_save

workflows:
Expand Down
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 901fe13

Please sign in to comment.