Skip to content

Commit 76c9ce2

Browse files
committed
Changes to be compatible with crate2nix (#383)
see stackabletech/operator-templating#212 for more details
1 parent fdd2a79 commit 76c9ce2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

rust/operator-binary/build.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
use std::path::PathBuf;
2+
13
fn main() {
2-
built::write_built_file().expect("Failed to acquire build-time information");
4+
let out_dir = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR is required"));
5+
built::write_built_file_with_opts(
6+
// built's env module depends on a whole bunch of variables that crate2nix doesn't provide
7+
// so we grab the specific env variables that we care about out ourselves instead.
8+
built::Options::default().set_env(false),
9+
"Cargo.toml".as_ref(),
10+
&out_dir.join("built.rs"),
11+
)
12+
.unwrap();
313
}

rust/operator-binary/src/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod product_logging;
66

77
use crate::controller::{CONTROLLER_NAME, OPERATOR_NAME};
88

9-
use clap::Parser;
9+
use clap::{crate_description, crate_version, Parser};
1010
use futures::stream::StreamExt;
1111
use stackable_operator::{
1212
cli::{Command, ProductOperatorRun},
@@ -27,10 +27,11 @@ use std::sync::Arc;
2727

2828
mod built_info {
2929
include!(concat!(env!("OUT_DIR"), "/built.rs"));
30+
pub const TARGET_PLATFORM: Option<&str> = option_env!("TARGET");
3031
}
3132

3233
#[derive(Parser)]
33-
#[clap(about = built_info::PKG_DESCRIPTION, author = stackable_operator::cli::AUTHOR)]
34+
#[clap(about, author)]
3435
struct Opts {
3536
#[clap(subcommand)]
3637
cmd: Command,
@@ -55,10 +56,10 @@ async fn main() -> anyhow::Result<()> {
5556
tracing_target,
5657
);
5758
stackable_operator::utils::print_startup_string(
58-
built_info::PKG_DESCRIPTION,
59-
built_info::PKG_VERSION,
59+
crate_description!(),
60+
crate_version!(),
6061
built_info::GIT_VERSION,
61-
built_info::TARGET,
62+
built_info::TARGET_PLATFORM.unwrap_or("unknown target"),
6263
built_info::BUILT_TIME_UTC,
6364
built_info::RUSTC_VERSION,
6465
);

0 commit comments

Comments
 (0)