Skip to content

Commit 218848c

Browse files
authored
fix/proto: move generatex code to OUT_DIR (#1703)
1 parent 3b9298c commit 218848c

File tree

34 files changed

+131
-9970
lines changed

34 files changed

+131
-9970
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
name: "Install protobuf compiler"
3+
description: "Install compiler for protobuf compilation"
4+
5+
runs:
6+
using: "composite"
7+
steps:
8+
- name: Install protobuf compiler
9+
shell: bash
10+
run: |
11+
set -eux
12+
sudo apt-get update
13+
sudo apt-get install -y protobuf-compiler

.github/workflows/ci.yml

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ on:
2424

2525
env:
2626
# Shared prefix key for the rust cache.
27-
#
27+
#
2828
# This provides a convenient way to evict old or corrupted cache.
2929
RUST_CACHE_KEY: rust-cache-2026.02.02
3030
# Reduce cache usage by removing debug information.
@@ -47,8 +47,8 @@ jobs:
4747
- uses: actions/checkout@v6
4848
- name: Cleanup large tools for build space
4949
uses: ./.github/actions/cleanup-runner
50-
- name: Install RocksDB
51-
uses: ./.github/actions/install-rocksdb
50+
- uses: ./.github/actions/install-rocksdb
51+
- uses: ./.github/actions/install-protobuf-compiler
5252
- name: Rustup
5353
run: rustup update --no-self-update
5454
- uses: Swatinem/rust-cache@v2
@@ -95,7 +95,7 @@ jobs:
9595
fi
9696
done
9797
echo "Static linkage check passed for all of ${bin_targets[@]}"
98-
98+
9999
clippy:
100100
name: lint - clippy
101101
runs-on: ubuntu-24.04
@@ -152,29 +152,6 @@ jobs:
152152
- name: Build docs
153153
run: cargo doc --no-deps --workspace --all-features --locked
154154

155-
# Ensures our checked-in protobuf generated code is aligned to the protobuf schema.
156-
#
157-
# We do this by rebuilding the generated code and ensuring there is no diff.
158-
proto:
159-
name: gRPC codegen
160-
needs: [build]
161-
runs-on: ubuntu-24.04
162-
steps:
163-
- uses: actions/checkout@v6
164-
- name: Rustup
165-
run: rustup update --no-self-update
166-
- name: Install protobuf
167-
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
168-
- uses: Swatinem/rust-cache@v2
169-
with:
170-
shared-key: ${{ github.workflow }}-build
171-
prefix-key: ${{ env.RUST_CACHE_KEY }}
172-
save-if: false
173-
- name: Rebuild protos
174-
run: BUILD_PROTO=1 cargo check --all-features --all-targets --locked --workspace
175-
- name: Diff check
176-
run: git diff --exit-code
177-
178155
# Ensure the stress-test still functions by running some cheap benchmarks.
179156
stress-test:
180157
name: stress test
@@ -204,7 +181,7 @@ jobs:
204181
cargo run --bin miden-node-stress-test seed-store \
205182
--data-directory ${{ env.DATA_DIR }} \
206183
--num-accounts 500 --public-accounts-percentage 50
207-
# TODO re-introduce
184+
# TODO re-introduce
208185
# - name: Benchmark state sync
209186
# run: |
210187
# cargo run --bin miden-node-stress-test benchmark-store \

.github/workflows/nightly.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
ref: "next"
2424
- name: Cleanup large tools for build space
2525
uses: ./.github/actions/cleanup-runner
26-
- name: Install RocksDB
27-
uses: ./.github/actions/install-rocksdb
26+
- uses: ./.github/actions/install-rocksdb
27+
- uses: ./.github/actions/install-protobuf-compiler
2828
- name: Rustup
2929
run: rustup install beta && rustup default beta
3030
- uses: taiki-e/install-action@v2
@@ -45,8 +45,8 @@ jobs:
4545
ref: "next"
4646
- name: Cleanup large tools for build space
4747
uses: ./.github/actions/cleanup-runner
48-
- name: Install RocksDB
49-
uses: ./.github/actions/install-rocksdb
48+
- uses: ./.github/actions/install-rocksdb
49+
- uses: ./.github/actions/install-protobuf-compiler
5050
- name: Install rust
5151
run: rustup update --no-self-update
5252
- name: Install cargo-hack

.github/workflows/publish-debian-all.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ jobs:
3131
uses: actions/checkout@main
3232
with:
3333
fetch-depth: 0
34-
- name: Install RocksDB
35-
uses: ./.github/actions/install-rocksdb
34+
- uses: ./.github/actions/install-rocksdb
35+
- uses: ./.github/actions/install-protobuf-compiler
3636
- name: Build and Publish Node
3737
uses: ./.github/actions/debian
3838
with:

.github/workflows/publish-debian.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ jobs:
6060
with:
6161
fetch-depth: 0
6262

63-
- name: Install RocksDB
64-
uses: ./.github/actions/install-rocksdb
63+
- uses: ./.github/actions/install-rocksdb
64+
- uses: ./.github/actions/install-protobuf-compiler
6565

6666
- name: Build and Publish Packages
6767
uses: ./.github/actions/debian

.github/workflows/publish-main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
with:
1919
fetch-depth: 0
2020
ref: main
21-
- name: Install RocksDB
22-
uses: ./.github/actions/install-rocksdb
21+
- uses: ./.github/actions/install-rocksdb
22+
- uses: ./.github/actions/install-protobuf-compiler
2323
# Ensure the release tag refers to the latest commit on main.
2424
# Compare the commit SHA that triggered the workflow with the HEAD of the branch we just
2525
# checked out (main).

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ help:
77
# -- variables ------------------------------------------------------------------------------------
88

99
WARNINGS=RUSTDOCFLAGS="-D warnings"
10-
BUILD_PROTO=BUILD_PROTO=1
1110
CONTAINER_RUNTIME ?= docker
1211
STRESS_TEST_DATA_DIR ?= stress-test-store-$(shell date +%Y%m%d-%H%M%S)
1312

@@ -86,7 +85,7 @@ test: ## Runs all tests
8685

8786
.PHONY: check
8887
check: ## Check all targets and features for errors without code generation
89-
${BUILD_PROTO} cargo check --all-features --all-targets --locked --workspace
88+
cargo check --all-features --all-targets --locked --workspace
9089

9190
.PHONY: check-features
9291
check-features: ## Checks all feature combinations compile without warnings using cargo-hack
@@ -96,22 +95,22 @@ check-features: ## Checks all feature combinations compile without warnings usin
9695

9796
.PHONY: build
9897
build: ## Builds all crates and re-builds protobuf bindings for proto crates
99-
${BUILD_PROTO} cargo build --locked --workspace
100-
${BUILD_PROTO} cargo build --locked -p miden-remote-prover-client --target wasm32-unknown-unknown --no-default-features --features batch-prover,block-prover,tx-prover # no-std compatible build
98+
cargo build --locked --workspace
99+
cargo build --locked -p miden-remote-prover-client --target wasm32-unknown-unknown --no-default-features --features batch-prover,block-prover,tx-prover # no-std compatible build
101100

102101
# --- installing ----------------------------------------------------------------------------------
103102

104103
.PHONY: install-node
105104
install-node: ## Installs node
106-
${BUILD_PROTO} cargo install --path bin/node --locked
105+
cargo install --path bin/node --locked
107106

108107
.PHONY: install-remote-prover
109108
install-remote-prover: ## Install remote prover's CLI
110-
$(BUILD_PROTO) cargo install --path bin/remote-prover --bin miden-remote-prover --locked
109+
cargo install --path bin/remote-prover --bin miden-remote-prover --locked
111110

112111
.PHONY: stress-test-smoke
113112
stress-test: ## Runs stress-test benchmarks
114-
${BUILD_PROTO} cargo build --release --locked -p miden-node-stress-test
113+
cargo build --release --locked -p miden-node-stress-test
115114
@mkdir -p $(STRESS_TEST_DATA_DIR)
116115
./target/release/miden-node-stress-test seed-store --data-directory $(STRESS_TEST_DATA_DIR) --num-accounts 500 --public-accounts-percentage 50
117116
./target/release/miden-node-stress-test benchmark-store --data-directory $(STRESS_TEST_DATA_DIR) --iterations 10 --concurrency 1 sync-state

bin/remote-prover/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,22 @@ tower-http = { features = ["trace"], workspace = true }
4040
tracing = { workspace = true }
4141

4242
[dev-dependencies]
43+
assert_matches = { workspace = true }
4344
miden-protocol = { features = ["testing"], workspace = true }
4445
miden-standards = { features = ["testing"], workspace = true }
4546
miden-testing = { workspace = true }
4647
miden-tx = { features = ["testing"], workspace = true }
4748

4849
[build-dependencies]
50+
fs-err = { workspace = true }
4951
miden-node-proto-build = { features = ["internal"], workspace = true }
5052
miden-node-rocksdb-cxx-linkage-fix = { workspace = true }
5153
miette = { features = ["fancy"], version = "7.5" }
5254
tonic-prost-build = { workspace = true }
55+
56+
[package.metadata.cargo-machete]
57+
ignored = [
58+
"http",
59+
"prost",
60+
"tonic-prost", # used in generated OUT_DIR code
61+
]

bin/remote-prover/build.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1+
use std::path::{Path, PathBuf};
2+
3+
use fs_err as fs;
14
use miden_node_proto_build::remote_prover_api_descriptor;
2-
use miette::IntoDiagnostic;
5+
use miette::{IntoDiagnostic, WrapErr};
36
use tonic_prost_build::FileDescriptorSet;
47

5-
/// Defines whether the build script should generate files in `/src`.
6-
///
7-
/// The docs.rs build pipeline has a read-only filesystem, so we have to avoid writing to `src`,
8-
/// otherwise the docs will fail to build there. Note that writing to `OUT_DIR` is fine.
9-
const BUILD_GENERATED_FILES_IN_SRC: bool = option_env!("BUILD_PROTO").is_some();
10-
11-
const GENERATED_OUT_DIR: &str = "src/generated";
12-
138
/// Generates Rust protobuf bindings.
149
fn main() -> miette::Result<()> {
1510
miden_node_rocksdb_cxx_linkage_fix::configure();
16-
println!("cargo:rerun-if-env-changed=BUILD_PROTO");
17-
if !BUILD_GENERATED_FILES_IN_SRC {
18-
return Ok(());
19-
}
11+
12+
let dst_dir =
13+
PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR should be set")).join("generated");
14+
15+
// Remove all existing files.
16+
let _ = fs::remove_dir_all(&dst_dir);
17+
fs::create_dir(&dst_dir)
18+
.into_diagnostic()
19+
.wrap_err("creating destination folder")?;
2020

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

2424
// Build tonic code
25-
build_tonic_from_descriptor(remote_prover_descriptor)?;
25+
build_tonic_from_descriptor(remote_prover_descriptor, &dst_dir)?;
2626

2727
Ok(())
2828
}
@@ -31,9 +31,12 @@ fn main() -> miette::Result<()> {
3131
// ================================================================================================
3232

3333
/// Builds tonic code from a `FileDescriptorSet`
34-
fn build_tonic_from_descriptor(descriptor: FileDescriptorSet) -> miette::Result<()> {
34+
fn build_tonic_from_descriptor(
35+
descriptor: FileDescriptorSet,
36+
dst_dir: &Path,
37+
) -> miette::Result<()> {
3538
tonic_prost_build::configure()
36-
.out_dir(GENERATED_OUT_DIR)
39+
.out_dir(dst_dir)
3740
.build_server(true)
3841
.build_transport(true)
3942
.compile_fds_with_config(descriptor, tonic_prost_build::Config::new())

0 commit comments

Comments
 (0)