Skip to content

Commit 67d9a9c

Browse files
committed
Temporarily workaround CMake dependencies bug
Workaround a CMake bug in order to make sure that libraries are rebuilt when their dependencies change.
1 parent ef4605b commit 67d9a9c

File tree

10 files changed

+53
-9
lines changed

10 files changed

+53
-9
lines changed

Sources/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9+
# cmake generation for Swift adds an order only dependency, which matches how C-family languages
10+
# works. In that case, however, ninja (and presumably other generators) will rebuild on header
11+
# changes. That's not the case for Swift, and thus if A -> B, A is not being rebuilt when the
12+
# ABI/API of B changes.
13+
#
14+
# For now workaround this by touching a file whenever B is rebuilt and then compiling that file as
15+
# part of A. Ideally this file would be generated by each of the targets, but that dependency didn't
16+
# seem to be being tracked.
17+
function(add_forced_dependencies TARGET)
18+
cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN})
19+
20+
foreach(DEPENDENCY ${ARGS_PUBLIC})
21+
target_link_libraries(${TARGET} PUBLIC
22+
${DEPENDENCY}
23+
)
24+
25+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
26+
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
27+
DEPENDS ${DEPENDENCY}
28+
)
29+
target_sources(${TARGET} PRIVATE
30+
${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
31+
)
32+
endforeach()
33+
endfunction()
34+
935
add_subdirectory(SwiftBasicFormat)
1036
add_subdirectory(SwiftSyntax)
1137
add_subdirectory(SwiftDiagnostics)

Sources/IDEUtils/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ add_library(IDEUtils STATIC
1212
SyntaxClassifier.swift
1313
)
1414

15-
target_link_libraries(IDEUtils PUBLIC
15+
# TODO: Change to target_link_libraries when cmake is fixed
16+
add_forced_dependencies(IDEUtils PUBLIC
1617
SwiftSyntax)
1718

1819
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS IDEUtils)

Sources/SwiftBasicFormat/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ add_library(SwiftBasicFormat STATIC
1313
Utils.swift
1414
)
1515

16-
target_link_libraries(SwiftBasicFormat PUBLIC
16+
# TODO: Change to target_link_libraries when cmake is fixed
17+
add_forced_dependencies(SwiftBasicFormat PUBLIC
1718
SwiftSyntax)
1819

1920
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftBasicFormat)

Sources/SwiftCompilerSupport/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ add_library(SwiftCompilerSupport STATIC
1010
ConsistencyCheck.swift
1111
)
1212

13-
target_link_libraries(SwiftCompilerSupport PUBLIC
13+
# TODO: Change to target_link_libraries when cmake is fixed
14+
add_forced_dependencies(SwiftCompilerSupport PUBLIC
1415
SwiftSyntax
1516
SwiftDiagnostics
1617
SwiftParser

Sources/SwiftDiagnostics/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ add_library(SwiftDiagnostics STATIC
1414
Note.swift
1515
)
1616

17-
target_link_libraries(SwiftDiagnostics PUBLIC
17+
# TODO: Change to target_link_libraries when cmake is fixed
18+
add_forced_dependencies(SwiftDiagnostics PUBLIC
1819
SwiftSyntax)
1920

2021
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftDiagnostics)

Sources/SwiftOperators/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ add_library(SwiftOperators STATIC
1919
SyntaxSynthesis.swift
2020
)
2121

22-
target_link_libraries(SwiftOperators PUBLIC
22+
# TODO: Change to target_link_libraries when cmake is fixed
23+
add_forced_dependencies(SwiftOperators PUBLIC
2324
SwiftSyntax
2425
SwiftDiagnostics
2526
SwiftParser)

Sources/SwiftParser/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ add_library(SwiftParser STATIC
3636
gyb_generated/DeclarationModifier.swift
3737
gyb_generated/TypeAttribute.swift)
3838

39-
target_link_libraries(SwiftParser PUBLIC
39+
# TODO: Change to target_link_libraries when cmake is fixed
40+
add_forced_dependencies(SwiftParser PUBLIC
4041
SwiftSyntax
4142
SwiftDiagnostics)
4243

@@ -47,6 +48,15 @@ set_target_properties(SwiftParser PROPERTIES
4748
INTERFACE_INCLUDE_DIRECTORIES
4849
"${CMAKE_Swift_MODULE_DIRECTORY}")
4950

51+
#file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/SwiftParser-complete.swift)
52+
#add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/SwiftParser-complete.swift
53+
# COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/SwiftParser-complete.swift
54+
# DEPENDS SwiftParser
55+
#)
56+
#set_target_properties(SwiftParser
57+
# PROPERTIES FORCE_DEP_PATH ${CMAKE_CURRENT_BINARY_DIR}/SwiftParser-complete.swift
58+
#)
59+
5060
install(TARGETS SwiftParser
5161
EXPORT SwiftSyntaxTargets
5262
ARCHIVE DESTINATION lib

Sources/SwiftParserDiagnostics/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ add_library(SwiftParserDiagnostics STATIC
1515
SyntaxExtensions.swift
1616
Utils.swift)
1717

18-
target_link_libraries(SwiftParserDiagnostics PUBLIC
18+
# TODO: Change to target_link_libraries when cmake is fixed
19+
add_forced_dependencies(SwiftParserDiagnostics PUBLIC
1920
SwiftBasicFormat
2021
SwiftDiagnostics
2122
SwiftParser

Sources/SwiftSyntaxBuilder/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ add_library(SwiftSyntaxBuilder STATIC
2323
gyb_generated/SyntaxExpressibleByStringInterpolationConformances.swift
2424
)
2525

26-
target_link_libraries(SwiftSyntaxBuilder PUBLIC
26+
# TODO: Change to target_link_libraries when cmake is fixed
27+
add_forced_dependencies(SwiftSyntaxBuilder PUBLIC
2728
SwiftBasicFormat
2829
SwiftParser
2930
SwiftParserDiagnostics

Sources/_SwiftSyntaxMacros/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ add_library(_SwiftSyntaxMacros STATIC
1717
Syntax+MacroEvaluation.swift
1818
)
1919

20-
target_link_libraries(_SwiftSyntaxMacros PUBLIC
20+
# TODO: Change to target_link_libraries when cmake is fixed
21+
add_forced_dependencies(_SwiftSyntaxMacros PUBLIC
2122
SwiftParser
2223
SwiftSyntaxBuilder
2324
)

0 commit comments

Comments
 (0)