Skip to content

Commit 9ed7ab0

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 9ed7ab0

File tree

11 files changed

+45
-10
lines changed

11 files changed

+45
-10
lines changed

Sources/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,31 @@
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+
#
18+
# Remove once rdar://102202478 is fixed.
19+
function(force_target_link_libraries TARGET)
20+
cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN})
21+
22+
target_link_libraries(${TARGET} PUBLIC ${ARGS_PUBLIC})
23+
foreach(DEPENDENCY ${ARGS_PUBLIC})
24+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
25+
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
26+
DEPENDS ${DEPENDENCY}
27+
)
28+
target_sources(${TARGET} PRIVATE
29+
${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
30+
)
31+
endforeach()
32+
endfunction()
33+
934
add_subdirectory(SwiftBasicFormat)
1035
add_subdirectory(SwiftSyntax)
1136
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+
force_target_link_libraries(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+
force_target_link_libraries(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+
force_target_link_libraries(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+
force_target_link_libraries(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+
force_target_link_libraries(SwiftOperators PUBLIC
2324
SwiftSyntax
2425
SwiftDiagnostics
2526
SwiftParser)

Sources/SwiftParser/CMakeLists.txt

Lines changed: 2 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+
force_target_link_libraries(SwiftParser PUBLIC
4041
SwiftSyntax
4142
SwiftDiagnostics)
4243

Sources/SwiftParser/Parser.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ extension Parser {
1616
/// Parse the source code in the given string as Swift source file.
1717
public static func parse(
1818
source: String,
19-
parseTransition: IncrementalParseTransition? = nil
19+
parseTransition: IncrementalParseTransition? = nil,
20+
newArgs: String? = nil
2021
) -> SourceFileSyntax {
2122
var source = source
2223
source.makeContiguousUTF8()

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+
force_target_link_libraries(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+
force_target_link_libraries(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+
force_target_link_libraries(_SwiftSyntaxMacros PUBLIC
2122
SwiftParser
2223
SwiftSyntaxBuilder
2324
)

0 commit comments

Comments
 (0)