Skip to content

Commit 24edb46

Browse files
committed
cli: Use runtime environment variable query in build script
It is incorrect to assume presence of the various environment variables used in the build script snippet at compile time [0]. Switch to using runtime querying instead. [0] https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
1 parent 5589c91 commit 24edb46

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

build.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
// Copyright (C) 2021-2023 The Nitrocli Developers
1+
// Copyright (C) 2021-2025 The Nitrocli Developers
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

4+
use std::env;
5+
6+
use anyhow::Context as _;
47
use anyhow::Result;
58

69
use grev::git_revision_auto;
710

811
fn main() -> Result<()> {
9-
let directory = env!("CARGO_MANIFEST_DIR");
10-
if let Some(git_revision) = git_revision_auto(directory)? {
12+
let manifest_dir =
13+
env::var_os("CARGO_MANIFEST_DIR").context("CARGO_MANIFEST_DIR variable not set")?;
14+
if let Some(git_revision) = git_revision_auto(manifest_dir)? {
1115
println!("cargo:rustc-env=NITROCLI_GIT_REVISION={}", git_revision);
1216
}
1317
Ok(())

0 commit comments

Comments
 (0)