Skip to content

Commit 8675ce9

Browse files
Walk proto dir instead of manually specifying needed files
1 parent a9b08a1 commit 8675ce9

File tree

3 files changed

+62
-8
lines changed

3 files changed

+62
-8
lines changed

Cargo.lock

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/proto/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ prost = "0.13"
99

1010
[build-dependencies]
1111
tonic-build = "0.12"
12+
walkdir = "2.5"
1213

1314
[lib]
1415
path = "lib.rs"

lib/proto/build.rs

+32-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::path::Path;
1+
use std::path::{Path, PathBuf};
2+
use walkdir::WalkDir;
23

34
fn main() -> Result<(), Box<dyn std::error::Error>> {
45
let workspace_dir = Path::new(env!("CARGO_WORKSPACE_DIR"));
@@ -8,13 +9,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
89
let proto_file_descriptor_set_path = Path::new("generated/bin/descriptor.bin");
910
let generated_include_file = Path::new("include.rs");
1011

11-
let v1_protos = [
12-
proto_tuxtape_dir.join("server/database/v1/database.proto"),
13-
proto_tuxtape_dir.join("server/registrar/v1/registrar.proto"),
14-
proto_tuxtape_dir.join("server/fleet_client/v1/fleet_client.proto"),
15-
proto_tuxtape_dir.join("kernel_builder/v1/kernel_builder.proto"),
16-
proto_tuxtape_dir.join("patch_builder/v1/patch_builder.proto"),
17-
];
12+
let v1_protos = fetch_proto_dirs(&proto_tuxtape_dir, 1, &["common"]);
1813

1914
let mut config = tonic_build::Config::default();
2015
config.out_dir(proto_src_out_dir);
@@ -29,3 +24,32 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2924

3025
Ok(())
3126
}
27+
28+
fn fetch_proto_dirs(
29+
proto_package_dir: &Path,
30+
proto_version: usize,
31+
ignore_modules: &[&str],
32+
) -> Vec<PathBuf> {
33+
let version_str = format!("v{proto_version}");
34+
WalkDir::new(proto_package_dir)
35+
.into_iter()
36+
// Remove all files that don't have read permission
37+
.filter_map(|e| e.ok())
38+
.filter(|entry| entry.path().extension().is_some_and(|ext| ext == "proto"))
39+
.filter(|entry| {
40+
entry
41+
.path()
42+
.components()
43+
.filter_map(|comp| comp.as_os_str().to_str())
44+
.any(|comp| comp == version_str)
45+
})
46+
.filter(|entry| {
47+
!entry
48+
.path()
49+
.components()
50+
.filter_map(|comp| comp.as_os_str().to_str())
51+
.any(|comp| ignore_modules.contains(&comp))
52+
})
53+
.map(|entry| entry.path().to_path_buf())
54+
.collect()
55+
}

0 commit comments

Comments
 (0)