Skip to content

Commit 1b239fc

Browse files
committed
Changes
1 parent ac8b9e3 commit 1b239fc

File tree

8 files changed

+86
-58
lines changed

8 files changed

+86
-58
lines changed

.github/workflows/build-common.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ jobs:
3030
sudo dnf install -y protobuf-compiler
3131
sudo dnf install -y systemd-devel
3232
33-
- name: Clone protosol
34-
run: make fetch_proto
35-
3633
- name: Check lints and clippy
3734
run: |
3835
cargo fmt --all -- --check

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ winapi = "0.3.8"
518518
x509-parser = "0.14.0"
519519
zeroize = { version = "1.7", default-features = false }
520520
zstd = "0.13.3"
521+
protosol = {git = "https://github.com/firedancer-io/protosol", tag = "v1.0.4"}
521522
solfuzz-agave-macro = { path = "macro" }
522523
once_cell = "1.21.3"
523524
lazy_static = "1.5.0"

Makefile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ CC:=clang
1717

1818
CARGO?=cargo
1919

20-
.PHONY: build clean binaries shared_obj fetch_proto
20+
.PHONY: build clean binaries shared_obj
2121

22-
all: | fetch_proto shared_obj binaries
22+
all: | shared_obj binaries
2323

2424
# Alias for backwards compatibility
25-
build: | fetch_proto shared_obj
25+
build: | shared_obj
2626

27-
conformance: | fetch_proto shared_obj_debug
28-
29-
fetch_proto:
30-
./scripts/fetch_proto.sh
27+
conformance: | shared_obj_debug
3128

3229
shared_obj:
3330
RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) build --target x86_64-unknown-linux-gnu --release --lib

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,19 @@ apt install libudev-dev protobuf-compiler pkg-config
2525

2626
Running with a local copy of Agave (for easily adding print statements):
2727
```sh
28-
pip3 install tomlkit
29-
python3 scripts/generate_cargo.py -p <your_local_agave_path> -o Cargo.toml
28+
./scripts/generate_cargo.py -p <your_local_agave_path> -o Cargo.toml
3029
```
3130

31+
Running with a specific Agave commit:
32+
```sh
33+
./scripts/generate_cargo.py -c <commit_hash> -o Cargo.toml
34+
```
35+
36+
Running with a specific protosol version:
37+
```sh
38+
./scripts/generate_cargo.py -c <commit_hash> -v <version> -o Cargo.toml
39+
# Example: ./scripts/generate_cargo.py -c <commit_hash> -v 1.0.4 -o Cargo.toml
40+
```
3241

3342
Check and test:
3443

