Skip to content

Commit 7dc6057

Browse files
committed
[CMake] Workaround stale object files causing rebuilds
Consider the case of A -> B. The previous workaround will add a `forced-B-dep.swift` to A that is touched if B rebuilds. So if B is rebuilt, A is also rebuilt. But A itself has no real changes, and so none of its object files are built and none of the mtimes are updated. Thus, A is then rebuilt again on the next run because its input (`forced-B-dep.swift`) is newer than the corresponding object file. To prevent this, update the mtime for the library and object files after the build (which is actually a link step that both compiles and links).
1 parent bcaad6d commit 7dc6057

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cmake/modules/AddSwiftHostLibrary.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ function(add_swift_host_library name)
3030
COMMAND "${CMAKE_COMMAND}" -E make_directory ${module_base}
3131
COMMENT "Generating module directory for ${name}")
3232

33+
# Touch the library and objects to workaround their mtime not being updated
34+
# when there are no real changes (eg. a file was updated with a comment).
35+
# Ideally this should be done in the driver, which could only update the
36+
# files that have changed.
37+
add_custom_command(
38+
TARGET ${name}
39+
POST_BUILD
40+
COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $<TARGET_FILE:${name}> $<TARGET_OBJECTS:${name}>
41+
COMMAND_EXPAND_LISTS
42+
COMMENT "Update mtime of library outputs workaround")
43+
3344
# Install the Swift module into the appropriate location.
3445
set_target_properties(${name}
3546
PROPERTIES Swift_MODULE_DIRECTORY ${module_dir}

0 commit comments

Comments
 (0)