From 3a98db46bca35908fc8ca3a902d09bcf95f32487 Mon Sep 17 00:00:00 2001 From: David Adam Date: Sun, 31 Mar 2024 13:43:55 +0800 Subject: [PATCH] build.rs: pick up version file for tarballs from source, not build, directory (#10400) --- build.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index ebe3f3b2c..b664b0835 100644 --- a/build.rs +++ b/build.rs @@ -3,7 +3,7 @@ use rsconf::{LinkType, Target}; use std::env; use std::error::Error; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; fn main() { setup_paths(); @@ -24,7 +24,12 @@ fn main() { .unwrap(), ); - rsconf::set_env_value("FISH_BUILD_VERSION", &get_version(build_dir)); + // Per https://doc.rust-lang.org/cargo/reference/build-scripts.html#inputs-to-the-build-script, + // the source directory is the current working directory of the build script + rsconf::set_env_value( + "FISH_BUILD_VERSION", + &get_version(&env::current_dir().unwrap()), + ); rsconf::rebuild_if_path_changed("src/libc.c"); cc::Build::new() @@ -196,7 +201,7 @@ fn setup_paths() { rsconf::rebuild_if_env_changed("DOCDIR"); } -fn get_version(build_dir: &str) -> String { +fn get_version(src_dir: &Path) -> String { use std::fs::read_to_string; use std::process::Command; @@ -204,7 +209,7 @@ fn get_version(build_dir: &str) -> String { return var; } - let path = PathBuf::from(build_dir).join("version"); + let path = PathBuf::from(src_dir).join("version"); if let Ok(strver) = read_to_string(path) { return strver.to_string(); }