Skip to content

Commit ac2fa0e

Browse files
committed
Create and export libswiftIdentifier
1 parent 61ec6f9 commit ac2fa0e

File tree

3 files changed

+91
-29
lines changed

3 files changed

+91
-29
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ message("Using Clang_CONFIG: ${LLVM_CONFIG}")
1010
message("Using Swift_CONFIG: ${Clang_CONFIG}")
1111

1212
add_executable(codeql-swift-artifacts empty.cpp)
13-
target_link_libraries(codeql-swift-artifacts PRIVATE LLVMSupport swiftPluggableObserverDriverTool swiftCompilerModules)
13+
target_link_libraries(codeql-swift-artifacts PRIVATE LLVMSupport swiftFrontendTool swiftCompilerModules)
1414

1515
if(APPLE)
1616
execute_process(

patches/swift/04-allow-plugging-in-observer.patch

Lines changed: 80 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake
2+
index 6d93e52f1d5..9ab79aeb9d6 100644
3+
--- a/cmake/modules/AddSwift.cmake
4+
+++ b/cmake/modules/AddSwift.cmake
5+
@@ -715,6 +715,7 @@ function(add_swift_host_tool executable)
6+
7+
# Include the abi stable system stdlib in our rpath.
8+
list(APPEND RPATH_LIST "/usr/lib/swift")
9+
+ list(APPEND RPATH_LIST "${SWIFTLIB_DIR}")
10+
11+
elseif(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE-WITH-HOSTLIBS")
12+
13+
@@ -731,6 +732,7 @@ function(add_swift_host_tool executable)
14+
15+
# Include the abi stable system stdlib in our rpath.
16+
list(APPEND RPATH_LIST "/usr/lib/swift")
17+
+ list(APPEND RPATH_LIST "@executable_path/../lib")
18+
19+
elseif(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING-WITH-HOSTLIBS")
20+
# Add the SDK directory for the host platform.
21+
@@ -798,7 +800,7 @@ function(add_swift_host_tool executable)
22+
if(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
23+
set_target_properties(${executable} PROPERTIES
24+
BUILD_WITH_INSTALL_RPATH YES
25+
- INSTALL_RPATH "${host_lib_dir}")
26+
+ INSTALL_RPATH "${host_lib_dir};$ORIGIN/../lib")
27+
else()
28+
set_target_properties(${executable} PROPERTIES
29+
BUILD_WITH_INSTALL_RPATH YES
130
diff --git a/include/swift/DriverTool/FrontendObserver.h b/include/swift/DriverTool/FrontendObserver.h
231
new file mode 100644
332
index 00000000000..4ac9b299a13
@@ -28,49 +57,68 @@ index 184e6196918..ef5c3eafe69 100644
2857
// TODO: maybe enhance this interface to hear about IRGen and LLVM
2958
// progress.
3059
};
60+
diff --git a/lib/AST/CMakeLists.txt b/lib/AST/CMakeLists.txt
61+
index ec3fa2c853b..9bf73c9b2fc 100644
62+
--- a/lib/AST/CMakeLists.txt
63+
+++ b/lib/AST/CMakeLists.txt
64+
@@ -58,7 +58,6 @@ add_swift_host_library(swiftAST STATIC
65+
GenericParamList.cpp
66+
GenericSignature.cpp
67+
GenericSignatureBuilder.cpp
68+
- Identifier.cpp
69+
ImportCache.cpp
70+
IndexSubset.cpp
71+
InlinableText.cpp
72+
@@ -122,6 +121,10 @@ add_swift_host_library(swiftAST STATIC
73+
${SWIFTAST_LLVM_LINK_COMPONENTS}
74+
)
75+
76+
+add_swift_host_library(swiftIdentifier SHARED
77+
+ Identifier.cpp
78+
+ )
79+
+
80+
if(SWIFT_FORCE_OPTIMIZED_TYPECHECKER)
81+
if(CMAKE_CXX_COMPILER_ID STREQUAL MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL MSVC)
82+
target_compile_options(swiftAST PRIVATE /O2 /Ob2)
83+
@@ -152,7 +155,7 @@ if(NOT SWIFT_BUILD_ONLY_SYNTAXPARSERLIB)
84+
endif()
85+
86+
target_link_libraries(swiftAST
87+
- PUBLIC swiftBasic
88+
+ PUBLIC swiftBasic swiftIdentifier
89+
PRIVATE swiftSyntax)
90+
if(SWIFT_BUILD_ONLY_SYNTAXPARSERLIB)
91+
# Remove dependencies from clangBasic to avoid bringing along some llvm
3192
diff --git a/lib/DriverTool/CMakeLists.txt b/lib/DriverTool/CMakeLists.txt
32-
index 869c00fece9..8787598e2bf 100644
93+
index 869c00fece9..21610d8eb95 100644
3394
--- a/lib/DriverTool/CMakeLists.txt
3495
+++ b/lib/DriverTool/CMakeLists.txt
35-
@@ -9,21 +9,34 @@ set(driver_sources_and_options
36-
37-
set(driver_common_libs
38-
swiftAPIDigester
39-
+ swiftCompilerModules
40-
swiftDriver
41-
swiftFrontendTool
96+
@@ -14,16 +14,24 @@ set(driver_common_libs
4297
swiftSymbolGraphGen
4398
LLVMBitstreamReader)
4499

45-
-add_swift_host_library(swiftDriverTool STATIC
46-
+add_swift_host_library(swiftFrontendObserver STATIC
100+
+add_swift_host_library(swiftFrontendObserver SHARED
47101
+ swift_frontend_observer.cpp)
48102
+target_link_libraries(swiftFrontendObserver
49103
+ PUBLIC
50104
+ swiftFrontendTool)
51105
+
52-
+add_swift_host_library(swiftPluggableObserverDriverTool STATIC
106+
add_swift_host_library(swiftDriverTool STATIC
53107
${driver_sources_and_options}
54108
)
55-
-target_link_libraries(swiftDriverTool
56-
+target_link_libraries(swiftPluggableObserverDriverTool
109+
target_link_libraries(swiftDriverTool
57110
PUBLIC
58-
${driver_common_libs})
111+
- ${driver_common_libs})
112+
+ ${driver_common_libs}
113+
+ swiftFrontendObserver)
59114

60-
+add_library(swiftDriverTool INTERFACE)
61-
+target_link_libraries(swiftDriverTool INTERFACE
62-
+ swiftPluggableObserverDriverTool
63-
+ swiftFrontendObserver)
64-
+
65115
# If building as part of clang, make sure the headers are installed.
66116
if(NOT SWIFT_BUILT_STANDALONE)
67-
- add_dependencies(swiftDriverTool clang-resource-headers)
68-
+ add_dependencies(swiftPluggableObserverDriverTool clang-resource-headers)
117+
add_dependencies(swiftDriverTool clang-resource-headers)
69118
endif()
70119

71-
-set_swift_llvm_is_available(swiftDriverTool)
72120
+set_swift_llvm_is_available(swiftFrontendObserver)
73-
+set_swift_llvm_is_available(swiftPluggableObserverDriverTool)
121+
set_swift_llvm_is_available(swiftDriverTool)
74122
diff --git a/lib/DriverTool/driver.cpp b/lib/DriverTool/driver.cpp
75123
index f71e2de9eae..a500e30827f 100644
76124
--- a/lib/DriverTool/driver.cpp
@@ -151,3 +199,12 @@ index 811fb912f8a..afa2034aa71 100644
151199
void FrontendObserver::performedSILGeneration(SILModule &module) {}
152200
void FrontendObserver::performedSILProcessing(SILModule &module) {}
153201
+void FrontendObserver::finished(int status) {}
202+
diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt
203+
index a5dc3ccb845..30667ae51f9 100644
204+
--- a/tools/driver/CMakeLists.txt
205+
+++ b/tools/driver/CMakeLists.txt
206+
@@ -123,4 +123,3 @@ add_dependencies(editor-integration swift-frontend)
207+
swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-indent${CMAKE_EXECUTABLE_SUFFIX}"
208+
DESTINATION "bin"
209+
COMPONENT editor-integration)
210+
-

pkg_swift_llvm.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,14 @@ def export_stdlibs(exported_dir, swift_build_tree):
154154
'libswiftCompatibility51.a',
155155
'libswiftCompatibilityConcurrency.a',
156156
'libswiftCompatibilityDynamicReplacements.a']
157+
stdlibs = [lib_dir / lib for lib in stdlibs]
158+
stdlibs += [swift_build_tree / 'lib' / f'libswiftIdentifier.{ext}']
157159
for stdlib in stdlibs:
158-
lib_path = lib_dir / stdlib
159-
if lib_path.exists():
160-
print(f'Copying {stdlib}')
161-
shutil.copy(lib_path, exported_dir)
160+
if stdlib.exists():
161+
print(f'Copying {stdlib.name}')
162+
shutil.copy(stdlib, exported_dir)
162163
else:
163-
print(f'Skipping {stdlib}')
164+
print(f'Skipping {stdlib.name}')
164165

165166

166167
def export_libs(exported_dir, libs, swift_build_tree):
@@ -185,6 +186,9 @@ def export_headers(exported_dir, swift_source_tree, llvm_build_tree, swift_build
185186
for h in header_dirs:
186187
copy_includes(h, exported_dir)
187188

189+
def export_frontend(exported_dir, swift_build_tree):
190+
print("exporting swift-frontend")
191+
shutil.copy(swift_build_tree / 'bin' / 'swift-frontend', exported_dir)
188192

189193
def zip_dir(src, tgt):
190194
tgt = get_tgt(tgt, f"swift-prebuilt-{get_platform()}.zip")
@@ -206,6 +210,7 @@ def main(opts):
206210
export_libs(exported, libs, opts.swift_build_tree)
207211
export_headers(exported, opts.swift_source_tree, opts.llvm_build_tree, opts.swift_build_tree)
208212
export_sdk(exported / "sdk", opts.swift_source_tree, opts.swift_build_tree)
213+
export_frontend(exported, opts.swift_build_tree)
209214
zip_dir(exported, opts.output)
210215

211216

0 commit comments

Comments
 (0)