Skip to content
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
28 changes: 24 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ project(SwiftSyntax LANGUAGES C Swift)
set(SWIFT_VERSION 5)
set(CMAKE_Swift_LANGUAGE_VERSION ${SWIFT_VERSION})

set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
# The subdirectory into which host libraries will be installed.
set(SWIFT_HOST_LIBRARIES_SUBDIRECTORY "swift/host")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")

set(CMAKE_MACOSX_RPATH YES)

include(AddSwiftHostLibrary)

# Ensure that we do not link the _StringProcessing module. But we can
# only pass this flag for new-enough compilers that support it.
file(WRITE "${CMAKE_BINARY_DIR}/tmp/empty-check-string-processing.swift" "")
Expand All @@ -42,6 +44,24 @@ if (NOT SWIFT_SUPPORTS_DISABLE_IMPLICIT_STRING_PROCESSING_MODULE_IMPORT)
$<$<COMPILE_LANGUAGE:Swift>:-disable-implicit-string-processing-module-import>)
endif()

# Determine the module triple.
# FIXME: This is a hack. It's all a hack. Windows isn't setting
# CMAKE_Swift_COMPILER_TARGET.
if(CMAKE_Swift_COMPILER_TARGET)
string(REGEX REPLACE "macosx[0-9]+([.][0-9]+)?" "macos" SWIFT_MODULE_TRIPLE
${CMAKE_Swift_COMPILER_TARGET})
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
set(SWIFT_MODULE_TRIPLE "x86_64-unknown-windows-msvc")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
set(SWIFT_MODULE_TRIPLE "aarch64-unknown-windows-msvc")
else()
message(FATAL_ERROR "Unrecognized architecture for Windows host")
endif()
endif()

message(STATUS "Module triple: ${SWIFT_MODULE_TRIPLE}")

