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 <a.khuzhin@semrush.com>
This commit is contained in:
Azat Khuzhin 2023-02-02 18:04:40 +01:00
parent 3d6883dd9c
commit 9f9989ea72
2 changed files with 15 additions and 1 deletions

View File

@ -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)

2
rust/copy_exclude.cmake Normal file
View File

@ -0,0 +1,2 @@
file(COPY "${FROM}" DESTINATION "${TO}"
PATTERN target EXCLUDE)