Skip to content

Commit

Permalink
Use prost instead of rust-protobuf
Browse files Browse the repository at this point in the history
Main differences:

- use `::default` instead of `::new` to create instances
- use native field accessors
- use native Option and Vec types for optional and repeated fields
- dispatcher struct has a more qualified name
- gRPC generator code is encapsulated in a prost ServiceGenerator
- use `quote!` macros instead of string concatenation in the generator

Fixes project-oak#668
  • Loading branch information
tiziano88 committed Apr 9, 2020
1 parent 9bfc2a4 commit 24ee189
Show file tree
Hide file tree
Showing 106 changed files with 630 additions and 14,662 deletions.
113 changes: 20 additions & 93 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,3 @@ split_grpc_proxy = { path = "experimental/split_grpc/proxy" }
split_grpc_server = { path = "experimental/split_grpc/server" }
# Third party.
expect = { path = "third_party/expect" }
grpc-compiler = { path = "third_party/grpc-rust/grpc-compiler" }
protoc-rust-grpc = { path = "third_party/grpc-rust/protoc-rust-grpc" }
20 changes: 6 additions & 14 deletions docs/programming-oak.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ with the automatically generated `Dispatcher`, as described in the next section.
```Rust
oak::entrypoint!(oak_main => {
oak::logger::init_default();
Dispatcher::new(Node)
FormatServiceDispatcher::new(Node)
}
```
<!-- prettier-ignore-end -->
Expand Down Expand Up @@ -123,14 +123,10 @@ generated file appearing in `src/proto/<service>_grpc.rs`.
[embedmd]:# (../examples/hello_world/module/rust/build.rs Rust /fn main/ /^}/)
```Rust
fn main() {
oak_utils::run_protoc_rust_grpc(protoc_rust_grpc::Args {
out_dir: "src/proto",
input: &["../../proto/hello_world.proto"],
includes: &["../../proto", "../../../../third_party"],
rust_protobuf: true, // also generate protobuf messages, not just services
..Default::default()
})
.expect("protoc-rust-grpc");
oak_utils::compile_protos(
&["../../proto/hello_world.proto"],
&["../../proto", "../../../../third_party"],
);
}
```
<!-- prettier-ignore-end -->
Expand All @@ -146,14 +142,11 @@ methods in the gRPC service, taking the relevant (auto-generated) request and
response types. The Oak Node implements the gRPC service by implementing this
trait.

<!-- prettier-ignore-start -->
[embedmd]:# (../examples/rustfmt/module/rust/src/proto/rustfmt_grpc.rs Rust /pub trait FormatService/ /^}/)
```Rust
pub trait FormatService {
fn format(&mut self, req: super::rustfmt::FormatRequest) -> grpc::Result<super::rustfmt::FormatResponse>;
}
```
<!-- prettier-ignore-end -->

The second part of the autogenerated code includes a `Dispatcher` struct which
maps a request (as a method name and encoded request) to an invocation of the
Expand Down Expand Up @@ -444,7 +437,6 @@ fn test_say_hello() {
let req = HelloRequest {
greeting: "world".into(),
..Default::default()
};
let result: grpc::Result<HelloResponse> = oak_tests::grpc_request(
&runtime,
Expand Down Expand Up @@ -512,7 +504,7 @@ pub extern "C" fn frontend_oak_main(in_handle: u64) {
let _ = std::panic::catch_unwind(|| {
oak::set_panic_hook();
let node = FrontendNode::new();
let dispatcher = Dispatcher::new(node);
let dispatcher = OakAbiTestServiceDispatcher::new(node);
oak::run_event_loop(dispatcher, in_handle);
});
}
Expand Down
3 changes: 1 addition & 2 deletions examples/abitest/module_0/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ hex = "*"
log = "*"
oak = "=0.1.0"
oak_abi = "=0.1.0"
protobuf = "*"
prost = "*"
rand_core = "*"
rand = "*"
regex = "*"
Expand All @@ -24,4 +24,3 @@ serde_json = "*"

[build-dependencies]
oak_utils = "*"
protoc-rust-grpc = { path = "../../../../third_party/grpc-rust/protoc-rust-grpc" }
12 changes: 4 additions & 8 deletions examples/abitest/module_0/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
//

fn main() {
oak_utils::run_protoc_rust_grpc(protoc_rust_grpc::Args {
out_dir: "src/proto",
input: &["../../proto/abitest.proto"],
includes: &["../../proto", "../../../../third_party"],
rust_protobuf: true, // also generate protobuf messages, not just services
..Default::default()
})
.expect("protoc-rust-grpc");
oak_utils::compile_protos(
&["../../proto/abitest.proto"],
&["../../proto", "../../../../third_party"],
);
}

0 comments on commit 24ee189

Please sign in to comment.