Skip to content

Commit 4da85ea

Browse files
committed
Clean up build logic for ASTGen library.
Only introduce it and its dependency when the new Swift parser is being built, and rely more on existing logic to make sure we get the right build/link flags.
1 parent 2560aed commit 4da85ea

File tree

6 files changed

+49
-44
lines changed

6 files changed

+49
-44
lines changed

include/swift/AST/CASTBridging.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,7 @@ void Stmt_dump(void *);
155155

156156
SWIFT_END_NULLABILITY_ANNOTATIONS
157157

158-
#endif // SWIFT_C_AST_ASTBRIDGING_H
158+
#undef SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
159+
#undef SWIFT_END_NULLABILITY_ANNOTATIONS
160+
161+
#endif // SWIFT_C_AST_ASTBRIDGING_H

lib/ASTGen/CMakeLists.txt

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
# TODO: why do we need these on Linux?
2-
set(CMAKE_Swift_ARCHIVE_CREATE "<CMAKE_AR> crs <TARGET> <OBJECTS>")
3-
set(CMAKE_Swift_ARCHIVE_FINISH "")
4-
51
if (SWIFT_SWIFT_PARSER)
6-
add_library(ASTGen
7-
Sources/ASTGen/ASTGen.swift
8-
Sources/ASTGen/Decls.swift
9-
Sources/ASTGen/Exprs.swift
10-
Sources/ASTGen/Literals.swift
11-
Sources/ASTGen/Misc.swift
12-
Sources/ASTGen/Stmts.swift)
2+
add_swift_host_library(swiftASTGen STATIC
3+
Sources/ASTGen/ASTGen.swift
4+
Sources/ASTGen/Decls.swift
5+
Sources/ASTGen/Exprs.swift
6+
Sources/ASTGen/Literals.swift
7+
Sources/ASTGen/Misc.swift
8+
Sources/ASTGen/Stmts.swift
9+
)
1310

14-
target_link_libraries(ASTGen PUBLIC
15-
SwiftSyntax
16-
SwiftParser
17-
SwiftDiagnostics)
11+
# Link against the SwiftSyntax parser and libraries it depends on. The actual
12+
# formulation of this is a hack to work around a CMake bug in Ninja file
13+
# generation that results in multiple Ninja targets producing the same file in
14+
# a downstream SourceKit target. This should be expressed as:
15+
#
16+
# target_link_libraries(swiftASTGen
17+
# PRIVATE
18+
# SwiftSyntax::SwiftCompilerSupport
19+
# )
20+
target_link_libraries(swiftASTGen
21+
PRIVATE
22+
$<TARGET_OBJECTS:SwiftSyntax::SwiftBasicFormat>
23+
$<TARGET_OBJECTS:SwiftSyntax::SwiftParser>
24+
$<TARGET_OBJECTS:SwiftSyntax::SwiftDiagnostics>
25+
$<TARGET_OBJECTS:SwiftSyntax::SwiftSyntax>
26+
$<TARGET_OBJECTS:SwiftSyntax::SwiftOperators>
27+
$<TARGET_OBJECTS:SwiftSyntax::SwiftCompilerSupport>
28+
)
1829

19-
target_link_directories(ASTGen PUBLIC
20-
"${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib")
30+
target_include_directories(swiftASTGen PUBLIC
31+
"${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/swift")
2132

22-
target_include_directories(ASTGen PUBLIC
23-
"${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/swift")
24-
else()
25-
add_library(ASTGen
26-
Sources/ASTGen/DummyASTGen.swift)
33+
add_dependencies(swiftASTGen swiftAST)
2734
endif()
28-
29-
set_target_properties(ASTGen PROPERTIES LINKER_LANGUAGE Swift)
30-
31-
target_compile_options(ASTGen PUBLIC
32-
"-emit-module-interface"
33-
"-g")
34-
35-
add_dependencies(ASTGen swiftAST)

lib/ASTGen/Sources/ASTGen/DummyASTGen.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/Parse/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if (SWIFT_SWIFT_PARSER)
4545
# target_link_libraries(swiftParse
4646
# PRIVATE
4747
# SwiftSyntax::SwiftCompilerSupport
48+
# ...
4849
# )
4950
target_link_libraries(swiftParse
5051
PRIVATE
@@ -54,6 +55,7 @@ if (SWIFT_SWIFT_PARSER)
5455
$<TARGET_OBJECTS:SwiftSyntax::SwiftSyntax>
5556
$<TARGET_OBJECTS:SwiftSyntax::SwiftOperators>
5657
$<TARGET_OBJECTS:SwiftSyntax::SwiftCompilerSupport>
58+
$<TARGET_OBJECTS:swiftASTGen>
5759
)
5860

5961
target_include_directories(swiftParse
@@ -67,7 +69,6 @@ if (SWIFT_SWIFT_PARSER)
6769
)
6870
endif()
6971

70-
add_dependencies(swiftParse ASTGen)
7172
add_dependencies(swiftParse swift-parse-syntax-generated-headers)
7273

7374
set_swift_llvm_is_available(swiftParse)

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ macro(add_sourcekit_library name)
251251
add_llvm_symbol_exports(${name} ${EXPORTED_SYMBOL_FILE})
252252
endif()
253253

254+
# Once the new Swift parser is linked, everything has Swift modules.
255+
if (SWIFT_SWIFT_PARSER AND SOURCEKITLIB_SHARED)
256+
set(SOURCEKITLIB_HAS_SWIFT_MODULES ON)
257+
endif()
254258

255259
if(SOURCEKITLIB_SHARED)
256260
set(RPATH_LIST)
@@ -329,6 +333,16 @@ macro(add_sourcekit_executable name)
329333

330334
set_target_properties(${name} PROPERTIES FOLDER "SourceKit executables")
331335
add_sourcekit_default_compiler_flags("${name}")
336+
337+
if(SWIFT_SWIFT_PARSER)
338+
set(SKEXEC_HAS_SWIFT_MODULES TRUE)
339+
else()
340+
set(SKEXEC_HAS_SWIFT_MODULES FALSE)
341+
endif()
342+
343+
set(RPATH_LIST)
344+
add_sourcekit_swift_runtime_link_flags(${name} "../../../.." ${SKEXEC_HAS_SWIFT_MODULES})
345+
332346
endmacro()
333347

334348
# Add a new SourceKit framework.

tools/driver/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ if(${BOOTSTRAPPING_MODE} MATCHES "BOOTSTRAPPING.*")
1414
)
1515
target_link_libraries(swift-frontend-bootstrapping0
1616
PRIVATE
17-
ASTGen
1817
swiftCore
1918
swiftDriverTool
2019
swiftCompilerStub)
@@ -35,7 +34,6 @@ if(${BOOTSTRAPPING_MODE} MATCHES "BOOTSTRAPPING.*")
3534
)
3635
target_link_libraries(swift-frontend-bootstrapping1
3736
PRIVATE
38-
ASTGen
3937
swiftCore
4038
swiftDriverTool
4139
swiftCompilerModules-bootstrapping1)
@@ -53,7 +51,6 @@ add_swift_host_tool(swift-frontend
5351
)
5452
target_link_libraries(swift-frontend
5553
PUBLIC
56-
ASTGen
5754
swiftCore
5855
swiftDriverTool
5956
swiftCompilerModules)

0 commit comments

Comments
 (0)