Skip to content

Commit

Permalink
rpc: use protox to build proto files
Browse files Browse the repository at this point in the history
Use protox to build proto files so that the fds' can have a
deterministic serialized format for comparison in CI.
  • Loading branch information
bmwill committed Dec 16, 2024
1 parent e5b12a4 commit e6414a9
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 33 deletions.
108 changes: 78 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/sui-rpc-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tonic-reflection.workspace = true

[dev-dependencies]
diffy = "0.3"
prost-build = "0.13.3"
protox = "0.7"
tonic-build = "0.12.3"
sui-sdk-types = { workspace = true, features = ["proptest"] }
test-strategy = "0.4.0"
Expand Down
Binary file modified crates/sui-rpc-api/src/proto/generated/sui.node.v2.fds.bin
Binary file not shown.
25 changes: 23 additions & 2 deletions crates/sui-rpc-api/tests/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use protox::prost::Message as _;
use std::fs;
use std::path::PathBuf;

Expand Down Expand Up @@ -36,17 +37,37 @@ fn bootstrap() {
let out_dir = root_dir.join("src").join("proto").join("generated");
let file_descriptor_set_path = out_dir.join("sui.node.v2.fds.bin");

let fds = protox::Compiler::new(&[proto_dir.clone()])
.unwrap()
.include_source_info(true)
.include_imports(true)
.open_files(&proto_files)
.unwrap()
.file_descriptor_set();

if let Err(error) = tonic_build::configure()
.build_client(true)
.build_server(true)
.bytes(["."])
.out_dir(&out_dir)
.file_descriptor_set_path(file_descriptor_set_path)
.compile_protos(&proto_files[..], &[proto_dir])
.compile_fds(fds)
{
panic!("failed to compile `sui` protos: {}", error);
}

// Generate fds to expose via reflection
let mut fds = protox::Compiler::new(&[proto_dir])
.unwrap()
.include_source_info(false)
.include_imports(true)
.open_files(&proto_files)
.unwrap()
.file_descriptor_set();

// Sort them by their file name in order to have a stable serialized format
fds.file.sort_by(|a, b| a.name.cmp(&b.name));
std::fs::write(file_descriptor_set_path, fds.encode_to_vec()).unwrap();

let status = std::process::Command::new("git")
.arg("diff")
.arg("--exit-code")
Expand Down

0 comments on commit e6414a9

Please sign in to comment.