Skip to content

Commit bb33401

Browse files
committed
Changes needed to prepare crate to be compatible with crate2nix (#312)
# Description In stackabletech/operator-templating#212 we are planning to add a more developer friendly workflow for building and deploying artifacts to Kubernetes during development. This workflow uses crate2nix, which uses rustc directly and does not provide all environment variables required by the built crate we use (see nix-community/crate2nix#158). The content of these PR are the fixes needed to work around those limitations. Co-authored-by: Sönke Liebau <[email protected]>
1 parent 7077c3a commit bb33401

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/stackable-hdfs-operator.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clap::Parser;
1+
use clap::{crate_description, crate_version, Parser};
22
use stackable_hdfs_crd::constants::APP_NAME;
33
use stackable_hdfs_crd::HdfsCluster;
44
use stackable_hdfs_operator::OPERATOR_NAME;
@@ -10,10 +10,11 @@ use stackable_operator::{
1010
mod built_info {
1111
// The file has been placed there by the build script.
1212
include!(concat!(env!("OUT_DIR"), "/built.rs"));
13+
pub const TARGET_PLATFORM: Option<&str> = option_env!("TARGET");
1314
}
1415

1516
#[derive(clap::Parser)]
16-
#[clap(about = built_info::PKG_DESCRIPTION, author = stackable_operator::cli::AUTHOR)]
17+
#[clap(about, author)]
1718
struct Opts {
1819
#[clap(subcommand)]
1920
cmd: Command,
@@ -36,10 +37,10 @@ async fn main() -> anyhow::Result<()> {
3637
);
3738

3839
stackable_operator::utils::print_startup_string(
39-
built_info::PKG_DESCRIPTION,
40-
built_info::PKG_VERSION,
40+
crate_description!(),
41+
crate_version!(),
4142
built_info::GIT_VERSION,
42-
built_info::TARGET,
43+
built_info::TARGET_PLATFORM.unwrap_or("unknown target"),
4344
built_info::BUILT_TIME_UTC,
4445
built_info::RUSTC_VERSION,
4546
);

0 commit comments

Comments
 (0)