[llvm] 7cca34a - [llvm-rc]: Find <target>-clang over just clang

Tobias Hieta via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 9 00:04:59 PST 2022


Author: Tobias Hieta
Date: 2022-02-09T09:04:53+01:00
New Revision: 7cca34acc4acd9d163ca8b9e585587b8897483b9

URL: https://github.com/llvm/llvm-project/commit/7cca34acc4acd9d163ca8b9e585587b8897483b9
DIFF: https://github.com/llvm/llvm-project/commit/7cca34acc4acd9d163ca8b9e585587b8897483b9.diff

LOG: [llvm-rc]: Find <target>-clang over just clang

This patch makes llvm-rc/windres prefer <target>-clang over
clang when doing it's preprocessing. This is so that we can
have a .cfg file for <target> and configure sysroot and other
important flags.

Config files not picked up with clang --target=<target>
automatically.

We only look for <target>-clang in the same dir as llvm-windres
and not for all PATHs to minimize the change.

Reviewed By: mstorsjo

Differential Revision: https://reviews.llvm.org/D119219

Added: 
    

Modified: 
    llvm/tools/llvm-rc/llvm-rc.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp
index d43994deecc09..b6d2047061349 100644
--- a/llvm/tools/llvm-rc/llvm-rc.cpp
+++ b/llvm/tools/llvm-rc/llvm-rc.cpp
@@ -124,13 +124,14 @@ std::string createTempFile(const Twine &Prefix, StringRef Suffix) {
   return static_cast<std::string>(FileName);
 }
 
-ErrorOr<std::string> findClang(const char *Argv0) {
+ErrorOr<std::string> findClang(const char *Argv0, StringRef Triple) {
   StringRef Parent = llvm::sys::path::parent_path(Argv0);
   ErrorOr<std::string> Path = std::error_code();
+  std::string TargetClang = (Triple + "-clang").str();
   if (!Parent.empty()) {
     // First look for the tool with all potential names in the specific
     // directory of Argv0, if known
-    for (const auto *Name : {"clang", "clang-cl"}) {
+    for (const auto *Name : {TargetClang.c_str(), "clang", "clang-cl"}) {
       Path = sys::findProgramByName(Name, Parent);
       if (Path)
         return Path;
@@ -219,7 +220,7 @@ bool preprocess(StringRef Src, StringRef Dst, const RcOptions &Opts,
   if (Opts.PrintCmdAndExit) {
     Clang = "clang";
   } else {
-    ErrorOr<std::string> ClangOrErr = findClang(Argv0);
+    ErrorOr<std::string> ClangOrErr = findClang(Argv0, Opts.Triple);
     if (ClangOrErr) {
       Clang = *ClangOrErr;
     } else {


        


More information about the llvm-commits mailing list