From bae735740ca6afeacba243913015638ea15f17eb Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 27 Oct 2025 08:29:32 +0100 Subject: [PATCH] Rename FISH_BUILD_DIR variable, to assert that CMake is used It's always the CMake output directory, so call it FISH_CMAKE_BINARY_DIR. It's possible to set it via some other build system but if such builds exist, they are likely subtly broken, or at least with the following commit which adds the assumption that "share/__fish_build_paths.fish.in" exists in this directory. We could even call it CMAKE_BINARY_DIR but let's namespace it to make our use more obvious. Also, stop using the $CMAKE environment variable, it's not in our namespace. --- build.rs | 1 + cmake/Rust.cmake | 4 +--- crates/build-helper/src/lib.rs | 3 +-- src/builtins/status.rs | 5 +---- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/build.rs b/build.rs index 9dacdb103..73eec2a69 100644 --- a/build.rs +++ b/build.rs @@ -81,6 +81,7 @@ fn detect_cfgs(target: &mut Target) { ("", &(|_: &Target| false) as &dyn Fn(&Target) -> bool), ("apple", &detect_apple), ("bsd", &detect_bsd), + ("using_cmake", &|_| option_env!("FISH_CMAKE_BINARY_DIR").is_some()), ("cygwin", &detect_cygwin), ("small_main_stack", &has_small_stack), // See if libc supports the thread-safe localeconv_l(3) alternative to localeconv(3). diff --git a/cmake/Rust.cmake b/cmake/Rust.cmake index 00ddf9055..370c2287d 100644 --- a/cmake/Rust.cmake +++ b/cmake/Rust.cmake @@ -31,10 +31,8 @@ list(JOIN FISH_CARGO_FEATURES_LIST , FISH_CARGO_FEATURES) # Tell Cargo where our build directory is so it can find Cargo.toml. set(VARS_FOR_CARGO - "FISH_BUILD_DIR=${CMAKE_BINARY_DIR}" + "FISH_CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}" "PREFIX=${CMAKE_INSTALL_PREFIX}" - # Cheesy so we can tell cmake was used to build - "CMAKE=1" "DOCDIR=${CMAKE_INSTALL_FULL_DOCDIR}" "DATADIR=${CMAKE_INSTALL_FULL_DATADIR}" "SYSCONFDIR=${CMAKE_INSTALL_FULL_SYSCONFDIR}" diff --git a/crates/build-helper/src/lib.rs b/crates/build-helper/src/lib.rs index df9baf1b1..ddc4df2df 100644 --- a/crates/build-helper/src/lib.rs +++ b/crates/build-helper/src/lib.rs @@ -29,8 +29,7 @@ fn cargo_target_dir() -> Cow<'static, Path> { } pub fn fish_build_dir() -> Cow<'static, Path> { - // This is set if using CMake. - option_env!("FISH_BUILD_DIR") + option_env!("FISH_CMAKE_BINARY_DIR") .map(|d| Cow::Borrowed(Path::new(d))) .unwrap_or(cargo_target_dir()) } diff --git a/src/builtins/status.rs b/src/builtins/status.rs index ad83ac7c7..54eb7e6dc 100644 --- a/src/builtins/status.rs +++ b/src/builtins/status.rs @@ -579,10 +579,7 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> B let host = bytes2wcstring(env!("BUILD_HOST_TRIPLE").as_bytes()); let profile = bytes2wcstring(env!("BUILD_PROFILE").as_bytes()); streams.out.append(L!("Build system: ")); - let buildsystem = match option_env!("CMAKE") { - Some("1") => "CMake", - _ => "Cargo", - }; + let buildsystem = if cfg!(using_cmake) { "CMake" } else { "Cargo" }; streams.out.appendln(bytes2wcstring(buildsystem.as_bytes())); streams.out.append(L!("Version: ")); streams.out.appendln(version);