@@ -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 )
0 commit comments