From 8e73a4c5af4fd049e72c25961e211578677d40ea Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Sat, 3 Feb 2024 09:55:16 +0100 Subject: [PATCH] cmake: Do add dependencies Unfortunately ninja does not want to be tricked. I tried `touch`ing a file and writing the date to a file, and even removing that file before cargo runs, it doesn't work. So instead we'll do the imperfect solution of enumerating sources. And yes, we use a GLOB because listing source files is terrible. Any build system that wants you not to glob is a build system made for build system people who like touching build systems, not me. --- CMakeLists.txt | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a80fc302d..95387e690 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,16 +93,10 @@ add_definitions(-DCMAKE_SOURCE_DIR="${REAL_CMAKE_SOURCE_DIR}") # Enable thread-safe errno on Solaris (#5611) add_definitions(-D_REENTRANT) -# Cmake doesn't know when cargo should be rerun. -# We could enumerate when (source files changed, Cargo.toml/lock, cargo update, ...), -# but that's a pain and cargo takes <100ms when there's nothing to do, -# so we can just always rerun it. -# So this adds a dummy command that is successful but creates no output, -# and then depend on it. -add_custom_command( - OUTPUT always_rebuild - COMMAND echo -) +# cargo needs to be rerun when the sources change. +# This is imperfect, but the ninja generator really wants to +# not run cargo, so we need to tell it *something* +FILE(GLOB sources src/*) add_custom_command( OUTPUT ${rust_target_dir}/${rust_profile}/libfish.rlib @@ -117,7 +111,8 @@ add_custom_command( ${FEATURES_ARG} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" USES_TERMINAL - DEPENDS always_rebuild + DEPENDS ${sources} + DEPENDS Cargo.toml Cargo.lock build.rs # Don't use VERBATIM here, to allow the generator expressions above to expand to nothing rather than an empty string ) add_custom_target(libfish DEPENDS ${rust_target_dir}/${rust_profile}/libfish.rlib)