Skip to content

[SwiftCompilerModules] Link lib_InternalSwiftSyntaxParser to libswift #59209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion SwiftCompilerSources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#
function(add_swift_compiler_module module)
cmake_parse_arguments(ALSM
""
"ADD_TO_SYNTAXPARSE"
""
"DEPENDS;SOURCES"
${ARGN})
Expand All @@ -35,6 +35,7 @@ function(add_swift_compiler_module module)

set_property(TARGET ${target_name} PROPERTY module_name ${module})
set_property(TARGET ${target_name} PROPERTY module_depends ${ALSM_DEPENDS})
set_property(TARGET ${target_name} PROPERTY add_to_syntaxparse ${ALSM_ADD_TO_SYNTAXPARSE})

get_property(modules GLOBAL PROPERTY swift_compiler_modules)
set_property(GLOBAL PROPERTY swift_compiler_modules ${modules} ${module})
Expand Down Expand Up @@ -120,13 +121,16 @@ function(add_swift_compiler_modules_library name)

set(all_obj_files)
set(all_module_targets)
set(syntaxparse_obj_files)
set(syntaxparse_module_targets)
get_property(modules GLOBAL PROPERTY "swift_compiler_modules")
foreach(module ${modules})

set(module_target "SwiftModule${module}")
get_target_property(module ${module_target} "module_name")
get_target_property(sources ${module_target} SOURCES)
get_target_property(dependencies ${module_target} "module_depends")
get_target_property(add_to_syntaxparse ${module_target} "add_to_syntaxparse")
set(deps, "")
if (dependencies)
foreach(dep_module ${dependencies})
Expand All @@ -146,6 +150,9 @@ function(add_swift_compiler_modules_library name)
set_property(TARGET ${module_target} PROPERTY "module_file" "${module_file}")

set(all_obj_files ${all_obj_files} ${module_obj_file})
if (add_to_syntaxparse)
set(syntaxparse_obj_files ${syntaxparse_obj_files} ${module_obj_file})
endif()

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

set("${module}_dep_target" ${dep_target})
set(all_module_targets ${all_module_targets} ${dep_target})
if (add_to_syntaxparse)
set(syntaxparse_module_targets ${syntaxparse_module_targets} ${dep_target})
endif()
endforeach()

# Create a static library containing all module object files.
Expand All @@ -181,6 +191,15 @@ function(add_swift_compiler_modules_library name)
add_dependencies(${name} ${all_module_targets})
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE CXX)
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${name})

if (XCODE)
set(syntaxparse_obj_files force_lib.c ${syntaxparse_obj_files})
endif()
add_library("${name}_SwiftSyntax" STATIC ${syntaxparse_obj_files})
add_dependencies("${name}_SwiftSyntax" ${syntaxparse_module_targets})
set_target_properties("${name}_SwiftSyntax" PROPERTIES LINKER_LANGUAGE CXX)
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS "${name}_SwiftSyntax")

endfunction()


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

add_library(swiftCompilerModules ALIAS swiftCompilerStub)
add_library(swiftCompilerModules_SwiftSyntax ALIAS swiftCompilerStub)

else()
# Note: "Swift" is not added intentionally here, because it would break
Expand Down
1 change: 1 addition & 0 deletions SwiftCompilerSources/Sources/AST/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_swift_compiler_module(AST
ADD_TO_SYNTAXPARSE
DEPENDS
Basic
SOURCES
Expand Down
6 changes: 4 additions & 2 deletions SwiftCompilerSources/Sources/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_swift_compiler_module(Basic
SourceLoc.swift
Utils.swift)
ADD_TO_SYNTAXPARSE
SOURCES
SourceLoc.swift
Utils.swift)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Parse
public func initializeSwiftModules() {
registerSILClasses()
registerSwiftPasses()
registerRegexParser()
initializeSwiftParseModules()
}

private func registerPass(
Expand Down
2 changes: 2 additions & 0 deletions SwiftCompilerSources/Sources/Parse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ endif()
add_swift_compiler_module(Parse
DEPENDS
${dependencies}
ADD_TO_SYNTAXPARSE
SOURCES
Parse.swift
Regex.swift)
16 changes: 16 additions & 0 deletions SwiftCompilerSources/Sources/Parse/Parse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===--- Parse.swift - SourceLoc bridiging utilities ------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

@_cdecl("initializeSwiftParseModules")
public func initializeSwiftParseModules() {
registerRegexParser()
}
4 changes: 2 additions & 2 deletions SwiftCompilerSources/Sources/Parse/Regex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Basic
#if canImport(_CompilerRegexParser)
@_spi(CompilerInterface) import _CompilerRegexParser

public func registerRegexParser() {
func registerRegexParser() {
Parser_registerRegexLiteralParsingFn(_RegexLiteralParsingFn)
Parser_registerRegexLiteralLexingFn(_RegexLiteralLexingFn)
}
Expand Down Expand Up @@ -122,6 +122,6 @@ public func _RegexLiteralParsingFn(
#else // canImport(_CompilerRegexParser)

#warning("Regex parsing is disabled")
public func registerRegexParser() {}
func registerRegexParser() {}

#endif // canImport(_CompilerRegexParser)
2 changes: 2 additions & 0 deletions SwiftCompilerSources/Sources/_RegexParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ endforeach()
message(STATUS "Using Experimental String Processing library for libswift _RegexParser (${EXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR}).")

add_swift_compiler_module(_CompilerRegexParser
ADD_TO_SYNTAXPARSE
SOURCES
"${LIBSWIFT_REGEX_PARSER_SOURCES}")
3 changes: 2 additions & 1 deletion SwiftCompilerSources/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
extern "C" {

void initializeSwiftModules();
void initializeSwiftParseModules();

}

void initializeSwiftModules() {}

void initializeSwiftParseModules() {}
Loading