From 3e8dc3e2ee6dbb677c14bdf4a3d12868d383d906 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 14 Jan 2025 16:14:03 -0800 Subject: [PATCH 1/2] add $SDK\usr\include as -isystem for non-Windows non-Darwin --- lib/ClangImporter/ClangImporter.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index a1355d880a5f7..14638524f015b 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -701,6 +701,13 @@ void importer::getNormalInvocationArguments( invocationArgStrs.push_back("-isysroot"); invocationArgStrs.push_back(searchPathOpts.getSDKPath().str()); } else { + llvm::SmallString<256> path; + path = searchPathOpts.getSDKPath(); + llvm::sys::path::append(path, "usr", "include"); + + invocationArgStrs.push_back("-isystem"); + invocationArgStrs.push_back(path.str().str()); + if (auto sysroot = searchPathOpts.getSysRoot()) { invocationArgStrs.push_back("--sysroot"); invocationArgStrs.push_back(sysroot->str()); From 6d48d1cbf79dfea139aeee65835181a0b29a0ab4 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 21 Jan 2025 13:29:59 -0800 Subject: [PATCH 2/2] only add sdk include path if both sysroot and sdk are specified --- lib/ClangImporter/ClangImporter.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 14638524f015b..3edabcb5b1a86 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -701,16 +701,17 @@ void importer::getNormalInvocationArguments( invocationArgStrs.push_back("-isysroot"); invocationArgStrs.push_back(searchPathOpts.getSDKPath().str()); } else { - llvm::SmallString<256> path; - path = searchPathOpts.getSDKPath(); - llvm::sys::path::append(path, "usr", "include"); - - invocationArgStrs.push_back("-isystem"); - invocationArgStrs.push_back(path.str().str()); - if (auto sysroot = searchPathOpts.getSysRoot()) { + // Both the sdk path and sysroot are provided. Pass along the sysroot + // to Clang but also ensure the SDK include path is provided. invocationArgStrs.push_back("--sysroot"); invocationArgStrs.push_back(sysroot->str()); + + llvm::SmallString<256> path; + path = searchPathOpts.getSDKPath(); + llvm::sys::path::append(path, "usr", "include"); + invocationArgStrs.push_back("-isystem"); + invocationArgStrs.push_back(path.str().str()); } else { invocationArgStrs.push_back("--sysroot"); invocationArgStrs.push_back(searchPathOpts.getSDKPath().str());