@@ -89,14 +89,27 @@ function(add_swift_compiler_modules_library name)
8989
9090 if (SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
9191 set (deployment_version "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _DEPLOYMENT_VERSION}" )
92- set (sdk_option "-sdk" "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _ARCH_${SWIFT_HOST_VARIANT_ARCH} _PATH}" )
92+ set (sdk_path "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _ARCH_${SWIFT_HOST_VARIANT_ARCH} _PATH}" )
93+ set (sdk_option "-sdk" "${sdk_path} " )
9394 if (${BOOTSTRAPPING_MODE} STREQUAL "CROSSCOMPILE-WITH-HOSTLIBS" )
9495 # Let the cross-compiled compile don't pick up the compiled stdlib by providing
9596 # an (almost) empty resource dir.
9697 # The compiler will instead pick up the stdlib from the SDK.
9798 get_filename_component (swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY )
9899 set (sdk_option ${sdk_option} "-resource-dir" "${swift_exec_bin_dir} /../bootstrapping0/lib/swift" )
99100 endif ()
101+ if (NOT EXISTS "${sdk_path} /usr/include/c++" )
102+ # Darwin SDKs in Xcode 12 or older do not include libc++, which prevents clang from finding libc++ when invoked
103+ # from ClangImporter. This results in build errors. To workaround this, let's explicitly pass the path to libc++
104+ # to clang.
105+ message (WARNING "Building with an outdated Darwin SDK: libc++ missing from the ${SWIFT_HOST_VARIANT_SDK} SDK. Will use libc++ from the toolchain." )
106+ get_filename_component (absolute_libcxx_path "${CMAKE_C_COMPILER} /../../include/c++/v1" REALPATH)
107+ if (EXISTS "${absolute_libcxx_path} " )
108+ set (sdk_option ${sdk_option} "-Xcc" "-isystem" "-Xcc" "${absolute_libcxx_path} " )
109+ else ()
110+ message (ERROR "libc++ not found in the toolchain." )
111+ endif ()
112+ endif ()
100113 elseif (${BOOTSTRAPPING_MODE} STREQUAL "CROSSCOMPILE" )
101114 set (sdk_option "-sdk" "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _ARCH_${SWIFT_HOST_VARIANT_ARCH} _PATH}" )
102115 get_filename_component (swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY )
@@ -212,6 +225,10 @@ else()
212225 list (APPEND b0_deps swiftDarwin-bootstrapping0)
213226 list (APPEND b1_deps swiftDarwin-bootstrapping1)
214227 endif ()
228+ if (${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_LIBSTDCXX_PLATFORMS)
229+ list (APPEND b0_deps copy-libstdcxx-modulemap-bootstrapping0 copy-libstdcxx-header-bootstrapping0)
230+ list (APPEND b1_deps copy-libstdcxx-modulemap-bootstrapping1 copy-libstdcxx-header-bootstrapping1)
231+ endif ()
215232 endif ()
216233 if (SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
217234 set (platform ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _LIB_SUBDIR})
@@ -252,22 +269,23 @@ else()
252269endif ()
253270
254271# Configure 'SwiftCompilerModules' SwiftPM package. The 'Package.swift' will
255- # be created at '${build_dir}/SwiftCompilerSources /Package.swift' and can be
256- # built with 'swift-build'.
272+ # be created at '${build_dir}/SwiftCompilerModulesPackage /Package.swift' and can
273+ # be built with 'swift-build'.
257274# Note that this SwiftPM package itself is just for development purposes, and
258275# is not actually used for the compiler building.
259- set (swiftcompiler_source_dir_name "_Sources" )
276+ set (swiftcompiler_modules_package_directory
277+ "${SWIFT_BINARY_DIR} /SwiftCompilerModulesPackage" )
260278configure_file (Package.swift.in
261- "${CMAKE_CURRENT_BINARY_DIR } /Package.swift" @ONLY)
279+ "${swiftcompiler_modules_package_directory } /Package.swift" @ONLY)
262280# SwiftPM requires all sources are inside the directory of 'Package.swift'.
263281# Create symlinks to the actual source directories.
264282execute_process (COMMAND
265283 "${CMAKE_COMMAND} " -E create_symlink
266284 "${CMAKE_CURRENT_SOURCE_DIR} /Sources"
267- "${CMAKE_CURRENT_BINARY_DIR} / ${swiftcompiler_source_dir_name} " )
285+ "${swiftcompiler_modules_package_directory} /Sources " )
268286if (SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
269287 execute_process (COMMAND
270288 "${CMAKE_COMMAND} " -E create_symlink
271289 "${EXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR} /Sources/_RegexParser"
272- "${CMAKE_CURRENT_BINARY_DIR } /_RegexParser_Sources" )
290+ "${swiftcompiler_modules_package_directory } /_RegexParser_Sources" )
273291endif ()
0 commit comments