Skip to content

Commit 58ca217

Browse files
author
Chris Bieneman
committed
[CMake] Fix bad dependency in symlink_clang_headers
The problem here is a bit complicated. The symlink_clang_headers target creates two symlinks to clang's headers, one under the build directory at lib/swift/clang, and the other under a temporary path. The one under the temporary path is a bad symlink, and it is only created during the build so that it can be installed. It isn't actually used by the build. Ninja treats the bad symlink as a non-existing file, and since the build rule that creates it has the restat property on it this results in the commands to symlink the clang headers directory running over and over and over again during the build. This patch prevents that by not generating the bad symlink during the build. Instead we generate it at install time using the LLVMInstallSymlink script that is vended as part of LLVM's distribution.
1 parent 4cf424e commit 58ca217

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

cmake/modules/SwiftComponents.cmake

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,29 @@ function(swift_install_in_component component)
122122
install(${ARGN})
123123
endif()
124124
endfunction()
125+
126+
function(swift_install_symlink_component component)
127+
cmake_parse_arguments(
128+
ARG # prefix
129+
"" "LINK_NAME;TARGET;DESTINATION" "" ${ARGN})
130+
precondition(ARG_LINK_NAME MESSAGE "LINK_NAME is required")
131+
precondition(ARG_TARGET MESSAGE "TARGET is required")
132+
precondition(ARG_DESTINATION MESSAGE "DESTINATION is required")
133+
134+
swift_is_installing_component("${component}" is_installing)
135+
if (NOT is_installing)
136+
return()
137+
endif()
138+
139+
foreach(path ${CMAKE_MODULE_PATH})
140+
if(EXISTS ${path}/LLVMInstallSymlink.cmake)
141+
set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake)
142+
break()
143+
endif()
144+
endforeach()
145+
precondition(INSTALL_SYMLINK
146+
MESSAGE "LLVMInstallSymlink script must be available.")
147+
148+
install(SCRIPT ${INSTALL_SYMLINK}
149+
CODE "install_symlink(${ARG_LINK_NAME} ${ARG_TARGET} ${ARG_DESTINATION})")
150+
endfunction()

stdlib/public/SwiftShims/CMakeLists.txt

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,8 @@ add_custom_command_target(unused_var
8080
"${clang_headers_location}"
8181
"${SWIFTLIB_DIR}/clang"
8282

83-
# Create a broken symlink that points to '../clang/$VERSION'. It is not
84-
# used when running Swift tools from the build tree directly, but we will
85-
# install it in such a way that it points to Clang installation. If the
86-
# link can be resolved, CMake would try to follow it when installing the
87-
# project under certain conditions.
88-
COMMAND
89-
"${CMAKE_COMMAND}" "-E" "make_directory" "${SWIFTLIB_DIR}/install-tmp/install-tmp"
90-
COMMAND
91-
"${CMAKE_COMMAND}" "-E" "remove"
92-
"${SWIFTLIB_DIR}/install-tmp/install-tmp/clang"
93-
COMMAND
94-
"${CMAKE_COMMAND}" "-E" "create_symlink"
95-
"../clang/${CLANG_VERSION}"
96-
"${SWIFTLIB_DIR}/install-tmp/install-tmp/clang"
9783
CUSTOM_TARGET_NAME "symlink_clang_headers"
98-
OUTPUT "${SWIFTLIB_DIR}/clang" "${SWIFTLIB_DIR}/install-tmp/install-tmp/clang"
84+
OUTPUT "${SWIFTLIB_DIR}/clang"
9985
COMMENT "Symlinking Clang resource headers into ${SWIFTLIB_DIR}/clang")
10086
add_dependencies(copy_shim_headers symlink_clang_headers)
10187

@@ -110,10 +96,10 @@ swift_install_in_component(clang-builtin-headers
11096
DESTINATION "lib/swift/clang"
11197
PATTERN "*.h")
11298

113-
# Alternatively, install a symbolic link to the Clang resource directory.
114-
swift_install_in_component(clang-resource-dir-symlink
115-
DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/swift/install-tmp/install-tmp/clang"
116-
DESTINATION "lib/swift")
99+
swift_install_symlink_component(clang-resource-dir-symlink
100+
LINK_NAME clang
101+
TARGET ../clang/${CLANG_VERSION}
102+
DESTINATION "lib/swift")
117103

118104
# Possibly install Clang headers under Clang's resource directory in case we
119105
# need to use a different version of the headers than the installed Clang. This

0 commit comments

Comments
 (0)