mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CMake] Propagate header changes to pure Swift modules
Changes to the headers imported by Swift files aren't not correctly propagated in CMake/Ninja. So changes to C/C++ headers didn't rebuild ASTGen modules. Move the similar hack from SwiftCompilerSources and use it in ASTGen as well. rdar://120863405
This commit is contained in:
@@ -264,40 +264,6 @@ else()
|
|||||||
|
|
||||||
add_subdirectory(Sources)
|
add_subdirectory(Sources)
|
||||||
|
|
||||||
# TODO: generate this dynamically through the modulemap; this cannot use `sed`
|
|
||||||
# as that is not available on all platforms (e.g. Windows).
|
|
||||||
#
|
|
||||||
# step 1: generate a dummy source file, which just includes all headers
|
|
||||||
# defined in include/swift/module.modulemap
|
|
||||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp.tmp"
|
|
||||||
"
|
|
||||||
#define COMPILED_WITH_SWIFT
|
|
||||||
|
|
||||||
#include \"swift/Basic/BasicBridging.h\"
|
|
||||||
#include \"swift/SIL/SILBridging.h\"
|
|
||||||
#include \"swift/SILOptimizer/OptimizerBridging.h\"
|
|
||||||
")
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp"
|
|
||||||
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp.tmp"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp.tmp"
|
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
# step 2: build a library containing that source file. This library depends on all the included header files.
|
|
||||||
# The swift modules can now depend on that target.
|
|
||||||
# Note that this library is unused, i.e. not linked to anything.
|
|
||||||
add_library(importedHeaderDependencies "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp")
|
|
||||||
|
|
||||||
# When building unified, we need to make sure all the Clang headers are
|
|
||||||
# generated before we try to use them.
|
|
||||||
# When building Swift against an already compiled LLVM/Clang, like
|
|
||||||
# build-script does, this target does not exist, but the headers
|
|
||||||
# are already completely generated at that point.
|
|
||||||
if(TARGET clang-tablegen-targets)
|
|
||||||
add_dependencies(importedHeaderDependencies clang-tablegen-targets)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS|CROSSCOMPILE")
|
if(BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS|CROSSCOMPILE")
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
include(macCatalystUtils)
|
include(macCatalystUtils)
|
||||||
|
|
||||||
# Workaround a cmake bug, see the corresponding function in swift-syntax
|
# Workaround a cmake bug, see the corresponding function in swift-syntax
|
||||||
function(force_target_link_libraries TARGET)
|
function(force_add_dependencies TARGET)
|
||||||
target_link_libraries(${TARGET} ${ARGN})
|
foreach(DEPENDENCY ${ARGN})
|
||||||
|
|
||||||
cmake_parse_arguments(ARGS "PUBLIC;PRIVATE;INTERFACE" "" "" ${ARGN})
|
|
||||||
foreach(DEPENDENCY ${ARGS_UNPARSED_ARGUMENTS})
|
|
||||||
string(REGEX REPLACE [<>:\"/\\|?*] _ sanitized ${DEPENDENCY})
|
string(REGEX REPLACE [<>:\"/\\|?*] _ sanitized ${DEPENDENCY})
|
||||||
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
|
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
|
||||||
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
|
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
|
||||||
@@ -17,6 +14,13 @@ function(force_target_link_libraries TARGET)
|
|||||||
endforeach()
|
endforeach()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(force_target_link_libraries TARGET)
|
||||||
|
target_link_libraries(${TARGET} ${ARGN})
|
||||||
|
|
||||||
|
cmake_parse_arguments(ARGS "PUBLIC;PRIVATE;INTERFACE" "" "" ${ARGN})
|
||||||
|
force_add_dependencies(${TARGET} ${ARGS_UNPARSED_ARGUMENTS})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Add compile options shared between libraries and executables.
|
# Add compile options shared between libraries and executables.
|
||||||
function(_add_host_swift_compile_options name)
|
function(_add_host_swift_compile_options name)
|
||||||
# Avoid introducing an implicit dependency on the string-processing library.
|
# Avoid introducing an implicit dependency on the string-processing library.
|
||||||
@@ -175,6 +179,9 @@ function(add_pure_swift_host_library name)
|
|||||||
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
|
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Depends on all '*.h' files in 'include/module.modulemap'.
|
||||||
|
force_add_dependencies(${name} importedHeaderDependencies)
|
||||||
|
|
||||||
# Workaround to touch the library and its objects so that we don't
|
# Workaround to touch the library and its objects so that we don't
|
||||||
# continually rebuild (again, see corresponding change in swift-syntax).
|
# continually rebuild (again, see corresponding change in swift-syntax).
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
@@ -334,6 +341,9 @@ function(add_pure_swift_host_tool name)
|
|||||||
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
|
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Depends on all '*.h' files in 'include/module.modulemap'.
|
||||||
|
force_add_dependencies(${name} importedHeaderDependencies)
|
||||||
|
|
||||||
# Link against dependencies.
|
# Link against dependencies.
|
||||||
target_link_libraries(${name} PUBLIC
|
target_link_libraries(${name} PUBLIC
|
||||||
${APSHT_DEPENDENCIES}
|
${APSHT_DEPENDENCIES}
|
||||||
|
|||||||
@@ -1 +1,30 @@
|
|||||||
add_subdirectory(swift)
|
add_subdirectory(swift)
|
||||||
|
|
||||||
|
|
||||||
|
# Create a library that depends on all headers defined in include/swift/module.modulemap
|
||||||
|
#
|
||||||
|
# TODO: generate this dynamically through the modulemap; this cannot use `sed`
|
||||||
|
# as that is not available on all platforms (e.g. Windows).
|
||||||
|
file(GENERATE
|
||||||
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp"
|
||||||
|
CONTENT "
|
||||||
|
#define COMPILED_WITH_SWIFT
|
||||||
|
#define SWIFT_TARGET
|
||||||
|
|
||||||
|
#include \"swift/Basic/BasicBridging.h\"
|
||||||
|
#include \"swift/AST/ASTBridging.h\"
|
||||||
|
#include \"swift/IDE/IDEBridging.h\"
|
||||||
|
#include \"swift/Parse/ParseBridging.h\"
|
||||||
|
#include \"swift/SIL/SILBridging.h\"
|
||||||
|
#include \"swift/SILOptimizer/OptimizerBridging.h\"
|
||||||
|
")
|
||||||
|
add_library(importedHeaderDependencies "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp")
|
||||||
|
|
||||||
|
# When building unified, we need to make sure all the Clang headers are
|
||||||
|
# generated before we try to use them.
|
||||||
|
# When building Swift against an already compiled LLVM/Clang, like
|
||||||
|
# build-script does, this target does not exist, but the headers
|
||||||
|
# are already completely generated at that point.
|
||||||
|
if(TARGET clang-tablegen-targets)
|
||||||
|
add_dependencies(importedHeaderDependencies clang-tablegen-targets)
|
||||||
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user