@@ -64,7 +73,7 @@ $ nm -D target/x86_64-unknown-linux-gnu/release/libsolfuzz_agave.so | grep '__sa
6473
U __sanitizer_cov_trace_pc_indir
6574
```
6675

67-
**Note:** You may have to periodically run `make build` to ensure that Protobuf definitions stay in sync with [Protosol](https://github.com/firedancer-io/protosol/). Alternatively, you can run `./scripts/fetch_proto.sh` to keep Protosol up to date. Maintainers are expected to bump the `PROTO_VERSION` corresponding to the versioned git tag of the protosol repository when staging new protobuf changes.
76+
**Note:** Protobuf definitions are now managed through the `protosol` Rust crate dependency. The `protosol` crate is automatically included in the generated Cargo.toml with a specific version tag. When protobuf schema changes are needed, maintainers should update the `PROTOSOL_VERSION_TAG` in `scripts/generate_cargo.py` to the appropriate version tag from the [protosol repository](https://github.com/firedancer-io/protosol/).
6877

6978
## Building Targets with Core BPF Programs
7079

build.rs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::io::Result;
1+
use std::{env, fs, path::PathBuf};
22

3-
fn main() -> Result<()> {
3+
fn main() -> Result<(), Box<dyn std::error::Error>> {
44
// Tells rustc to recompile the `load_core_bpf_program!` macro if either
55
// of the required environment variables has changed.
66
println!("cargo:rerun-if-env-changed=CORE_BPF_PROGRAM_ID");
@@ -12,36 +12,40 @@ fn main() -> Result<()> {
1212
println!("cargo:rerun-if-changed=force_rebuild");
1313
}
1414

15-
let proto_base_path = std::path::PathBuf::from("protosol/proto");
16-
17-
let protos = &[
18-
proto_base_path.join("invoke.proto"),
19-
proto_base_path.join("vm.proto"),
20-
proto_base_path.join("txn.proto"),
21-
proto_base_path.join("elf.proto"),
22-
proto_base_path.join("shred.proto"),
23-
proto_base_path.join("pack.proto"),
24-
proto_base_path.join("block.proto"),
25-
proto_base_path.join("type.proto"),
26-
];
27-
28-
protos
29-
.iter()
30-
.for_each(|proto| println!("cargo:rerun-if-changed={}", proto.display()));
31-
32-
for proto in protos {
33-
if !proto.exists() {
34-
return Err(std::io::Error::new(
35-
std::io::ErrorKind::NotFound,
36-
format!(
37-
"Proto file does not exist: {}. Run ./scripts/fetch_proto.sh",
38-
proto.display()
39-
),
40-
));
15+
// Get absolute proto dir from producer
16+
let proto_dir = PathBuf::from(
17+
env::var("DEP_PROTOSOL_PROTO_DIR")
18+
.expect("protosol did not expose PROTO_DIR, did protosol build.rs run first?"),
19+
);
20+
21+
println!("cargo:rerun-if-env-changed=DEP_PROTOSOL_PROTO_DIR");
22+
println!("cargo:rerun-if-changed={}", proto_dir.display());
23+
24+
// Collect absolute .proto paths
25+
let mut proto_files = vec![];
26+
for entry in fs::read_dir(&proto_dir)? {
27+
let path = entry?.path();
28+
if path.extension().and_then(|e| e.to_str()) == Some("proto") {
29+
println!("cargo:rerun-if-changed={}", path.display());
30+
proto_files.push(path);
4131
}
4232
}
4333

44-
prost_build::compile_protos(protos, &[proto_base_path])?;
34+
// Ensure deterministic order for rebuilds
35+
proto_files.sort();
36+
37+
// Compile protos into Rust
38+
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
39+
let mut config = prost_build::Config::new();
40+
config.out_dir(&out_dir);
41+
42+
config.compile_protos(
43+
&proto_files
44+
.iter()
45+
.map(|p| p.display().to_string())
46+
.collect::<Vec<_>>(),
47+
&[proto_dir.to_str().unwrap()],
48+
)?;
4549

4650
Ok(())
4751
}

scripts/fetch_proto.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

scripts/generate_cargo.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import os
1212
import subprocess
1313

14+
# NOTE: this needs bumped with schema version upgrades of the protocol
15+
PROTOSOL_VERSION_TAG = "v1.0.4"
16+
1417
def replace_path_with_git_rev(toml_data, git_url, rev):
1518
"""
1619
Recursively process the TOML data to replace path with git and rev,
@@ -78,15 +81,23 @@ def parse_toml_file(file_path):
7881
return parse(f.read())
7982

8083
def main():
84+
global PROTOSOL_VERSION_TAG
8185

8286
parser = argparse.ArgumentParser(description="Process input files.")
8387

8488
# # Add flags
8589
parser.add_argument("--commit", "-c", help="Commit in firedancer-io/agave to use")
8690
parser.add_argument("--agave-path", "-p", help="Commit in firedancer-io/agave to use")
8791
parser.add_argument("--output", "-o", help="Path to the output file")
92+
parser.add_argument("--version", "-v", help=f"Protosol version to use (e.g. \"{PROTOSOL_VERSION_TAG}\")")
8893

8994
args = parser.parse_args()
95+
if args.version:
96+
PROTOSOL_VERSION_TAG = args.version
97+
# Prepend 'v' if not already present
98+
if not PROTOSOL_VERSION_TAG.startswith('v'):
99+
PROTOSOL_VERSION_TAG = 'v' + PROTOSOL_VERSION_TAG
100+
print(f"Using protosol version: {PROTOSOL_VERSION_TAG}")
90101

91102
if args.agave_path:
92103
toml_data = parse_toml_file(args.agave_path + "/Cargo.toml")
@@ -117,6 +128,20 @@ def main():
117128
if patch_to_remove in toml_data.get("patch", {}).get("crates-io", {}):
118129
del toml_data["patch"]["crates-io"][patch_to_remove]
119130

131+
# Add protosol dependency (deduped if already present)
132+
if "dependencies" not in toml_data:
133+
toml_data["dependencies"] = table()
134+
135+
# Remove existing protosol if present to ensure we use the correct version
136+
if "protosol" in toml_data["dependencies"]:
137+
del toml_data["dependencies"]["protosol"]
138+
139+
# Add the required protosol dependency
140+
protosol_dep = inline_table()
141+
protosol_dep["git"] = "https://github.com/firedancer-io/protosol"
142+
protosol_dep["tag"] = PROTOSOL_VERSION_TAG
143+
toml_data["dependencies"]["protosol"] = protosol_dep
144+
120145
# add required solfuzz-agave added configurations
121146
solfuzz_agave_config = parse_toml_file("solfuzz_agave.toml")
122147
for section, values in solfuzz_agave_config.items():
@@ -141,4 +166,4 @@ def main():
141166
f.write(toml_data.as_string())
142167

143168
if __name__ == "__main__":
144-
main()
169+
main()

0 commit comments

Comments
 (0)