Skip to content

Commit 3b82aa5

Browse files
committed
Changes to be compatible with crate2nix (#208)
see stackabletech/operator-templating#212 for more details
1 parent 524d0a7 commit 3b82aa5

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
@@ -4,7 +4,7 @@ mod spark_k8s_controller;
44

55
use std::sync::Arc;
66

7-
use clap::Parser;
7+
use clap::{crate_description, crate_version, Parser};
88
use futures::StreamExt;
99
use stackable_operator::cli::{Command, ProductOperatorRun};
1010
use stackable_operator::k8s_openapi::api::apps::v1::StatefulSet;
@@ -24,10 +24,11 @@ use tracing_futures::Instrument;
2424

2525
mod built_info {
2626
include!(concat!(env!("OUT_DIR"), "/built.rs"));
27+
pub const TARGET_PLATFORM: Option<&str> = option_env!("TARGET");
2728
}
2829

2930
#[derive(Parser)]
30-
#[clap(about = built_info::PKG_DESCRIPTION, author = stackable_operator::cli::AUTHOR)]
31+
#[clap(about, author)]
3132
struct Opts {
3233
#[clap(subcommand)]
3334
cmd: Command,
@@ -52,10 +53,10 @@ async fn main() -> anyhow::Result<()> {
5253
tracing_target,
5354
);
5455
stackable_operator::utils::print_startup_string(
55-
built_info::PKG_DESCRIPTION,
56-
built_info::PKG_VERSION,
56+
crate_description!(),
57+
crate_version!(),
5758
built_info::GIT_VERSION,
58-
built_info::TARGET,
59+
built_info::TARGET_PLATFORM.unwrap_or("unknown target"),
5960
built_info::BUILT_TIME_UTC,
6061
built_info::RUSTC_VERSION,
6162
);

0 commit comments

Comments
 (0)