Skip to content

Commit c70d8fd

Browse files
authored
Merge pull request #59050 from apple/egorzhdan/libstdcxx-sysroot
[cxx-interop] Pass sysroot to the Clang driver when detecting libstdc++ path
2 parents b79797e + 07aec92 commit c70d8fd

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,12 +885,23 @@ getClangInvocationFileMapping(ASTContext &ctx) {
885885
if (triple.isAndroid())
886886
return {};
887887

888+
// Extract the libstdc++ installation path from Clang driver.
888889
auto clangDiags = clang::CompilerInstance::createDiagnostics(
889890
new clang::DiagnosticOptions());
890891
clang::driver::Driver clangDriver(ctx.ClangImporterOpts.clangPath,
891892
triple.str(), *clangDiags);
893+
llvm::opt::InputArgList clangDriverArgs;
894+
// If an SDK path was explicitly passed to Swift, make sure to pass it to
895+
// Clang driver as well. It affects the resulting include paths.
896+
auto sdkPath = ctx.SearchPathOpts.getSDKPath();
897+
if (!sdkPath.empty()) {
898+
unsigned argIndex = clangDriverArgs.MakeIndex("--sysroot", sdkPath);
899+
clangDriverArgs.append(new llvm::opt::Arg(
900+
clangDriver.getOpts().getOption(clang::driver::options::OPT__sysroot),
901+
sdkPath, argIndex));
902+
}
892903
auto cxxStdlibDirs =
893-
clangDriver.getLibStdCxxIncludePaths(llvm::opt::InputArgList(), triple);
904+
clangDriver.getLibStdCxxIncludePaths(clangDriverArgs, triple);
894905
if (cxxStdlibDirs.empty()) {
895906
ctx.Diags.diagnose(SourceLoc(), diag::libstdcxx_not_found, triple.str());
896907
return {};

0 commit comments

Comments
 (0)