Skip to content

Commit 04992a5

Browse files
committed
[CMake] Provide a way to build the minimum things necessary for the syntax parser library
These changes allow to optionally perform a very fast build that is targeted to only produce the syntax parser library. Part of addressing rdar://48153331
1 parent 05893a8 commit 04992a5

File tree

5 files changed

+74
-30
lines changed

5 files changed

+74
-30
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ endif()
420420
option(SWIFT_BUILD_SYNTAXPARSERLIB
421421
"Build the Swift Syntax Parser library"
422422
${SWIFT_BUILD_SYNTAXPARSERLIB_default})
423+
option(SWIFT_BUILD_ONLY_SYNTAXPARSERLIB
424+
"Only build the Swift Syntax Parser library" FALSE)
423425
option(SWIFT_BUILD_SOURCEKIT
424426
"Build SourceKit"
425427
${SWIFT_BUILD_SOURCEKIT_default})

lib/AST/ASTPrinter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,10 @@ class PrintAST : public ASTVisitor<PrintAST> {
804804
using ASTVisitor::visit;
805805

806806
bool visit(Decl *D) {
807+
#if SWIFT_BUILD_ONLY_SYNTAXPARSERLIB
808+
return false; // not needed for the parser library.
809+
#endif
810+
807811
if (!shouldPrint(D, true))
808812
return false;
809813

@@ -1479,6 +1483,10 @@ bool ShouldPrintChecker::shouldPrint(const Pattern *P,
14791483

14801484
bool ShouldPrintChecker::shouldPrint(const Decl *D,
14811485
const PrintOptions &Options) {
1486+
#if SWIFT_BUILD_ONLY_SYNTAXPARSERLIB
1487+
return false; // not needed for the parser library.
1488+
#endif
1489+
14821490
if (auto *ED= dyn_cast<ExtensionDecl>(D)) {
14831491
if (Options.printExtensionContentAsMembers(ED))
14841492
return false;

lib/AST/Builtins.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,10 @@ static bool isValidCmpXChgOrdering(StringRef SuccessString,
15271527
}
15281528

15291529
ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
1530+
#if SWIFT_BUILD_ONLY_SYNTAXPARSERLIB
1531+
return nullptr; // not needed for the parser library.
1532+
#endif
1533+
15301534
SmallVector<Type, 4> Types;
15311535
StringRef OperationName = getBuiltinBaseName(Context, Id.str(), Types);
15321536

lib/AST/CMakeLists.txt

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,39 @@ if (SWIFT_FORCE_OPTIMIZED_TYPECHECKER)
33
set(EXTRA_AST_FLAGS "FORCE_BUILD_OPTIMIZED")
44
endif()
55

6+
if(SWIFT_BUILD_ONLY_SYNTAXPARSERLIB)
7+
set(SWIFTAST_INTERFACE_LINK_LIBRARIES)
8+
set(SWIFTAST_LLVM_COMPONENT_DEPENDS)
9+
else()
10+
set(SWIFTAST_INTERFACE_LINK_LIBRARIES
11+
# Clang dependencies.
12+
# FIXME: Clang should really export these in some reasonable manner.
13+
clangCodeGen
14+
clangIndex
15+
clangFormat
16+
clangToolingCore
17+
clangFrontendTool
18+
clangFrontend
19+
clangDriver
20+
clangSerialization
21+
clangParse
22+
clangSema
23+
clangAnalysis
24+
clangEdit
25+
clangRewriteFrontend
26+
clangRewrite
27+
clangAST
28+
clangLex
29+
clangAPINotes
30+
clangBasic
31+
)
32+
set(SWIFTAST_LLVM_COMPONENT_DEPENDS
33+
bitreader bitwriter coroutines coverage irreader debuginfoDWARF
34+
profiledata instrumentation object objcarcopts mc mcparser
35+
bitreader bitwriter lto ipo option core support ${LLVM_TARGETS_TO_BUILD}
36+
)
37+
endif()
38+
639
add_swift_host_library(swiftAST STATIC
740
AccessScopeChecker.cpp
841
AccessRequests.cpp
@@ -65,38 +98,32 @@ add_swift_host_library(swiftAST STATIC
6598
USRGeneration.cpp
6699

67100
INTERFACE_LINK_LIBRARIES
68-
# Clang dependencies.
69-
# FIXME: Clang should really export these in some reasonable manner.
70-
clangCodeGen
71-
clangIndex
72-
clangFormat
73-
clangToolingCore
74-
clangFrontendTool
75-
clangFrontend
76-
clangDriver
77-
clangSerialization
78-
clangParse
79-
clangSema
80-
clangAnalysis
81-
clangEdit
82-
clangRewriteFrontend
83-
clangRewrite
84-
clangAST
85-
clangLex
86-
clangAPINotes
87-
clangBasic
101+
${SWIFTAST_INTERFACE_LINK_LIBRARIES}
88102

89103
LLVM_COMPONENT_DEPENDS
90-
bitreader bitwriter coroutines coverage irreader debuginfoDWARF
91-
profiledata instrumentation object objcarcopts mc mcparser
92-
bitreader bitwriter lto ipo option core support ${LLVM_TARGETS_TO_BUILD}
104+
${SWIFTAST_LLVM_COMPONENT_DEPENDS}
93105

94106
${EXTRA_AST_FLAGS}
95107
)
96-
target_link_libraries(swiftAST PRIVATE
97-
swiftBasic
98-
swiftMarkup
99-
swiftSyntax)
108+
109+
if(SWIFT_BUILD_ONLY_SYNTAXPARSERLIB)
110+
# Add clangBasic as a single direct dependency to avoid bringing along some
111+
# llvm libraries that we don't need.
112+
if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WINDOWS")
113+
set(clangBasicDep "${LLVM_LIBRARY_OUTPUT_INTDIR}/clangBasic.lib")
114+
else()
115+
set(clangBasicDep "${LLVM_LIBRARY_OUTPUT_INTDIR}/libclangBasic.a")
116+
endif()
117+
target_link_libraries(swiftAST PRIVATE
118+
swiftBasic
119+
swiftSyntax
120+
${clangBasicDep})
121+
else()
122+
target_link_libraries(swiftAST PRIVATE
123+
swiftBasic
124+
swiftMarkup
125+
swiftSyntax)
126+
endif()
100127

101128
# intrinsics_gen is the LLVM tablegen target that generates the include files
102129
# where intrinsics and attributes are declared. swiftAST depends on these

lib/Basic/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ add_swift_host_library(swiftBasic STATIC
106106

107107
C_COMPILE_FLAGS ${UUID_INCLUDE}
108108
LLVM_COMPONENT_DEPENDS support)
109-
target_link_libraries(swiftBasic PRIVATE
110-
swiftDemangling
111-
${UUID_LIBRARIES})
109+
110+
if(NOT SWIFT_BUILD_ONLY_SYNTAXPARSERLIB)
111+
target_link_libraries(swiftBasic PRIVATE
112+
swiftDemangling
113+
${UUID_LIBRARIES})
114+
endif()
112115

113116
message(STATUS "Swift version: ${SWIFT_VERSION}")
114117
message(STATUS "Swift vendor: ${SWIFT_VENDOR}")

0 commit comments

Comments
 (0)