-
Notifications
You must be signed in to change notification settings - Fork 449
[CMake] Rework build and installation of all swift-syntax modules #1097
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a566bcc
[CMake] Respect `BUILD_SHARED_LIBS` rather than forcing static builds.
DougGregor 8ac6d59
[CMake] Introduce add_swift_host_library and use it for all libraries.
DougGregor c35ff05
[CMake] Build modules into a proper ".swiftmodule" directory
DougGregor 07f094b
[CMake] Build modules into lib/swift/host.
DougGregor 2f35ee2
[CMake] Install Swift modules into lib/swift/host.
DougGregor 11f1138
Add missing newline
DougGregor 2f1be83
[CMake] Build with library evolution and generate Swift interfaces.
DougGregor ffdd338
Revert "[CMake] Build with library evolution and generate Swift inter…
DougGregor 0071efe
[CMake] Cope with the lack of CMAKE_Swift_COMPILER_TARGET on Windows
DougGregor c992215
[CMake] Deal with CMAKE_SYSTEM_PROCESSOR not matching module triple arch
DougGregor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.