[PATCH] D45504: [MinGW] Look for a cross sysroot relative to the clang binary

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 18 01:50:56 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL330244: [MinGW] Look for a cross sysroot relative to the clang binary (authored by mstorsjo, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45504?vs=141909&id=142897#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45504

Files:
  cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
  cfe/trunk/lib/Driver/ToolChains/MinGW.h


Index: cfe/trunk/lib/Driver/ToolChains/MinGW.h
===================================================================
--- cfe/trunk/lib/Driver/ToolChains/MinGW.h
+++ cfe/trunk/lib/Driver/ToolChains/MinGW.h
@@ -96,6 +96,7 @@
   mutable std::unique_ptr<tools::gcc::Compiler> Compiler;
   void findGccLibDir();
   llvm::ErrorOr<std::string> findGcc();
+  llvm::ErrorOr<std::string> findClangRelativeSysroot();
 };
 
 } // end namespace toolchains
Index: cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
===================================================================
--- cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
+++ cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
@@ -275,7 +275,8 @@
   Archs.emplace_back(getTriple().getArchName());
   Archs[0] += "-w64-mingw32";
   Archs.emplace_back("mingw32");
-  Arch = Archs[0].str();
+  if (Arch.empty())
+    Arch = Archs[0].str();
   // lib: Arch Linux, Ubuntu, Windows
   // lib64: openSUSE Linux
   for (StringRef CandidateLib : {"lib", "lib64"}) {
@@ -302,13 +303,35 @@
   return make_error_code(std::errc::no_such_file_or_directory);
 }
 
+llvm::ErrorOr<std::string> toolchains::MinGW::findClangRelativeSysroot() {
+  llvm::SmallVector<llvm::SmallString<32>, 2> Subdirs;
+  Subdirs.emplace_back(getTriple().str());
+  Subdirs.emplace_back(getTriple().getArchName());
+  Subdirs[1] += "-w64-mingw32";
+  Twine ClangRoot =
+      llvm::sys::path::parent_path(getDriver().getInstalledDir()) +
+      llvm::sys::path::get_separator();
+  for (StringRef CandidateSubdir : Subdirs) {
+    Twine Subdir = ClangRoot + CandidateSubdir;
+    if (llvm::sys::fs::is_directory(Subdir)) {
+      Arch = CandidateSubdir;
+      return Subdir.str();
+    }
+  }
+  return make_error_code(std::errc::no_such_file_or_directory);
+}
+
 toolchains::MinGW::MinGW(const Driver &D, const llvm::Triple &Triple,
                          const ArgList &Args)
     : ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args) {
   getProgramPaths().push_back(getDriver().getInstalledDir());
 
   if (getDriver().SysRoot.size())
     Base = getDriver().SysRoot;
+  // Look for <clang-bin>/../<triplet>; if found, use <clang-bin>/.. as the
+  // base as it could still be a base for a gcc setup with libgcc.
+  else if (llvm::ErrorOr<std::string> TargetSubdir = findClangRelativeSysroot())
+    Base = llvm::sys::path::parent_path(TargetSubdir.get());
   else if (llvm::ErrorOr<std::string> GPPName = findGcc())
     Base = llvm::sys::path::parent_path(
         llvm::sys::path::parent_path(GPPName.get()));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45504.142897.patch
Type: text/x-patch
Size: 2517 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180418/3ed41039/attachment-0001.bin>


More information about the cfe-commits mailing list