fix: use runtime CARGO_MANIFEST_DIR

Problem: env!() bakes the path at compile time,
so it breaks when the binary runs from a different
location (e.g. a Guix/Nix sandbox or container).

Solution: use std::env::var() to read it at runtime.
This commit is contained in:
Sylvain Bellemare 2026-03-17 23:08:58 +09:00
parent e9c408fbca
commit b83800ba5a
No known key found for this signature in database
GPG key ID: C38AE0ECCAB7D5C8
2 changed files with 2 additions and 2 deletions

View file

@ -144,5 +144,5 @@ fn main() {
}
fn project_root() -> PathBuf {
Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(1).unwrap().to_path_buf()
Path::new(&std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set — this binary must be run via cargo")).ancestors().nth(1).unwrap().to_path_buf()
}

View file

@ -1511,7 +1511,7 @@ impl Builder {
pub fn cargo() -> String { env::var("CARGO").unwrap_or_else(|_| "cargo".to_string()) }
pub fn project_root() -> PathBuf {
Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(1).unwrap().to_path_buf()
Path::new(&std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set — this binary must be run via cargo")).ancestors().nth(1).unwrap().to_path_buf()
}
use std::fs::File;