Skip to content

Commit 2335b8b

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 2335b8b

File tree

10 files changed

+58
-9
lines changed

10 files changed

+58
-9
lines changed

Sources/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@
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_dependency TARGET DEPENDENCY)
18+
target_link_libraries(${TARGET} PUBLIC
19+
${DEPENDENCY}
20+
)
21+
22+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
23+
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
24+
DEPENDS ${DEPENDENCY}
25+
)
26+
target_sources(${TARGET} PRIVATE
27+
${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
28+
)
29+
endfunction()
30+
931
add_subdirectory(SwiftBasicFormat)
1032
add_subdirectory(SwiftSyntax)
1133
add_subdirectory(SwiftDiagnostics)

Sources/IDEUtils/CMakeLists.txt

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

15-
target_link_libraries(IDEUtils PUBLIC
15+
# TODO: Change to `target_link_libraries(IDEUtils PUBLIC
16+
# when cmake is fixed
17+
add_forced_dependency(IDEUtils
1618
SwiftSyntax)
1719

1820
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS IDEUtils)

Sources/SwiftBasicFormat/CMakeLists.txt

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

16-
target_link_libraries(SwiftBasicFormat PUBLIC
16+
# TODO: Change to `target_link_libraries(SwiftBasicFormat PUBLIC
17+
# when cmake is fixed
18+
add_forced_dependency(SwiftBasicFormat
1719
SwiftSyntax)
1820

1921
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftBasicFormat)

Sources/SwiftCompilerSupport/CMakeLists.txt

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

13-
target_link_libraries(SwiftCompilerSupport PUBLIC
13+
# TODO: Change to `target_link_libraries(SwiftCompilerSupport PUBLIC
14+
# when cmake is fixed
15+
add_forced_dependency(SwiftCompilerSupport
1416
SwiftSyntax
1517
SwiftDiagnostics
1618
SwiftParser

Sources/SwiftDiagnostics/CMakeLists.txt

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

17-
target_link_libraries(SwiftDiagnostics PUBLIC
17+
# TODO: Change to `target_link_libraries(SwiftDiagnostics PUBLIC
18+
# when cmake is fixed
19+
add_forced_dependency(SwiftDiagnostics
1820
SwiftSyntax)
1921

2022
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftDiagnostics)

Sources/SwiftOperators/CMakeLists.txt

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

22-
target_link_libraries(SwiftOperators PUBLIC
22+
# TODO: Change to `target_link_libraries(SwiftOperators PUBLIC
23+
# when cmake is fixed
24+
add_forced_dependency(SwiftOperators
2325
SwiftSyntax
2426
SwiftDiagnostics
2527
SwiftParser)

Sources/SwiftParser/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ 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(SwiftParser PUBLIC
40+
# when cmake is fixed
41+
add_forced_dependency(SwiftParser
4042
SwiftSyntax
4143
SwiftDiagnostics)
4244

@@ -47,6 +49,15 @@ set_target_properties(SwiftParser PROPERTIES
4749
INTERFACE_INCLUDE_DIRECTORIES
4850
"${CMAKE_Swift_MODULE_DIRECTORY}")
4951

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

Sources/SwiftParserDiagnostics/CMakeLists.txt

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

18-
target_link_libraries(SwiftParserDiagnostics PUBLIC
18+
# TODO: Change to `target_link_libraries(SwiftParserDiagnostics PUBLIC
19+
# when cmake is fixed
20+
add_forced_dependency(SwiftParserDiagnostics
1921
SwiftBasicFormat
2022
SwiftDiagnostics
2123
SwiftParser

Sources/SwiftSyntaxBuilder/CMakeLists.txt

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

26-
target_link_libraries(SwiftSyntaxBuilder PUBLIC
26+
# TODO: Change to `target_link_libraries(SwiftSyntaxBuilder PUBLIC
27+
# when cmake is fixed
28+
add_forced_dependency(SwiftSyntaxBuilder
2729
SwiftBasicFormat
2830
SwiftParser
2931
SwiftParserDiagnostics

Sources/_SwiftSyntaxMacros/CMakeLists.txt

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

20-
target_link_libraries(_SwiftSyntaxMacros PUBLIC
20+
# TODO: Change to `target_link_libraries(_SwiftSyntaxMacros PUBLIC
21+
# when cmake is fixed
22+
add_forced_dependency(_SwiftSyntaxMacros
2123
SwiftParser
2224
SwiftSyntaxBuilder
2325
)

0 commit comments

Comments
 (0)