Skip to content

Commit

Permalink
Windows: Match UCRT Version from build environment if possible.
Browse files Browse the repository at this point in the history
Signed-off-by: Vassil Vassilev <vvasilev@cern.ch>
  • Loading branch information
marsupial authored and sftnight committed Oct 18, 2016
1 parent 3acc9e5 commit 182954b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion include/cling/Utils/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ inline namespace windows {
///
/// \param [out] Path - Path to VisualStudio
/// \param [out] WindSDK - Store the path to the Windows SDK here
/// \param [out] UniversalSDK - Store the path to the Universal SDK here
/// \param [in/out] UniversalSDK - Universal SDK version to match, or empty to
/// match the highest version. On ouput the path to the Universal SDK.
/// \param [in] Verbose - Log progress
///
bool GetVisualStudioDirs(std::string& Path,
Expand Down
5 changes: 3 additions & 2 deletions lib/Interpreter/CIFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ namespace {
}

// When built with access to the proper Windows APIs, try to actually find
// the correct include paths first.
std::string VSDir, WinSDK, UnivSDK;
// the correct include paths first. Init for UnivSDK.empty check below.
std::string VSDir, WinSDK,
UnivSDK(opts.NoBuiltinInc ? "" : CLING_UCRT_VERSION);
if (platform::GetVisualStudioDirs(VSDir,
opts.NoBuiltinInc ? nullptr : &WinSDK,
opts.NoBuiltinInc ? nullptr : &UnivSDK,
Expand Down
1 change: 1 addition & 0 deletions lib/Interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ else()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in
"
#define CLING_INCLUDE_PATHS \"${CLING_INCLUDE_PATHS}\"
#define CLING_UCRT_VERSION \"$ENV{UCRTVersion}\"
")
endif()

Expand Down
22 changes: 13 additions & 9 deletions lib/Utils/PlatformWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ static bool getVisualStudioVer(int VSVersion, std::string& Path,
// So we compare entry names lexicographically to find the greatest one.
static bool getWindows10SDKVersion(std::string& SDKPath,
std::string& SDKVersion) {
SDKVersion.clear();
// Save input SDKVersion to match, and clear SDKVersion for > comparsion
std::string UcrtCompiledVers;
UcrtCompiledVers.swap(SDKVersion);

std::error_code EC;
llvm::SmallString<MAX_PATHC> IncludePath(SDKPath);
Expand All @@ -205,15 +207,15 @@ static bool getWindows10SDKVersion(std::string& SDKPath,
DirIt != DirEnd && !EC; DirIt.increment(EC)) {
if (!llvm::sys::fs::is_directory(DirIt->path()))
continue;
llvm::StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
// If WDK is installed, there could be subfolders like "wdf" in the
// "Include" directory.
// Allow only directories which names start with "10.".
if (!CandidateName.startswith("10."))
continue;
if (CandidateName > SDKVersion) {
llvm::StringRef Candidate = llvm::sys::path::filename(DirIt->path());
// There could be subfolders like "wdf" in the "Include" directory, so only
// test names that start with "10." or match input.
const bool Match = Candidate == UcrtCompiledVers;
if (Match || (Candidate.startswith("10.") && Candidate > SDKVersion)) {
SDKPath = DirIt->path();
SDKVersion = CandidateName;
Candidate.str().swap(SDKVersion);
if (Match)
return true;
}
}
return !SDKVersion.empty();
Expand Down Expand Up @@ -392,7 +394,9 @@ bool GetVisualStudioDirs(std::string& Path, std::string* WinSDK,
}

if (UniversalSDK) {
// On input UniversalSDK is the best version to match
std::string UCRTVersion;
UniversalSDK->swap(UCRTVersion);
if (!getUniversalCRTSdkDir(*UniversalSDK, UCRTVersion)) {
UniversalSDK->clear();
if (Verbose)
Expand Down

0 comments on commit 182954b

Please sign in to comment.