@@ -89,14 +89,27 @@ function(add_swift_compiler_modules_library name)
89
89
90
90
if (SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS )
91
91
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} " )
93
94
if (${BOOTSTRAPPING_MODE} STREQUAL "CROSSCOMPILE-WITH-HOSTLIBS" )
94
95
# Let the cross-compiled compile don't pick up the compiled stdlib by providing
95
96
# an (almost) empty resource dir.
96
97
# The compiler will instead pick up the stdlib from the SDK.
97
98
get_filename_component (swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY )
98
99
set (sdk_option ${sdk_option} "-resource-dir" "${swift_exec_bin_dir} /../bootstrapping0/lib/swift" )
99
100
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 ()
100
113
elseif (${BOOTSTRAPPING_MODE} STREQUAL "CROSSCOMPILE" )
101
114
set (sdk_option "-sdk" "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _ARCH_${SWIFT_HOST_VARIANT_ARCH} _PATH}" )
102
115
get_filename_component (swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY )
0 commit comments