# Force single-threaded-only syntax trees to eliminate the Darwin
# dependency in the compiler.
add_compile_definitions(
Expand Down
14 changes: 1 addition & 13 deletions Sources/IDEUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,11 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_library(IDEUtils STATIC
add_swift_host_library(IDEUtils
gyb_generated/SyntaxClassification.swift
Syntax+Classifications.swift
SyntaxClassifier.swift
)

target_link_libraries(IDEUtils PUBLIC
SwiftSyntax)

set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS IDEUtils)

# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(IDEUtils PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

install(TARGETS IDEUtils
EXPORT SwiftSyntaxTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
14 changes: 1 addition & 13 deletions Sources/SwiftBasicFormat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,11 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_library(SwiftBasicFormat STATIC
add_swift_host_library(SwiftBasicFormat
generated/BasicFormat.swift
SyntaxProtocol+Formatted.swift
Trivia+Indented.swift
)

target_link_libraries(SwiftBasicFormat PUBLIC
SwiftSyntax)

set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftBasicFormat)

# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(SwiftBasicFormat PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

install(TARGETS SwiftBasicFormat
EXPORT SwiftSyntaxTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
15 changes: 1 addition & 14 deletions Sources/SwiftCompilerSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_library(SwiftCompilerSupport STATIC
add_swift_host_library(SwiftCompilerSupport
ConsistencyCheck.swift
)

Expand All @@ -17,16 +17,3 @@ target_link_libraries(SwiftCompilerSupport PUBLIC
SwiftParserDiagnostics
SwiftOperators
)

set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftCompilerSupport)

# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(SwiftCompilerSupport PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_Swift_MODULE_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}")

install(TARGETS SwiftCompilerSupport
EXPORT SwiftSyntaxTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
14 changes: 1 addition & 13 deletions Sources/SwiftDiagnostics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_library(SwiftDiagnostics STATIC
add_swift_host_library(SwiftDiagnostics
Diagnostic.swift
DiagnosticsFormatter.swift
FixIt.swift
Expand All @@ -16,15 +16,3 @@ add_library(SwiftDiagnostics STATIC

target_link_libraries(SwiftDiagnostics PUBLIC
SwiftSyntax)

set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftDiagnostics)

# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(SwiftDiagnostics PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

install(TARGETS SwiftDiagnostics
EXPORT SwiftSyntaxTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
15 changes: 1 addition & 14 deletions Sources/SwiftOperators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_library(SwiftOperators STATIC
add_swift_host_library(SwiftOperators
Operator.swift
OperatorError+Diagnostics.swift
OperatorError.swift
Expand All @@ -23,16 +23,3 @@ target_link_libraries(SwiftOperators PUBLIC
SwiftSyntax
SwiftDiagnostics
SwiftParser)

set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftOperators)

# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(SwiftOperators PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_Swift_MODULE_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}")

install(TARGETS SwiftOperators
EXPORT SwiftSyntaxTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
15 changes: 1 addition & 14 deletions Sources/SwiftParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_library(SwiftParser STATIC
add_swift_host_library(SwiftParser
Attributes.swift
Availability.swift
CharacterInfo.swift
Expand Down Expand Up @@ -40,16 +40,3 @@ add_library(SwiftParser STATIC
target_link_libraries(SwiftParser PUBLIC
SwiftSyntax
SwiftDiagnostics)

set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftParser)

# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(SwiftParser PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_Swift_MODULE_DIRECTORY}")

install(TARGETS SwiftParser
EXPORT SwiftSyntaxTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
15 changes: 1 addition & 14 deletions Sources/SwiftParserDiagnostics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_library(SwiftParserDiagnostics STATIC
add_swift_host_library(SwiftParserDiagnostics
DiagnosticExtensions.swift
MissingNodesError.swift
ParserDiagnosticMessages.swift
Expand All @@ -20,16 +20,3 @@ target_link_libraries(SwiftParserDiagnostics PUBLIC
SwiftDiagnostics
SwiftParser
SwiftSyntax)

set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftParserDiagnostics)

# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(SwiftParserDiagnostics PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_Swift_MODULE_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}")

install(TARGETS SwiftParserDiagnostics
EXPORT SwiftSyntaxTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
14 changes: 1 addition & 13 deletions Sources/SwiftSyntax/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_library(SwiftSyntax STATIC
add_swift_host_library(SwiftSyntax
AbsolutePosition.swift
BumpPtrAllocator.swift
CommonAncestor.swift
Expand Down Expand Up @@ -54,15 +54,3 @@ add_library(SwiftSyntax STATIC
gyb_generated/syntax_nodes/SyntaxStmtNodes.swift
gyb_generated/syntax_nodes/SyntaxTypeNodes.swift
)

set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftSyntax)

# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(SwiftSyntax PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

install(TARGETS SwiftSyntax
EXPORT SwiftSyntaxTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
15 changes: 1 addition & 14 deletions Sources/SwiftSyntaxBuilder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_library(SwiftSyntaxBuilder STATIC
add_swift_host_library(SwiftSyntaxBuilder
ConvenienceInitializers.swift
HasTrailingComma.swift
Indenter.swift
Expand All @@ -29,16 +29,3 @@ target_link_libraries(SwiftSyntaxBuilder PUBLIC
SwiftParserDiagnostics
SwiftSyntax
)

set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftSyntaxBuilder)

# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(SwiftSyntaxBuilder PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_Swift_MODULE_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}")

install(TARGETS SwiftSyntaxBuilder
EXPORT SwiftSyntaxTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
15 changes: 1 addition & 14 deletions Sources/_SwiftSyntaxMacros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_library(_SwiftSyntaxMacros STATIC
add_swift_host_library(_SwiftSyntaxMacros
ExpressionMacro.swift
Macro.swift
MacroEvaluationContext.swift
Expand All @@ -21,16 +21,3 @@ target_link_libraries(_SwiftSyntaxMacros PUBLIC
SwiftParser
SwiftSyntaxBuilder
)

set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS _SwiftSyntaxMacros)

# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(_SwiftSyntaxMacros PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_Swift_MODULE_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}")

install(TARGETS _SwiftSyntaxMacros
EXPORT SwiftSyntaxTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
65 changes: 65 additions & 0 deletions cmake/modules/AddSwiftHostLibrary.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

# Add a new host library with the given name.
function(add_swift_host_library name)
set(ASHL_SOURCES ${ARGN})

# Create the library target.
add_library(${name} ${ASHL_SOURCES})

# Add this to the list of exported targets.
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS ${name})

# Determine where Swift modules will be built and installed.
set(module_dir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(module_base "${module_dir}/${name}.swiftmodule")
set(module_file "${module_base}/${SWIFT_MODULE_TRIPLE}.swiftmodule")
set(module_interface_file "${module_base}/${SWIFT_MODULE_TRIPLE}.swiftinterface")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don’t use module_interface_file anywhere. Is that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a vestige of the failed attempt to enable library evolution. There's a potential miscompile in the very old Swift on CI.

set(module_sourceinfo_file "${module_base}/${SWIFT_MODULE_TRIPLE}.swiftsourceinfo")

# Add a custom target to create the module directory.
add_custom_command(
TARGET ${name}
PRE_BUILD
COMMAND "${CMAKE_COMMAND}" -E make_directory ${module_base}
COMMENT "Generating module directory for ${name}")

# Install the Swift module into the appropriate location.
set_target_properties(${name}
PROPERTIES Swift_MODULE_DIRECTORY ${module_base}
)

# Configure the emission of the Swift module files.
target_compile_options("${name}" PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:
-module-name;${name};
-emit-module-path;${module_file};
-emit-module-source-info-path;${module_sourceinfo_file}
>)

# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(${name} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${module_dir}
)

# Install this target
install(TARGETS ${name}
EXPORT SwiftSyntaxTargets
ARCHIVE DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
LIBRARY DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
RUNTIME DESTINATION bin
)

# Install the module files.
install(
DIRECTORY ${module_base}
DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
FILES_MATCHING PATTERN "*.swift*"
)
endfunction()