Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
Hi İsmail, It looks like we need a new logic to detect a Windows 10 SDK installation folder. I'll fill the bug about that. Thank you. On 11.09.2015 20:11, İsmail Dönmez wrote: Hi, On Fri, Sep 11, 2015 at 5:03 PM, Igor Kudrin wrote: Hi İsmail, Clang tries to detect pathes automatically only if corresponding environment variables are not set. In your case, you have these variables set, so clang honors them. In the original case no variable was set, I thought you wanted the variables vs script sets when it works. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
Hi, On Fri, Sep 11, 2015 at 5:03 PM, Igor Kudrin wrote: > Hi İsmail, > > Clang tries to detect pathes automatically only if corresponding environment > variables are not set. In your case, you have these variables set, so clang > honors them. In the original case no variable was set, I thought you wanted the variables vs script sets when it works. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
Hi İsmail, Clang tries to detect pathes automatically only if corresponding environment variables are not set. In your case, you have these variables set, so clang honors them. You have only set pathes for VC libraries and Universal CRT, but the kernel32.lib library is shipped with Windows SDKs and probably located at the path like "C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64". On 11.09.2015 19:44, İsmail Dönmez wrote: Hi, C:\Users\ismail\Desktop>set include INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\winrt; C:\Users\ismail\Desktop>set lib LIB=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\lib\um\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\um\x64; LIBPATH=C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64;C:\Program Files (x86)\Windows Kits\10\UnionMetadata;C:\Program Files (x86)\Windows Kits\10\References;C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\1.0.0.0;C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.FoundationContract\1.0.0.0;C:\Program Files (x86)\Windows Kits\10\References\indows.Networking.Connectivity.WwanContract\1.0.0.0;C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs\Microsoft.VCLibs\14.0\References\CommonConfiguration\neutral; C:\Users\ismail\Desktop>clang-cl.exe -### -fms-compatibility-version=19 mandelbrot-mp.cpp clang version 3.8.0 (http://llvm.org/git/clang d2dc884a74b40711955713829e7a09b8ff5ca1bc) (http://llvm.org/git/llvm 595af7ed8595ccf005efb087b5bb7d9a19e50e3b) Target: x86_64-pc-windows-msvc Thread model: posix InstalledDir: C:\Program Files\LLVM\bin "C:\\Program Files\\LLVM\\bin\\clang-cl.exe" "-cc1" "-triple" "x86_64-pc-windows-msvc19.0.0" "-emit-obj" "-mrelax-all" "-disable-free" "-main-file-name" "mandelbrot-mp.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix" "-relaxed-aliasing" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-D_MT" "--dependent-lib=libcmt" "--dependent-lib=oldnames" "-fms-volatile" "-fdiagnostics-format" "msvc" "-momit-leaf-frame-pointer" "-dwarf-column-info" "-resource-dir" "C:\\Program Files\\LLVM\\bin\\..\\lib\\clang\\3.8.0" "-internal-isystem" "C:\\Program Files\\LLVM\\bin\\..\\lib\\clang\\3.8.0\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\INCLUDE" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\ATLMFC\\INCLUDE" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.10240.0\\ucrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6\\include\\um" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.10240.0\\shared" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.10240.0\\um" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.10240.0\\winrt" "-Wall" "-fdeprecated-macro" "-fdebug-compilation-dir" "C:\\Users\\ismail\\Desktop" "-ferror-limit" "19" "-fmessage-length" "100" "-mstackrealign" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19" "-std=c++14" "-fdelayed-template-parsing" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "C:\\Users\\ismail\\AppData\\Local\\Temp\\mandelbrot-mp-d6f68c.obj" "-x" "c++" "mandelbrot-mp.cpp" "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\link.exe" "-out:mandelbrot-mp.exe" "-nologo" "C:\\Users\\ismail\\AppData\\Local\\Temp\\mandelbrot-mp-d6f68c.obj" On Fri, Sep 11, 2015 at 4:42 PM, Igor Kudrin wrote: Please, can you show the output of the following commands: 1) set include 2) set lib 3) clang-cl.exe -### -fms-compatibility-version=19 foo.cpp On 11.09.2015 17:44, İsmail Dönmez wrote: This doesn't seem to work here, VS 2015 on Win 10 x64: C:\Users\ismail\Desktop>clang-cl.exe -fms-compatibility-version=19 foo.cpp LINK : fatal error LNK1104: cannot open file 'kernel32.lib' clang-cl.exe: error: linker command failed with exit code 1104 (use -v to see invocation) Works fine after setting LIB. On Fri, Sep 11, 2015 at 3:11 AM, Reid Kleckner via cfe-commits wrote: This revision was automatically updated to reflect th
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
Hi, C:\Users\ismail\Desktop>set include INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\winrt; C:\Users\ismail\Desktop>set lib LIB=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\lib\um\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\um\x64; LIBPATH=C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64;C:\Program Files (x86)\Windows Kits\10\UnionMetadata;C:\Program Files (x86)\Windows Kits\10\References;C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\1.0.0.0;C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.FoundationContract\1.0.0.0;C:\Program Files (x86)\Windows Kits\10\References\indows.Networking.Connectivity.WwanContract\1.0.0.0;C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs\Microsoft.VCLibs\14.0\References\CommonConfiguration\neutral; C:\Users\ismail\Desktop>clang-cl.exe -### -fms-compatibility-version=19 mandelbrot-mp.cpp clang version 3.8.0 (http://llvm.org/git/clang d2dc884a74b40711955713829e7a09b8ff5ca1bc) (http://llvm.org/git/llvm 595af7ed8595ccf005efb087b5bb7d9a19e50e3b) Target: x86_64-pc-windows-msvc Thread model: posix InstalledDir: C:\Program Files\LLVM\bin "C:\\Program Files\\LLVM\\bin\\clang-cl.exe" "-cc1" "-triple" "x86_64-pc-windows-msvc19.0.0" "-emit-obj" "-mrelax-all" "-disable-free" "-main-file-name" "mandelbrot-mp.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix" "-relaxed-aliasing" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-D_MT" "--dependent-lib=libcmt" "--dependent-lib=oldnames" "-fms-volatile" "-fdiagnostics-format" "msvc" "-momit-leaf-frame-pointer" "-dwarf-column-info" "-resource-dir" "C:\\Program Files\\LLVM\\bin\\..\\lib\\clang\\3.8.0" "-internal-isystem" "C:\\Program Files\\LLVM\\bin\\..\\lib\\clang\\3.8.0\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\INCLUDE" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\ATLMFC\\INCLUDE" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.10240.0\\ucrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6\\include\\um" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.10240.0\\shared" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.10240.0\\um" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.10240.0\\winrt" "-Wall" "-fdeprecated-macro" "-fdebug-compilation-dir" "C:\\Users\\ismail\\Desktop" "-ferror-limit" "19" "-fmessage-length" "100" "-mstackrealign" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19" "-std=c++14" "-fdelayed-template-parsing" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "C:\\Users\\ismail\\AppData\\Local\\Temp\\mandelbrot-mp-d6f68c.obj" "-x" "c++" "mandelbrot-mp.cpp" "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\link.exe" "-out:mandelbrot-mp.exe" "-nologo" "C:\\Users\\ismail\\AppData\\Local\\Temp\\mandelbrot-mp-d6f68c.obj" On Fri, Sep 11, 2015 at 4:42 PM, Igor Kudrin wrote: > Please, can you show the output of the following commands: > > 1) set include > 2) set lib > 3) clang-cl.exe -### -fms-compatibility-version=19 foo.cpp > > > On 11.09.2015 17:44, İsmail Dönmez wrote: >> >> This doesn't seem to work here, VS 2015 on Win 10 x64: >> >> C:\Users\ismail\Desktop>clang-cl.exe -fms-compatibility-version=19 foo.cpp >> LINK : fatal error LNK1104: cannot open file 'kernel32.lib' >> clang-cl.exe: error: linker command failed with exit code 1104 (use -v >> to see invocation) >> >> Works fine after setting LIB. >> >> On Fri, Sep 11, 2015 at 3:11 AM, Reid Kleckner via cfe-commits >> wrote: >>> >>> This revision was automatically updated to reflect the committed changes. >>> Closed by commit rL247362: [Driver] Use UniversalCRT on Windows if >>> available (authored by rnk). >>> >>> Changed prior to commit: >>>http://reviews.llvm.org/D12695?vs=34475&id=34515#toc >>> >>> Repository: >>>rL LLVM >>> >>> http://reviews.llvm.org/D12695 >>> >>> Files: >>>cfe/trunk/lib/Driver/MSVCToolChain.cpp >>>cfe/trunk/lib/Driver/ToolChains.h >>>
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
Please, can you show the output of the following commands: 1) set include 2) set lib 3) clang-cl.exe -### -fms-compatibility-version=19 foo.cpp On 11.09.2015 17:44, İsmail Dönmez wrote: This doesn't seem to work here, VS 2015 on Win 10 x64: C:\Users\ismail\Desktop>clang-cl.exe -fms-compatibility-version=19 foo.cpp LINK : fatal error LNK1104: cannot open file 'kernel32.lib' clang-cl.exe: error: linker command failed with exit code 1104 (use -v to see invocation) Works fine after setting LIB. On Fri, Sep 11, 2015 at 3:11 AM, Reid Kleckner via cfe-commits wrote: This revision was automatically updated to reflect the committed changes. Closed by commit rL247362: [Driver] Use UniversalCRT on Windows if available (authored by rnk). Changed prior to commit: http://reviews.llvm.org/D12695?vs=34475&id=34515#toc Repository: rL LLVM http://reviews.llvm.org/D12695 Files: cfe/trunk/lib/Driver/MSVCToolChain.cpp cfe/trunk/lib/Driver/ToolChains.h cfe/trunk/lib/Driver/Tools.cpp ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
This doesn't seem to work here, VS 2015 on Win 10 x64: C:\Users\ismail\Desktop>clang-cl.exe -fms-compatibility-version=19 foo.cpp LINK : fatal error LNK1104: cannot open file 'kernel32.lib' clang-cl.exe: error: linker command failed with exit code 1104 (use -v to see invocation) Works fine after setting LIB. On Fri, Sep 11, 2015 at 3:11 AM, Reid Kleckner via cfe-commits wrote: > This revision was automatically updated to reflect the committed changes. > Closed by commit rL247362: [Driver] Use UniversalCRT on Windows if available > (authored by rnk). > > Changed prior to commit: > http://reviews.llvm.org/D12695?vs=34475&id=34515#toc > > Repository: > rL LLVM > > http://reviews.llvm.org/D12695 > > Files: > cfe/trunk/lib/Driver/MSVCToolChain.cpp > cfe/trunk/lib/Driver/ToolChains.h > cfe/trunk/lib/Driver/Tools.cpp > > > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
This revision was automatically updated to reflect the committed changes. Closed by commit rL247362: [Driver] Use UniversalCRT on Windows if available (authored by rnk). Changed prior to commit: http://reviews.llvm.org/D12695?vs=34475&id=34515#toc Repository: rL LLVM http://reviews.llvm.org/D12695 Files: cfe/trunk/lib/Driver/MSVCToolChain.cpp cfe/trunk/lib/Driver/ToolChains.h cfe/trunk/lib/Driver/Tools.cpp Index: cfe/trunk/lib/Driver/MSVCToolChain.cpp === --- cfe/trunk/lib/Driver/MSVCToolChain.cpp +++ cfe/trunk/lib/Driver/MSVCToolChain.cpp @@ -205,6 +205,21 @@ #endif // USE_WIN32 } +// Convert LLVM's ArchType +// to the corresponding name of Windows SDK libraries subfolder +static StringRef getWindowsSDKArch(llvm::Triple::ArchType Arch) { + switch (Arch) { + case llvm::Triple::x86: +return "x86"; + case llvm::Triple::x86_64: +return "x64"; + case llvm::Triple::arm: +return "arm"; + default: +return ""; + } +} + /// \brief Get Windows SDK installation directory. bool MSVCToolChain::getWindowsSDKDir(std::string &path, int &major, int &minor) const { @@ -263,26 +278,75 @@ if (!found) return false; -llvm::sys::path::append(libPath, "um"); -switch (getArch()) { -case llvm::Triple::x86: - llvm::sys::path::append(libPath, "x86"); - break; -case llvm::Triple::x86_64: - llvm::sys::path::append(libPath, "x64"); - break; -case llvm::Triple::arm: - llvm::sys::path::append(libPath, "arm"); - break; -default: +const StringRef archName = getWindowsSDKArch(getArch()); +if (archName.empty()) return false; -} +llvm::sys::path::append(libPath, "um", archName); } path = libPath.str(); return true; } +// Check if the Include path of a specified version of Visual Studio contains +// specific header files. If not, they are probably shipped with Universal CRT. +bool clang::driver::toolchains::MSVCToolChain::useUniversalCRT( +std::string &VisualStudioDir) const { + llvm::SmallString<128> TestPath(VisualStudioDir); + llvm::sys::path::append(TestPath, "VC\\include\\stdlib.h"); + + return !llvm::sys::fs::exists(TestPath); +} + +bool MSVCToolChain::getUniversalCRTSdkDir(std::string &Path, + std::string &UCRTVersion) const { + // vcvarsqueryregistry.bat for Visual Studio 2015 queries the registry + // for the specific key "KitsRoot10". So do we. + if (!getSystemRegistryString( + "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots", "KitsRoot10", + Path, nullptr)) +return false; + + UCRTVersion.clear(); + + // Find the most recent version of Universal CRT. + // vcvarsqueryregistry.bat sorts entries in the include directory by names and + // uses the last one of the list. + // So we compare entry names lexicographically to find the greatest one. + std::error_code EC; + llvm::SmallString<128> IncludePath(Path); + llvm::sys::path::append(IncludePath, "Include"); + for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd; + DirIt != DirEnd && !EC; DirIt.increment(EC)) { +if (!llvm::sys::fs::is_directory(DirIt->path())) + continue; +StringRef CandidateName = llvm::sys::path::filename(DirIt->path()); +if (CandidateName > UCRTVersion) + UCRTVersion = CandidateName; + } + + return !UCRTVersion.empty(); +} + +bool MSVCToolChain::getUniversalCRTLibraryPath(std::string &Path) const { + std::string UniversalCRTSdkPath; + std::string UCRTVersion; + + Path.clear(); + if (!getUniversalCRTSdkDir(UniversalCRTSdkPath, UCRTVersion)) +return false; + + StringRef ArchName = getWindowsSDKArch(getArch()); + if (ArchName.empty()) +return false; + + llvm::SmallString<128> LibPath(UniversalCRTSdkPath); + llvm::sys::path::append(LibPath, "Lib", UCRTVersion, "ucrt", ArchName); + + Path = LibPath.str(); + return true; +} + // Get the location to use for Visual Studio binaries. The location priority // is: %VCINSTALLDIR% > %PATH% > newest copy of Visual Studio installed on // system (as reported by the registry). @@ -460,6 +524,17 @@ if (getVisualStudioInstallDir(VSDir)) { AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, VSDir, "VC\\include"); +if (useUniversalCRT(VSDir)) { + std::string UniversalCRTSdkPath; + std::string UCRTVersion; + if (getUniversalCRTSdkDir(UniversalCRTSdkPath, UCRTVersion)) { +llvm::SmallString<128> UCRTIncludePath(UniversalCRTSdkPath); +llvm::sys::path::append(UCRTIncludePath, "Include", UCRTVersion, +"ucrt"); +addSystemInclude(DriverArgs, CC1Args, UCRTIncludePath); + } +} + std::string WindowsSDKDir; int major, minor; if (getWindowsSDKDir(WindowsSDKDir, major, minor)) { Index: cfe/trunk/lib/Driver/ToolChains.h
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
ruiu added a comment. I'm sorry about leave http://reviews.llvm.org/D12604 hanging. I didn't notice that it got a new review message. Don't mind my patch -- please just submit when you got LGTM http://reviews.llvm.org/D12695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
ikudrin updated this revision to Diff 34475. ikudrin added a comment. - Fixed formatting issues. - Normalized VariableNames. - Reworked the useUniversalCRT method to receive a path of Visual Studio. http://reviews.llvm.org/D12695 Files: lib/Driver/MSVCToolChain.cpp lib/Driver/ToolChains.h lib/Driver/Tools.cpp Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -8951,6 +8951,13 @@ } CmdArgs.push_back( Args.MakeArgString(std::string("-libpath:") + LibDir.c_str())); + + if (MSVC.useUniversalCRT(VisualStudioDir)) { +std::string UniversalCRTLibPath; +if (MSVC.getUniversalCRTLibraryPath(UniversalCRTLibPath)) + CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") + + UniversalCRTLibPath.c_str())); + } } std::string WindowsSdkLibPath; Index: lib/Driver/ToolChains.h === --- lib/Driver/ToolChains.h +++ lib/Driver/ToolChains.h @@ -840,6 +840,10 @@ bool getWindowsSDKDir(std::string &path, int &major, int &minor) const; bool getWindowsSDKLibraryPath(std::string &path) const; + /// \brief Check if Universal CRT should be used if available + bool useUniversalCRT(std::string &visualStudioDir) const; + bool getUniversalCRTSdkDir(std::string &path, std::string &ucrtVersion) const; + bool getUniversalCRTLibraryPath(std::string &path) const; bool getVisualStudioInstallDir(std::string &path) const; bool getVisualStudioBinariesFolder(const char *clangProgramPath, std::string &path) const; Index: lib/Driver/MSVCToolChain.cpp === --- lib/Driver/MSVCToolChain.cpp +++ lib/Driver/MSVCToolChain.cpp @@ -205,6 +205,21 @@ #endif // USE_WIN32 } +// Convert LLVM's ArchType +// to the corresponding name of Windows SDK libraries subfolder +static StringRef getWindowsSDKArch(llvm::Triple::ArchType Arch) { + switch (Arch) { + case llvm::Triple::x86: +return "x86"; + case llvm::Triple::x86_64: +return "x64"; + case llvm::Triple::arm: +return "arm"; + default: +return ""; + } +} + /// \brief Get Windows SDK installation directory. bool MSVCToolChain::getWindowsSDKDir(std::string &path, int &major, int &minor) const { @@ -263,26 +278,75 @@ if (!found) return false; -llvm::sys::path::append(libPath, "um"); -switch (getArch()) { -case llvm::Triple::x86: - llvm::sys::path::append(libPath, "x86"); - break; -case llvm::Triple::x86_64: - llvm::sys::path::append(libPath, "x64"); - break; -case llvm::Triple::arm: - llvm::sys::path::append(libPath, "arm"); - break; -default: +const StringRef archName = getWindowsSDKArch(getArch()); +if (archName.empty()) return false; -} +llvm::sys::path::append(libPath, "um", archName); } path = libPath.str(); return true; } +// Check if the Include path of a specified version of Visual Studio contains +// specific header files. If not, they are probably shipped with Universal CRT. +bool clang::driver::toolchains::MSVCToolChain::useUniversalCRT( +std::string &VisualStudioDir) const { + llvm::SmallString<128> TestPath(VisualStudioDir); + llvm::sys::path::append(TestPath, "VC\\include\\stdlib.h"); + + return !llvm::sys::fs::exists(TestPath); +} + +bool MSVCToolChain::getUniversalCRTSdkDir(std::string &Path, + std::string &UCRTVersion) const { + // vcvarsqueryregistry.bat for Visual Studio 2015 queries the registry + // for the specific key "KitsRoot10". So do we. + if (!getSystemRegistryString( + "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots", "KitsRoot10", + Path, nullptr)) +return false; + + UCRTVersion.clear(); + + // Find the most recent version of Universal CRT. + // vcvarsqueryregistry.bat sorts entries in the include directory by names and + // uses the last one of the list. + // So we compare entry names lexicographically to find the greatest one. + std::error_code EC; + llvm::SmallString<128> IncludePath(Path); + llvm::sys::path::append(IncludePath, "Include"); + for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd; + DirIt != DirEnd && !EC; DirIt.increment(EC)) { +if (!llvm::sys::fs::is_directory(DirIt->path())) + continue; +StringRef CandidateName = llvm::sys::path::filename(DirIt->path()); +if (CandidateName > UCRTVersion) + UCRTVersion = CandidateName; + } + + return !UCRTVersion.empty(); +} + +bool MSVCToolChain::getUniversalCRTLibraryPath(std::string &Path) const { + std::string UniversalCRTSdkPath; + std::string UCRTVersion; + + Path.clear(); + if (!getUniversalCRTSdkDir(UniversalCRTSdkPath,
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
ikudrin added a comment. In http://reviews.llvm.org/D12695#243552, @rnk wrote: > There's a bunch of whitespace issues that clang-format can resolve. Thanks! I'll reformat it. > We also have the convention that variables are StudlyCaps, which isn't > followed in a few places. I've tried to follow the style of the source file. Do you think I should force this rule here? > Do you need someone to commit this for you? If so, I can patch this in, test > it manually, and deal with the style stuff if you deal with the VSDir part. I'd really appreciate it. I'll prepare a new version in a few minutes. http://reviews.llvm.org/D12695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
rnk added a comment. There's a bunch of whitespace issues that clang-format can resolve. We also have the convention that variables are StudlyCaps, which isn't followed in a few places. Do you need someone to commit this for you? If so, I can patch this in, test it manually, and deal with the style stuff if you deal with the VSDir part. Comment at: lib/Driver/MSVCToolChain.cpp:293 @@ +292,3 @@ +// specific header files. If not, they are probably shipped with Universal CRT. +bool clang::driver::toolchains::MSVCToolChain::useUniversalCRT() const +{ This should really take VSDir as a parameter instead of recomputing it, since all the callers are already computing it. http://reviews.llvm.org/D12695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
ikudrin marked an inline comment as done. ikudrin added a comment. In http://reviews.llvm.org/D12695#243320, @rnk wrote: > FYI @ruiu is moving this code to LLVM in http://reviews.llvm.org/D12604. Thanks. I think I'll move my changes to the new place when he's finished. http://reviews.llvm.org/D12695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
ikudrin updated this revision to Diff 34465. ikudrin marked an inline comment as done. ikudrin added a comment. Just added more context to the patch. http://reviews.llvm.org/D12695 Files: lib/Driver/MSVCToolChain.cpp lib/Driver/ToolChains.h lib/Driver/Tools.cpp Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -8953,6 +8953,13 @@ Args.MakeArgString(std::string("-libpath:") + LibDir.c_str())); } +if (MSVC.useUniversalCRT()) { + std::string UniversalCRTLibPath; + if (MSVC.getUniversalCRTLibraryPath(UniversalCRTLibPath)) +CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") + + UniversalCRTLibPath.c_str())); +} + std::string WindowsSdkLibPath; if (MSVC.getWindowsSDKLibraryPath(WindowsSdkLibPath)) CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") + Index: lib/Driver/ToolChains.h === --- lib/Driver/ToolChains.h +++ lib/Driver/ToolChains.h @@ -840,6 +840,11 @@ bool getWindowsSDKDir(std::string &path, int &major, int &minor) const; bool getWindowsSDKLibraryPath(std::string &path) const; + /// \brief Check if Universal CRT should be used if available + bool useUniversalCRT() const; + bool getUniversalCRTSdkDir(std::string &path, +std::string &ucrtVersion) const; + bool getUniversalCRTLibraryPath(std::string &path) const; bool getVisualStudioInstallDir(std::string &path) const; bool getVisualStudioBinariesFolder(const char *clangProgramPath, std::string &path) const; Index: lib/Driver/MSVCToolChain.cpp === --- lib/Driver/MSVCToolChain.cpp +++ lib/Driver/MSVCToolChain.cpp @@ -205,6 +205,21 @@ #endif // USE_WIN32 } +// Convert LLVM's ArchType +// to the corresponding name of Windows SDK libraries subfolder +static StringRef getWindowsSDKArch(llvm::Triple::ArchType arch) { + switch (arch) { + case llvm::Triple::x86: +return "x86"; + case llvm::Triple::x86_64: +return "x64"; + case llvm::Triple::arm: +return "arm"; + default: +return ""; + } +} + /// \brief Get Windows SDK installation directory. bool MSVCToolChain::getWindowsSDKDir(std::string &path, int &major, int &minor) const { @@ -263,22 +278,77 @@ if (!found) return false; -llvm::sys::path::append(libPath, "um"); -switch (getArch()) { -case llvm::Triple::x86: - llvm::sys::path::append(libPath, "x86"); - break; -case llvm::Triple::x86_64: - llvm::sys::path::append(libPath, "x64"); - break; -case llvm::Triple::arm: - llvm::sys::path::append(libPath, "arm"); - break; -default: +const StringRef archName = getWindowsSDKArch(getArch()); +if (archName.empty()) return false; -} +llvm::sys::path::append(libPath, "um", archName); + } + + path = libPath.str(); + return true; +} + +// Check if the Include path of a chosen version of Visual Studio contains +// specific header files. If not, they are probably shipped with Universal CRT. +bool clang::driver::toolchains::MSVCToolChain::useUniversalCRT() const +{ + std::string VSDir; + if (!getVisualStudioInstallDir(VSDir)) +return false; + + llvm::SmallString<128> testPath(VSDir); + llvm::sys::path::append(testPath, "VC\\include\\stdlib.h"); + + return !llvm::sys::fs::exists(testPath); +} + +bool MSVCToolChain::getUniversalCRTSdkDir(std::string &path, + std::string &ucrtVersion) const +{ + // vcvarsqueryregistry.bat for Visual Studio 2015 queries the registry + // for the specific key "KitsRoot10". So do we. + if (!getSystemRegistryString( +"SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots", +"KitsRoot10", path, nullptr)) +return false; + + ucrtVersion.clear(); + + // Find the most recent version of Universal CRT. + // vcvarsqueryregistry.bat sorts entries in the include directory by names and + // uses the last one of the list. + // So we compare entry names lexicographically to find the greatest one. + std::error_code ec; + llvm::SmallString<128> includePath(path); + llvm::sys::path::append(includePath, "Include"); + for (llvm::sys::fs::directory_iterator dirIt(includePath, ec), dirEnd; + dirIt != dirEnd && !ec; dirIt.increment(ec)) { +if (!llvm::sys::fs::is_directory(dirIt->path())) + continue; +StringRef name = llvm::sys::path::filename(dirIt->path()); +if (name > ucrtVersion) + ucrtVersion = name; } + return !ucrtVersion.empty(); +} + +bool MSVCToolChain::getUniversalCRTLibraryPath(std::string &path) const +{ + std::string universalCRTSdkPath; + std::string ucrtVersion; + + path.clear(); + if (!getUniversalCRTSdkDir
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
ikudrin updated this revision to Diff 34462. ikudrin added a comment. - Extracted a function to convert an architecture type to a library subfolder name. - Added a method to check if we should use Universal CRT depending on the chosen version of Visual Studio. http://reviews.llvm.org/D12695 Files: lib/Driver/MSVCToolChain.cpp lib/Driver/ToolChains.h lib/Driver/Tools.cpp Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -8953,6 +8953,13 @@ Args.MakeArgString(std::string("-libpath:") + LibDir.c_str())); } +if (MSVC.useUniversalCRT()) { + std::string UniversalCRTLibPath; + if (MSVC.getUniversalCRTLibraryPath(UniversalCRTLibPath)) +CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") + + UniversalCRTLibPath.c_str())); +} + std::string WindowsSdkLibPath; if (MSVC.getWindowsSDKLibraryPath(WindowsSdkLibPath)) CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") + Index: lib/Driver/ToolChains.h === --- lib/Driver/ToolChains.h +++ lib/Driver/ToolChains.h @@ -840,6 +840,11 @@ bool getWindowsSDKDir(std::string &path, int &major, int &minor) const; bool getWindowsSDKLibraryPath(std::string &path) const; + /// \brief Check if Universal CRT should be used if available + bool useUniversalCRT() const; + bool getUniversalCRTSdkDir(std::string &path, +std::string &ucrtVersion) const; + bool getUniversalCRTLibraryPath(std::string &path) const; bool getVisualStudioInstallDir(std::string &path) const; bool getVisualStudioBinariesFolder(const char *clangProgramPath, std::string &path) const; Index: lib/Driver/MSVCToolChain.cpp === --- lib/Driver/MSVCToolChain.cpp +++ lib/Driver/MSVCToolChain.cpp @@ -205,6 +205,21 @@ #endif // USE_WIN32 } +// Convert LLVM's ArchType +// to the corresponding name of Windows SDK libraries subfolder +static StringRef getWindowsSDKArch(llvm::Triple::ArchType arch) { + switch (arch) { + case llvm::Triple::x86: +return "x86"; + case llvm::Triple::x86_64: +return "x64"; + case llvm::Triple::arm: +return "arm"; + default: +return ""; + } +} + /// \brief Get Windows SDK installation directory. bool MSVCToolChain::getWindowsSDKDir(std::string &path, int &major, int &minor) const { @@ -263,22 +278,77 @@ if (!found) return false; -llvm::sys::path::append(libPath, "um"); -switch (getArch()) { -case llvm::Triple::x86: - llvm::sys::path::append(libPath, "x86"); - break; -case llvm::Triple::x86_64: - llvm::sys::path::append(libPath, "x64"); - break; -case llvm::Triple::arm: - llvm::sys::path::append(libPath, "arm"); - break; -default: +const StringRef archName = getWindowsSDKArch(getArch()); +if (archName.empty()) return false; -} +llvm::sys::path::append(libPath, "um", archName); + } + + path = libPath.str(); + return true; +} + +// Check if the Include path of a chosen version of Visual Studio contains +// specific header files. If not, they are probably shipped with Universal CRT. +bool clang::driver::toolchains::MSVCToolChain::useUniversalCRT() const +{ + std::string VSDir; + if (!getVisualStudioInstallDir(VSDir)) +return false; + + llvm::SmallString<128> testPath(VSDir); + llvm::sys::path::append(testPath, "VC\\include\\stdlib.h"); + + return !llvm::sys::fs::exists(testPath); +} + +bool MSVCToolChain::getUniversalCRTSdkDir(std::string &path, + std::string &ucrtVersion) const +{ + // vcvarsqueryregistry.bat for Visual Studio 2015 queries the registry + // for the specific key "KitsRoot10". So do we. + if (!getSystemRegistryString( +"SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots", +"KitsRoot10", path, nullptr)) +return false; + + ucrtVersion.clear(); + + // Find the most recent version of Universal CRT. + // vcvarsqueryregistry.bat sorts entries in the include directory by names and + // uses the last one of the list. + // So we compare entry names lexicographically to find the greatest one. + std::error_code ec; + llvm::SmallString<128> includePath(path); + llvm::sys::path::append(includePath, "Include"); + for (llvm::sys::fs::directory_iterator dirIt(includePath, ec), dirEnd; + dirIt != dirEnd && !ec; dirIt.increment(ec)) { +if (!llvm::sys::fs::is_directory(dirIt->path())) + continue; +StringRef name = llvm::sys::path::filename(dirIt->path()); +if (name > ucrtVersion) + ucrtVersion = name; } + return !ucrtVersion.empty(); +} + +bool MSVCToolChain::getUniversalCRTLibraryPath(std::string &path) const +{
Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
rnk added a subscriber: ruiu. rnk added a comment. FYI @ruiu is moving this code to LLVM in http://reviews.llvm.org/D12604. Comment at: lib/Driver/MSVCToolChain.cpp:328-340 @@ +327,15 @@ + llvm::sys::path::append(libPath, "Lib", ucrtVersion, "ucrt"); + switch (getArch()) { + case llvm::Triple::x86: +llvm::sys::path::append(libPath, "x86"); +break; + case llvm::Triple::x86_64: +llvm::sys::path::append(libPath, "x64"); +break; + case llvm::Triple::arm: +llvm::sys::path::append(libPath, "arm"); +break; + default: +return false; + } + Refactor this into a helper like `StringRef getWindowsSDKArch(llvm::Triple::Arch)` and share it with `getWindowsSDKLibraryPath`. Comment at: lib/Driver/Tools.cpp:8956-8959 @@ -8955,1 +8955,6 @@ +std::string UniversalCRTLibPath; +if (MSVC.getUniversalCRTLibraryPath(UniversalCRTLibPath)) + CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") + + UniversalCRTLibPath.c_str())); + Does this have to be conditional on the version of the CRT in use? If I install VS 2013 and the ucrt and am trying to use the 2013 CRT, this will put both on the libpath. Is that a problem? http://reviews.llvm.org/D12695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D12695: [Driver] Use UniversalCRT on Windows if available
ikudrin created this revision. ikudrin added a subscriber: cfe-commits. With Visual Studio 2015 release, a part of runtime library was extracted and now comes with Windows Kits. This patch enables clang to use Universal CRT library if %INCLUDE or %LIB environment varaibles are not specified. See also https://llvm.org/bugs/show_bug.cgi?id=24741 http://reviews.llvm.org/D12695 Files: lib/Driver/MSVCToolChain.cpp lib/Driver/ToolChains.h lib/Driver/Tools.cpp Index: lib/Driver/Tools.cpp === --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -8953,6 +8953,11 @@ Args.MakeArgString(std::string("-libpath:") + LibDir.c_str())); } +std::string UniversalCRTLibPath; +if (MSVC.getUniversalCRTLibraryPath(UniversalCRTLibPath)) + CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") + + UniversalCRTLibPath.c_str())); + std::string WindowsSdkLibPath; if (MSVC.getWindowsSDKLibraryPath(WindowsSdkLibPath)) CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") + Index: lib/Driver/ToolChains.h === --- lib/Driver/ToolChains.h +++ lib/Driver/ToolChains.h @@ -836,6 +836,9 @@ bool getWindowsSDKDir(std::string &path, int &major, int &minor) const; bool getWindowsSDKLibraryPath(std::string &path) const; + bool getUniversalCRTSdkDir(std::string &path, +std::string &ucrtVersion) const; + bool getUniversalCRTLibraryPath(std::string &path) const; bool getVisualStudioInstallDir(std::string &path) const; bool getVisualStudioBinariesFolder(const char *clangProgramPath, std::string &path) const; Index: lib/Driver/MSVCToolChain.cpp === --- lib/Driver/MSVCToolChain.cpp +++ lib/Driver/MSVCToolChain.cpp @@ -283,6 +283,66 @@ return true; } +bool MSVCToolChain::getUniversalCRTSdkDir(std::string &path, + std::string &ucrtVersion) const +{ + // vcvarsqueryregistry.bat for Visual Studio 2015 queries the registry + // for the specific key "KitsRoot10". So do we. + if (!getSystemRegistryString( +"SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots", +"KitsRoot10", path, nullptr)) +return false; + + ucrtVersion.clear(); + + // Find the most recent version of Universal CRT. + // vcvarsqueryregistry.bat sorts entries in the include directory by names and + // uses the last one of the list. + // So we compare entry names lexicographically to find the greatest one. + std::error_code ec; + llvm::SmallString<128> includePath(path); + llvm::sys::path::append(includePath, "Include"); + for (llvm::sys::fs::directory_iterator dirIt(includePath, ec), dirEnd; + dirIt != dirEnd && !ec; dirIt.increment(ec)) { +if (!llvm::sys::fs::is_directory(dirIt->path())) + continue; +StringRef name = llvm::sys::path::filename(dirIt->path()); +if (name > ucrtVersion) + ucrtVersion = name; + } + + return !ucrtVersion.empty(); +} + +bool MSVCToolChain::getUniversalCRTLibraryPath(std::string &path) const +{ + std::string universalCRTSdkPath; + std::string ucrtVersion; + + path.clear(); + if (!getUniversalCRTSdkDir(universalCRTSdkPath, ucrtVersion)) +return false; + + llvm::SmallString<128> libPath(universalCRTSdkPath); + llvm::sys::path::append(libPath, "Lib", ucrtVersion, "ucrt"); + switch (getArch()) { + case llvm::Triple::x86: +llvm::sys::path::append(libPath, "x86"); +break; + case llvm::Triple::x86_64: +llvm::sys::path::append(libPath, "x64"); +break; + case llvm::Triple::arm: +llvm::sys::path::append(libPath, "arm"); +break; + default: +return false; + } + + path = libPath.str(); + return true; +} + // Get the location to use for Visual Studio binaries. The location priority // is: %VCINSTALLDIR% > %PATH% > newest copy of Visual Studio installed on // system (as reported by the registry). @@ -460,6 +520,14 @@ if (getVisualStudioInstallDir(VSDir)) { AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, VSDir, "VC\\include"); +std::string universalCRTSdkPath; +std::string ucrtVersion; +if (getUniversalCRTSdkDir(universalCRTSdkPath, ucrtVersion)) { + llvm::SmallString<128> ucrtIncludePath(universalCRTSdkPath); + llvm::sys::path::append(ucrtIncludePath, "Include", ucrtVersion, "ucrt"); + addSystemInclude(DriverArgs, CC1Args, ucrtIncludePath); +} + std::string WindowsSDKDir; int major, minor; if (getWindowsSDKDir(WindowsSDKDir, major, minor)) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits