Skip to content

Commit 14282f1

Browse files
authored
Merge pull request #66484 from bnbarham/remove-rebuilds
[CMake] Prevent rebuilds of pure swift libraries and executables
2 parents b18e7f1 + b0b9705 commit 14282f1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cmake/modules/AddPureSwift.cmake

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function(add_pure_swift_host_library name)
163163
add_custom_command(
164164
TARGET ${name}
165165
POST_BUILD
166-
COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $<TARGET_FILE:${name}> $<TARGET_OBJECTS:${name}>
166+
COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $<TARGET_FILE:${name}> $<TARGET_OBJECTS:${name}> "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${name}.swiftmodule" "${CMAKE_CURRENT_BINARY_DIR}/${name}.swiftmodule"
167167
COMMAND_EXPAND_LISTS
168168
COMMENT "Update mtime of library outputs workaround")
169169

@@ -304,6 +304,24 @@ function(add_pure_swift_host_tool name)
304304
target_include_directories(${name} PUBLIC
305305
${SWIFT_HOST_LIBRARIES_DEST_DIR})
306306

307+
# Workaround to touch the library and its objects so that we don't
308+
# continually rebuild (again, see corresponding change in swift-syntax).
309+
add_custom_command(
310+
TARGET ${name}
311+
POST_BUILD
312+
COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $<TARGET_FILE:${name}> $<TARGET_OBJECTS:${name}>
313+
COMMAND_EXPAND_LISTS
314+
COMMENT "Update mtime of executable outputs workaround")
315+
316+
# Even worse hack - ${name}.swiftmodule is added as an output, even though
317+
# this is an executable target. Just touch it all the time to avoid having
318+
# to rebuild it every time.
319+
add_custom_command(
320+
TARGET ${name}
321+
POST_BUILD
322+
COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/${name}.swiftmodule"
323+
COMMAND_EXPAND_LISTS
324+
COMMENT "Update mtime of executable outputs workaround")
307325
# Export this target.
308326
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
309327
endfunction()

0 commit comments

Comments
 (0)