forked from cosmos/ibc-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ProtoJSON-compatible
Serialize
and Deserialize
instance…
…s on all Protobuf definitions via `pbjson` (cosmos#146) * Derive `Serialize` and `Deserialize` on all Protobuf definitions via `pbjson` * Run Clippy on all possible features combinations using `cargo-hack` * Feature-gate `pbjson` dependency * Add roundtrip serialization test
- Loading branch information
Showing
9 changed files
with
2,046 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
target | ||
.idea | ||
Cargo.lock | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,44 @@ | ||
extern crate prost_build; | ||
|
||
use std::env; | ||
use std::io::Result; | ||
use std::path::PathBuf; | ||
use std::vec::Vec; | ||
|
||
fn main() { | ||
fn main() -> Result<()> { | ||
let args: Vec<_> = env::args().collect(); | ||
let mut root = "../.."; | ||
if args.len() > 1 { | ||
root = &args[1]; | ||
} | ||
let root = if args.len() > 1 { | ||
&args[1] | ||
} else { | ||
env!("CARGO_MANIFEST_DIR") | ||
}; | ||
|
||
println!("Root: {root}"); | ||
|
||
let out_dir: &str = &format!("{}{}", root, "/rust/src"); | ||
let input: &str = &format!("{}{}", root, "/proto/cosmos/ics23/v1/proofs.proto"); | ||
let root = PathBuf::from(root).join("..").join("..").canonicalize()?; | ||
let input = root.join("proto/cosmos/ics23/v1/proofs.proto"); | ||
let out_dir = root.join("rust/src"); | ||
let descriptor_path = out_dir.join("proto_descriptor.bin"); | ||
|
||
println!("Input: {}", input.display()); | ||
println!("Output: {}", out_dir.display()); | ||
println!("Descriptor: {}", descriptor_path.display()); | ||
|
||
prost_build::Config::new() | ||
.out_dir(&out_dir) | ||
.format(true) | ||
.compile_protos(&[input], &[root]) | ||
.unwrap(); | ||
// Needed for pbjson_build to generate the serde implementations | ||
.file_descriptor_set_path(&descriptor_path) | ||
.compile_well_known_types() | ||
// As recommended in pbjson_types docs | ||
.extern_path(".google.protobuf", "::pbjson_types") | ||
.compile_protos(&[input], &[root])?; | ||
|
||
// Finally, build pbjson Serialize, Deserialize impls: | ||
let descriptor_set = std::fs::read(descriptor_path)?; | ||
|
||
pbjson_build::Builder::new() | ||
.register_descriptors(&descriptor_set)? | ||
.out_dir(&out_dir) | ||
.build(&[".cosmos.ics23.v1"])?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.