Skip to content

Commit 45979fa

Browse files
committed
ClangImporter: expand -sdk appropriately on Windows
The MSVC environment does not have a `-isysroot` or `-sysroot` equivalent. Instead, manually expand the sysroot to the path as a prefix to `/usr/include` and treat the path as a system include directory. This fixes a number of tests which use `-sdk` on Windows.
1 parent 9bff13e commit 45979fa

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,21 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
563563
invocationArgStrs.push_back("-Xclang");
564564
invocationArgStrs.push_back("-nostdsysteminc");
565565
} else {
566-
// On Darwin, Clang uses -isysroot to specify the include
567-
// system root. On other targets, it seems to use --sysroot.
568-
if (triple.isOSDarwin()) {
569-
invocationArgStrs.push_back("-isysroot");
566+
if (triple.isWindowsMSVCEnvironment()) {
567+
llvm::SmallString<261> path; // MAX_PATH + 1
568+
path = searchPathOpts.SDKPath;
569+
llvm::sys::path::append(path, "usr", "include");
570+
llvm::sys::path::native(path);
571+
572+
invocationArgStrs.push_back("-isystem");
573+
invocationArgStrs.push_back(path.str());
570574
} else {
571-
invocationArgStrs.push_back("--sysroot");
575+
// On Darwin, Clang uses -isysroot to specify the include
576+
// system root. On other targets, it seems to use --sysroot.
577+
invocationArgStrs.push_back(triple.isOSDarwin() ? "-isysroot"
578+
: "--sysroot");
579+
invocationArgStrs.push_back(searchPathOpts.SDKPath);
572580
}
573-
invocationArgStrs.push_back(searchPathOpts.SDKPath);
574581
}
575582

576583
const std::string &moduleCachePath = importerOpts.ModuleCachePath;

0 commit comments

Comments
 (0)