Skip to content

Commit 9f4ce61

Browse files
committed
[SwiftCompilerModules] Link lib_InternalSwiftSyntaxParser to libswift
To use _RegexParser from SwiftSyntax. * Create 'libswiftCompilerModules_SwiftSyntax.a' which is a subset of 'libswiftCompilerModules.a' * Link 'lib_InternalSwiftSyntaxParser' to 'libswiftCompilerModules_SwiftSyntax.a' * Factor out swift runtime linking logic in CMake so that dynamic libraries can link to Swift runtime, in addition to executables * Link 'lib_InternalSwiftSyntaxParser' to swift runtime
1 parent c4dd271 commit 9f4ce61

19 files changed

+218
-153
lines changed

Diff for: SwiftCompilerSources/CMakeLists.txt

+21-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717
function(add_swift_compiler_module module)
1818
cmake_parse_arguments(ALSM
19-
""
19+
"ADD_TO_SYNTAXPARSE"
2020
""
2121
"DEPENDS;SOURCES"
2222
${ARGN})
@@ -35,6 +35,7 @@ function(add_swift_compiler_module module)
3535

3636
set_property(TARGET ${target_name} PROPERTY module_name ${module})
3737
set_property(TARGET ${target_name} PROPERTY module_depends ${ALSM_DEPENDS})
38+
set_property(TARGET ${target_name} PROPERTY add_to_syntaxparse ${ALSM_ADD_TO_SYNTAXPARSE})
3839

3940
get_property(modules GLOBAL PROPERTY swift_compiler_modules)
4041
set_property(GLOBAL PROPERTY swift_compiler_modules ${modules} ${module})
@@ -120,13 +121,16 @@ function(add_swift_compiler_modules_library name)
120121

121122
set(all_obj_files)
122123
set(all_module_targets)
124+
set(syntaxparse_obj_files)
125+
set(syntaxparse_module_targets)
123126
get_property(modules GLOBAL PROPERTY "swift_compiler_modules")
124127
foreach(module ${modules})
125128

126129
set(module_target "SwiftModule${module}")
127130
get_target_property(module ${module_target} "module_name")
128131
get_target_property(sources ${module_target} SOURCES)
129132
get_target_property(dependencies ${module_target} "module_depends")
133+
get_target_property(add_to_syntaxparse ${module_target} "add_to_syntaxparse")
130134
set(deps, "")
131135
if (dependencies)
132136
foreach(dep_module ${dependencies})
@@ -146,6 +150,9 @@ function(add_swift_compiler_modules_library name)
146150
set_property(TARGET ${module_target} PROPERTY "module_file" "${module_file}")
147151

148152
set(all_obj_files ${all_obj_files} ${module_obj_file})
153+
if (add_to_syntaxparse)
154+
set(syntaxparse_obj_files ${syntaxparse_obj_files} ${module_obj_file})
155+
endif()
149156

150157
# Compile the module into an object file
151158
add_custom_command_target(dep_target OUTPUT ${module_obj_file}
@@ -168,6 +175,9 @@ function(add_swift_compiler_modules_library name)
168175

169176
set("${module}_dep_target" ${dep_target})
170177
set(all_module_targets ${all_module_targets} ${dep_target})
178+
if (add_to_syntaxparse)
179+
set(syntaxparse_module_targets ${syntaxparse_module_targets} ${dep_target})
180+
endif()
171181
endforeach()
172182

173183
# Create a static library containing all module object files.
@@ -181,6 +191,15 @@ function(add_swift_compiler_modules_library name)
181191
add_dependencies(${name} ${all_module_targets})
182192
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE CXX)
183193
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${name})
194+
195+
if (XCODE)
196+
set(syntaxparse_obj_files force_lib.c ${syntaxparse_obj_files})
197+
endif()
198+
add_library("${name}_SwiftSyntax" STATIC ${syntaxparse_obj_files})
199+
add_dependencies("${name}_SwiftSyntax" ${syntaxparse_module_targets})
200+
set_target_properties("${name}_SwiftSyntax" PROPERTIES LINKER_LANGUAGE CXX)
201+
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS "${name}_SwiftSyntax")
202+
184203
endfunction()
185204

186205

@@ -190,6 +209,7 @@ add_swift_host_library(swiftCompilerStub OBJECT stubs.cpp)
190209
if (NOT BOOTSTRAPPING_MODE)
191210

192211
add_library(swiftCompilerModules ALIAS swiftCompilerStub)
212+
add_library(swiftCompilerModules_SwiftSyntax ALIAS swiftCompilerStub)
193213

194214
else()
195215
# Note: "Swift" is not added intentionally here, because it would break

Diff for: SwiftCompilerSources/Sources/AST/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
add_swift_compiler_module(AST
10+
ADD_TO_SYNTAXPARSE
1011
DEPENDS
1112
Basic
1213
SOURCES

Diff for: SwiftCompilerSources/Sources/Basic/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
add_swift_compiler_module(Basic
10-
SourceLoc.swift
11-
Utils.swift)
10+
ADD_TO_SYNTAXPARSE
11+
SOURCES
12+
SourceLoc.swift
13+
Utils.swift)

Diff for: SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Parse
1818
public func initializeSwiftModules() {
1919
registerSILClasses()
2020
registerSwiftPasses()
21-
registerRegexParser()
21+
initializeSwiftParseModules()
2222
}
2323

2424
private func registerPass(

Diff for: SwiftCompilerSources/Sources/Parse/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ endif()
1414
add_swift_compiler_module(Parse
1515
DEPENDS
1616
${dependencies}
17+
ADD_TO_SYNTAXPARSE
1718
SOURCES
19+
Parse.swift
1820
Regex.swift)

Diff for: SwiftCompilerSources/Sources/Parse/Parse.swift

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===--- Parse.swift - SourceLoc bridiging utilities ------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
@_cdecl("initializeSwiftParseModules")
14+
public func initializeSwiftParseModules() {
15+
registerRegexParser()
16+
}

Diff for: SwiftCompilerSources/Sources/Parse/Regex.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Basic
1717
#if canImport(_CompilerRegexParser)
1818
@_spi(CompilerInterface) import _CompilerRegexParser
1919

20-
public func registerRegexParser() {
20+
func registerRegexParser() {
2121
Parser_registerRegexLiteralParsingFn(_RegexLiteralParsingFn)
2222
Parser_registerRegexLiteralLexingFn(_RegexLiteralLexingFn)
2323
}
@@ -122,6 +122,6 @@ public func _RegexLiteralParsingFn(
122122
#else // canImport(_CompilerRegexParser)
123123

124124
#warning("Regex parsing is disabled")
125-
public func registerRegexParser() {}
125+
func registerRegexParser() {}
126126

127127
#endif // canImport(_CompilerRegexParser)

Diff for: SwiftCompilerSources/Sources/_RegexParser/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ endforeach()
1616
message(STATUS "Using Experimental String Processing library for libswift _RegexParser (${EXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR}).")
1717

1818
add_swift_compiler_module(_CompilerRegexParser
19+
ADD_TO_SYNTAXPARSE
20+
SOURCES
1921
"${LIBSWIFT_REGEX_PARSER_SOURCES}")

Diff for: SwiftCompilerSources/stubs.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
extern "C" {
1414

1515
void initializeSwiftModules();
16+
void initializeSwiftParseModules();
1617

1718
}
1819

1920
void initializeSwiftModules() {}
20-
21+
void initializeSwiftParseModules() {}

0 commit comments

Comments
 (0)