From 9f9989ea72f93f9ffb6792d7297f981d86c72b20 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 2 Feb 2023 18:04:40 +0100 Subject: [PATCH] Properly detect changes in Rust code and recompile Rust libraries Due to we need to substitude config for Rust builds (see #44762 for details), the source dir is copied to the binary dir, but this is done only once, so to detect changes in sources you need to run cmake, without this patch. Signed-off-by: Azat Khuzhin --- rust/CMakeLists.txt | 14 +++++++++++++- rust/copy_exclude.cmake | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 rust/copy_exclude.cmake diff --git a/rust/CMakeLists.txt b/rust/CMakeLists.txt index 1f11423a557..ec2377fce71 100644 --- a/rust/CMakeLists.txt +++ b/rust/CMakeLists.txt @@ -51,8 +51,20 @@ file(COPY ".cargo" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") function(add_rust_subdirectory src) set(dst "${CMAKE_CURRENT_BINARY_DIR}/${src}") message(STATUS "Copy ${src} to ${dst}") - file(COPY "${src}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") + file(COPY "${src}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" + PATTERN target EXCLUDE) add_subdirectory("${dst}" "${dst}") + + # cmake -E copy* do now know how to exclude files + # but we need to exclude "target" folder from copying, if someone or semantic + # completion created it. + add_custom_target(${src}-update ALL + COMMAND ${CMAKE_COMMAND} + -DFROM=${src} + -DTO=${CMAKE_CURRENT_BINARY_DIR} + -P "${CMAKE_CURRENT_SOURCE_DIR}/copy_exclude.cmake" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + VERBATIM) endfunction() add_rust_subdirectory (BLAKE3) diff --git a/rust/copy_exclude.cmake b/rust/copy_exclude.cmake new file mode 100644 index 00000000000..c6a6ff56b6e --- /dev/null +++ b/rust/copy_exclude.cmake @@ -0,0 +1,2 @@ +file(COPY "${FROM}" DESTINATION "${TO}" + PATTERN target EXCLUDE)