Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions bin/remote-prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ miden-testing = { workspace = true }
miden-tx = { features = ["testing"], workspace = true }

[build-dependencies]
fs-err = { workspace = true }
miden-node-proto-build = { features = ["internal"], workspace = true }
miden-node-rocksdb-cxx-linkage-fix = { workspace = true }
miette = { features = ["fancy"], version = "7.5" }
tonic-prost-build = { workspace = true }

[package.metadata.cargo-machete]
ignored = [
"http",
"prost",
"tonic-prost", # used in generated OUT_DIR code
]
35 changes: 19 additions & 16 deletions bin/remote-prover/build.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
use std::path::{Path, PathBuf};

use fs_err as fs;
use miden_node_proto_build::remote_prover_api_descriptor;
use miette::IntoDiagnostic;
use miette::{IntoDiagnostic, WrapErr};
use tonic_prost_build::FileDescriptorSet;

/// Defines whether the build script should generate files in `/src`.
///
/// The docs.rs build pipeline has a read-only filesystem, so we have to avoid writing to `src`,
/// 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_PROTO").is_some();

const GENERATED_OUT_DIR: &str = "src/generated";

/// Generates Rust protobuf bindings.
fn main() -> miette::Result<()> {
miden_node_rocksdb_cxx_linkage_fix::configure();
println!("cargo:rerun-if-env-changed=BUILD_PROTO");
if !BUILD_GENERATED_FILES_IN_SRC {
return Ok(());
}

let dst_dir =
PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR should be set")).join("generated");

// Remove all existing files.
let _ = fs::remove_dir_all(&dst_dir);
fs::create_dir(&dst_dir)
.into_diagnostic()
.wrap_err("creating destination folder")?;

// Get the file descriptor set
let remote_prover_descriptor = remote_prover_api_descriptor();

// Build tonic code
build_tonic_from_descriptor(remote_prover_descriptor)?;
build_tonic_from_descriptor(remote_prover_descriptor, &dst_dir)?;

Ok(())
}
Expand All @@ -31,9 +31,12 @@ fn main() -> miette::Result<()> {
// ================================================================================================

/// Builds tonic code from a `FileDescriptorSet`
fn build_tonic_from_descriptor(descriptor: FileDescriptorSet) -> miette::Result<()> {
fn build_tonic_from_descriptor(
descriptor: FileDescriptorSet,
dst_dir: &Path,
) -> miette::Result<()> {
tonic_prost_build::configure()
.out_dir(GENERATED_OUT_DIR)
.out_dir(dst_dir)
.build_server(true)
.build_transport(true)
.compile_fds_with_config(descriptor, tonic_prost_build::Config::new())
Expand Down
4 changes: 3 additions & 1 deletion bin/remote-prover/src/generated/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
#![allow(clippy::allow_attributes, reason = "generated by build.rs and tonic")]

#[rustfmt::skip]
mod remote_prover;
pub mod remote_prover {
include!(concat!(env!("OUT_DIR"), "/generated/remote_prover.rs"));
}
pub use remote_prover::*;
Loading
Loading