From 9fa223eaaf0eda4e5f76621dc6d457417afb8b54 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Wed, 12 Jun 2024 17:45:38 +0200 Subject: chore(build): compile protobufs with protox (#2122) * chore(build): compile protobufs with protox protox is a pure-rust implementation of the protobuf compiler. Therefore, it can be managed by cargo. This removes the implicit dependency on protoc being available in the environment for the build. * fix(build): replace copypasta in build script The paths passed to `compile` aren't actually used by the build. `skip_protoc_run` prevents that. That's why a clean build succeeds even with this mistake. However, the paths are passed to a `cargo:rerun-if-changed` directive. So this mistake would've caused a failed incremental build if the protobuf definitions were changed. --- crates/atuin-daemon/Cargo.toml | 1 + crates/atuin-daemon/build.rs | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/atuin-daemon/Cargo.toml b/crates/atuin-daemon/Cargo.toml index 3133bcdf..0f3ccb1a 100644 --- a/crates/atuin-daemon/Cargo.toml +++ b/crates/atuin-daemon/Cargo.toml @@ -38,4 +38,5 @@ rand.workspace = true listenfd = "1.0.1" [build-dependencies] +protox = "0.6.0" tonic-build = "0.11" diff --git a/crates/atuin-daemon/build.rs b/crates/atuin-daemon/build.rs index 95118f6f..37721249 100644 --- a/crates/atuin-daemon/build.rs +++ b/crates/atuin-daemon/build.rs @@ -1,4 +1,17 @@ -fn main() -> Result<(), Box> { - tonic_build::compile_protos("./proto/history.proto")?; - Ok(()) +use std::{env, fs, path::PathBuf}; + +use protox::prost::Message; + +fn main() -> std::io::Result<()> { + let file_descriptors = protox::compile(["history.proto"], ["./proto/"]).unwrap(); + + let file_descriptor_path = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR not set")) + .join("file_descriptor_set.bin"); + fs::write(&file_descriptor_path, file_descriptors.encode_to_vec()).unwrap(); + + tonic_build::configure() + .build_server(true) + .file_descriptor_set_path(&file_descriptor_path) + .skip_protoc_run() + .compile(&["history.proto"], &["."]) } -- cgit v1.3.1