diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 9be2e5b333c4431a522c6c1fab5659da47a8636a_cnVzdC9DYXJnby5sb2Nr..bd9e9d777e70fc6442ab07b717848d2f17f0ef26_cnVzdC9DYXJnby5sb2Nr 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -161,6 +161,12 @@ ] [[package]] +name = "build_const" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7" + +[[package]] name = "byteorder" version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1248,6 +1254,7 @@ name = "rhgitaly" version = "0.1.0" dependencies = [ + "build_const", "hg-core", "prost", "prost-types", diff --git a/rust/rhgitaly/Cargo.toml b/rust/rhgitaly/Cargo.toml index 9be2e5b333c4431a522c6c1fab5659da47a8636a_cnVzdC9yaGdpdGFseS9DYXJnby50b21s..bd9e9d777e70fc6442ab07b717848d2f17f0ef26_cnVzdC9yaGdpdGFseS9DYXJnby50b21s 100644 --- a/rust/rhgitaly/Cargo.toml +++ b/rust/rhgitaly/Cargo.toml @@ -13,5 +13,6 @@ tokio-stream = { version = "0.1", features = ["net"] } tracing = "0.1.37" tracing-subscriber = "0.3.16" +build_const = "0.2" [build-dependencies] @@ -16,3 +17,4 @@ [build-dependencies] -tonic-build = "0.8" \ No newline at end of file +tonic-build = "0.8" +build_const = "0.2" \ No newline at end of file diff --git a/rust/rhgitaly/build.rs b/rust/rhgitaly/build.rs index 9be2e5b333c4431a522c6c1fab5659da47a8636a_cnVzdC9yaGdpdGFseS9idWlsZC5ycw==..bd9e9d777e70fc6442ab07b717848d2f17f0ef26_cnVzdC9yaGdpdGFseS9idWlsZC5ycw== 100644 --- a/rust/rhgitaly/build.rs +++ b/rust/rhgitaly/build.rs @@ -1,1 +1,17 @@ +use std::fs::File; +use std::io::Read; + +use build_const::ConstWriter; + +fn build_constants() -> Result<(), Box<dyn std::error::Error>> { + // use `for_build` in `build.rs` + let mut consts = ConstWriter::for_build("constants")?.finish_dependencies(); + let mut version = String::new(); + File::open("../../hgitaly/VERSION")?.read_to_string(&mut version)?; + + // Add a value that is a result of "complex" calculations + consts.add_value("HGITALY_VERSION", "&str", version.trim()); + Ok(()) +} + fn main() -> Result<(), Box<dyn std::error::Error>> { @@ -1,4 +17,5 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { + build_constants()?; tonic_build::configure() .build_server(true) .out_dir("src/generated") diff --git a/rust/rhgitaly/src/lib.rs b/rust/rhgitaly/src/lib.rs index 9be2e5b333c4431a522c6c1fab5659da47a8636a_cnVzdC9yaGdpdGFseS9zcmMvbGliLnJz..bd9e9d777e70fc6442ab07b717848d2f17f0ef26_cnVzdC9yaGdpdGFseS9zcmMvbGliLnJz 100644 --- a/rust/rhgitaly/src/lib.rs +++ b/rust/rhgitaly/src/lib.rs @@ -3,6 +3,8 @@ // This software may be used and distributed according to the terms of the // GNU General Public License version 2 or any later version. // SPDX-License-Identifier: GPL-2.0-or-later +#[macro_use] +extern crate build_const; // The generated module is derived from the Protobuf "package" name // Hence as soon as we start compiling the HGitaly-specific proto files, diff --git a/rust/rhgitaly/src/service/server.rs b/rust/rhgitaly/src/service/server.rs index 9be2e5b333c4431a522c6c1fab5659da47a8636a_cnVzdC9yaGdpdGFseS9zcmMvc2VydmljZS9zZXJ2ZXIucnM=..bd9e9d777e70fc6442ab07b717848d2f17f0ef26_cnVzdC9yaGdpdGFseS9zcmMvc2VydmljZS9zZXJ2ZXIucnM= 100644 --- a/rust/rhgitaly/src/service/server.rs +++ b/rust/rhgitaly/src/service/server.rs @@ -8,6 +8,8 @@ use tonic::{Request, Response, Status}; use tracing::{info, instrument}; +build_const!("constants"); + #[derive(Debug, Default)] pub struct ServerServiceImpl {} @@ -19,11 +21,10 @@ _request: Request<ServerInfoRequest>, ) -> Result<Response<ServerInfoResponse>, Status> { info!("Processing"); - - let mut resp = ServerInfoResponse::default(); - resp.server_version = "RHGitaly/Tonic 6.6.6".into(); - - Ok(Response::new(resp)) + Ok(Response::new(ServerInfoResponse { + server_version: HGITALY_VERSION.into(), + ..Default::default() + })) } }