Skip to content

Commit 5786cbd

Browse files
committed
[Macros] Make the compiler frontend depend on the macro plugin libraries
The dependency of the Observation library on the observation macro plugin introduces a direct dependency of a target library on a host library, (lib -> stdlib) that we'd like to avoid. Instead, make the Swift frontend binary depend on the macro plugin libraries that we build, so that it's the complete host-side stack.
1 parent 6b0a0b6 commit 5786cbd

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

lib/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,26 @@ if (SWIFT_SWIFT_PARSER)
8383
list(TRANSFORM SWIFT_SYNTAX_MODULES APPEND ".swiftmodule"
8484
OUTPUT_VARIABLE SWIFT_SYNTAX_MODULE_DIRS)
8585
foreach(module_dir ${SWIFT_SYNTAX_MODULE_DIRS})
86+
# Find all of the source module files.
8687
file(GLOB module_files
8788
"${SWIFT_SYNTAX_LIBRARIES_SOURCE_DIR}/${module_dir}/*.swiftinterface")
89+
90+
# Determine the destination module files.
91+
set(dest_module_files)
92+
foreach(full_module_file ${module_files})
93+
get_filename_component(module_file ${full_module_file} NAME)
94+
list(APPEND dest_module_files
95+
"${SWIFT_HOST_LIBRARIES_DEST_DIR}/${module_dir}/${module_file}")
96+
endforeach()
97+
8898
add_custom_command(
89-
OUTPUT ${module_files}
99+
OUTPUT ${dest_module_files}
90100
COMMAND ${CMAKE_COMMAND} -E make_directory ${SWIFT_HOST_LIBRARIES_DEST_DIR}/${module_dir}
91101
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${module_files} ${SWIFT_HOST_LIBRARIES_DEST_DIR}/${module_dir}/
92102
COMMENT "Copying ${module_dir}"
93103
)
94104

95-
list(APPEND SWIFT_SYNTAX_DEST_FILES ${module_files})
105+
list(APPEND SWIFT_SYNTAX_DEST_FILES ${dest_module_files})
96106
endforeach()
97107

98108
# Add a custom target to copy over the SwiftSyntax build products into

lib/Macros/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ function(add_swift_macro_library name)
4545
ARCHIVE
4646
DESTINATION "${SWIFT_HOST_PLUGINS_DEST_DIR}"
4747
COMPONENT compiler)
48+
49+
# Export this macro plugin target.
50+
set_property(GLOBAL APPEND PROPERTY SWIFT_MACRO_PLUGINS ${name})
4851
endfunction()
4952

5053
add_subdirectory(Sources/ObservationMacros)

stdlib/public/Observation/Sources/Observation/CMakeLists.txt

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,10 @@
1010
#
1111
#===----------------------------------------------------------------------===#
1212

13-
# Linux and windows hosts are disabled for now; it is dependent upon earlyswiftsyntax
14-
# which does not build in the same way just yet
15-
if (${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)
13+
# We can only build when earlyswiftsyntax is enabled.
14+
if (SWIFT_SWIFT_PARSER)
1615
list(APPEND swift_runtime_library_compile_flags -I${SWIFT_SOURCE_DIR}/stdlib/include -I${SWIFT_SOURCE_DIR}/include)
1716

18-
set(SWIFT_OBSERVATION_SWIFT_FLAGS)
19-
set(SWIFT_OBSERVATION_DEPENDS)
20-
21-
list(APPEND SWIFT_OBSERVATION_SWIFT_FLAGS
22-
"-enable-experimental-feature" "Macros"
23-
"-DSWIFT_OBSERVATION_MACROS"
24-
)
25-
list(APPEND SWIFT_OBSERVATION_DEPENDS ObservationMacros)
26-
2717
add_swift_target_library(swiftObservation ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
2818
Locking.cpp
2919
Locking.swift
@@ -37,15 +27,11 @@ if (${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)
3727
ThreadLocal.swift
3828
TrackedProperties.swift
3929

40-
DEPENDS ${SWIFT_OBSERVATION_DEPENDS}
41-
4230
SWIFT_COMPILE_FLAGS
4331
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
44-
${SWIFT_OBSERVATION_SWIFT_FLAGS}
4532
SWIFT_MODULE_DEPENDS _Concurrency
4633
INSTALL_IN_COMPONENT stdlib
4734

4835
MACCATALYST_BUILD_FLAVOR "zippered"
4936
)
50-
51-
endif()
37+
endif()

tools/driver/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ function(add_swift_parser_link_libraries target)
77
if(SWIFT_SWIFT_PARSER)
88
target_link_libraries(${target}
99
PRIVATE swiftCore)
10+
11+
get_property(SWIFT_MACRO_PLUGINS GLOBAL PROPERTY SWIFT_MACRO_PLUGINS)
12+
foreach(macrolib ${SWIFT_MACRO_PLUGINS})
13+
add_dependencies(${target} ${macrolib})
14+
endforeach()
1015
endif()
1116
endfunction()
1217

0 commit comments

Comments
 (0)