Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Jan 23, 2025
2 parents 5e9b75b + 5aa52b2 commit 3867404
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 22 deletions.
2 changes: 1 addition & 1 deletion 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 bin/proving-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "miden-proving-service"
version = "0.8.0"
description = "Miden rollup proving service"
readme = "README.md"
keywords = ["miden", "proving-service"]
keywords = ["miden", "proving", "service"]
license.workspace = true
authors.workspace = true
homepage.workspace = true
Expand Down
29 changes: 21 additions & 8 deletions bin/proving-service/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use protox::prost::Message;
/// otherwise the docs will fail to build there. Note that writing to `OUT_DIR` is fine.
const BUILD_GENERATED_FILES_IN_SRC: bool = option_env!("BUILD_GENERATED_FILES_IN_SRC").is_some();

const REPO_PROTO_DIR: &str = "../../proto";
const CRATE_PROTO_DIR: &str = "proto";

/// Generates Rust protobuf bindings from .proto files.
///
/// Because the proto generated files will be written to ./src/generated, this should be a no-op
Expand All @@ -23,27 +26,37 @@ fn main() -> miette::Result<()> {
return Ok(());
}

copy_proto_files()?;
compile_tonic_server_proto()
}

// HELPER FUNCTIONS
// ================================================================================================

/// Copies all api.proto file from the root proto directory to the proto directory of this crate.
fn copy_proto_files() -> miette::Result<()> {
let src_file = format!("{REPO_PROTO_DIR}/api.proto");
let dest_file = format!("{CRATE_PROTO_DIR}/api.proto");

fs::remove_dir_all(CRATE_PROTO_DIR).into_diagnostic()?;
fs::create_dir_all(CRATE_PROTO_DIR).into_diagnostic()?;
fs::copy(src_file, dest_file).into_diagnostic()?;

Ok(())
}

fn compile_tonic_server_proto() -> miette::Result<()> {
let crate_root =
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR should be set"));
let dst_dir = crate_root.join("src").join("generated");

// Construct the path to the proto/api.proto file
let proto_dir = crate_root
.parent() // Go up to the workspace root
.expect("bin directory should exist")
.parent() // Go up to the workspace root
.expect("Workspace root should exist")
.join("proto");

// Remove `api.rs` if it exists.
fs::remove_file(dst_dir.join("api.rs")).into_diagnostic().ok();

let out_dir = env::var("OUT_DIR").into_diagnostic()?;
let file_descriptor_path = PathBuf::from(out_dir).join("file_descriptor_set.bin");

let proto_dir: PathBuf = CRATE_PROTO_DIR.into();
let protos = &[proto_dir.join("api.proto")];
let includes = &[proto_dir];

Expand Down
15 changes: 15 additions & 0 deletions bin/proving-service/proto/api.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Specification of the user facing gRPC API.
syntax = "proto3";
package api;

service Api {
rpc ProveTransaction(ProveTransactionRequest) returns (ProveTransactionResponse) {}
}

message ProveTransactionRequest {
bytes transaction_witness = 1;
}

message ProveTransactionResponse {
bytes proven_transaction = 1;
}
6 changes: 3 additions & 3 deletions crates/miden-proving-service-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "miden-proving-service-client"
version = "0.1.0"
description = "client library that provides a client for the remote provers"
version = "0.8.0"
description = "Client library for the Miden rollup proving service"
readme = "README.md"
keywords = ["miden", "miden-proving-service-client"]
keywords = ["miden", "proving", "service"]
license.workspace = true
authors.workspace = true
repository.workspace = true
Expand Down
28 changes: 20 additions & 8 deletions crates/miden-proving-service-client/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use protox::prost::Message;
/// otherwise the docs will fail to build there. Note that writing to `OUT_DIR` is fine.
const BUILD_GENERATED_FILES_IN_SRC: bool = option_env!("BUILD_GENERATED_FILES_IN_SRC").is_some();

const REPO_PROTO_DIR: &str = "../../proto";
const CRATE_PROTO_DIR: &str = "proto";

/// Generates Rust protobuf bindings from .proto files.
///
/// Because the proto generated files will be written to ./src/generated, this should be a no-op
Expand All @@ -24,28 +27,37 @@ fn main() -> miette::Result<()> {
return Ok(());
}

copy_proto_files()?;
compile_tonic_client_proto()
}

// HELPER FUNCTIONS
// ================================================================================================

/// Copies all api.proto file from the root proto directory to the proto directory of this crate.
fn copy_proto_files() -> miette::Result<()> {
let src_file = format!("{REPO_PROTO_DIR}/api.proto");
let dest_file = format!("{CRATE_PROTO_DIR}/api.proto");

fs::remove_dir_all(CRATE_PROTO_DIR).into_diagnostic()?;
fs::create_dir_all(CRATE_PROTO_DIR).into_diagnostic()?;
fs::copy(src_file, dest_file).into_diagnostic()?;

Ok(())
}

fn compile_tonic_client_proto() -> miette::Result<()> {
let crate_root =
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR should be set"));
let dst_dir = crate_root.join("src").join("generated");

// Compute the directory of the `proto` definitions
let proto_dir = crate_root
.parent()
.expect("crates directory should exist")
.parent()
.expect("workspace root should exist")
.join("proto");

// Remove `api.rs` if it exists.
fs::remove_file(dst_dir.join("api.rs")).into_diagnostic().ok();

let out_dir = env::var("OUT_DIR").into_diagnostic()?;
let file_descriptor_path = PathBuf::from(out_dir).join("file_descriptor_set.bin");

let proto_dir: PathBuf = CRATE_PROTO_DIR.into();
let protos = &[proto_dir.join("api.proto")];
let includes = &[proto_dir];

Expand Down
15 changes: 15 additions & 0 deletions crates/miden-proving-service-client/proto/api.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Specification of the user facing gRPC API.
syntax = "proto3";
package api;

service Api {
rpc ProveTransaction(ProveTransactionRequest) returns (ProveTransactionResponse) {}
}

message ProveTransactionRequest {
bytes transaction_witness = 1;
}

message ProveTransactionResponse {
bytes proven_transaction = 1;
}
2 changes: 1 addition & 1 deletion crates/miden-proving-service-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod prover;
pub use prover::RemoteTransactionProver;

/// Protobuf definition for the Miden proving service
pub const SERVICE_PROTO: &str = include_str!("../../../proto/api.proto");
pub const SERVICE_PROTO: &str = include_str!("../proto/api.proto");

/// ERRORS
/// ===============================================================================================
Expand Down

0 comments on commit 3867404

Please sign in to comment.