@@ -68,6 +68,11 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
6868 Path, FrontendOpts.UseSharedResourceFolder , LibPath);
6969 setRuntimeResourcePath (LibPath.str ());
7070
71+ llvm::SmallString<128 > clangPath (Path);
72+ llvm::sys::path::remove_filename (clangPath);
73+ llvm::sys::path::append (clangPath, " clang" );
74+ ClangImporterOpts.clangPath = std::string (clangPath);
75+
7176 llvm::SmallString<128 > DiagnosticDocsPath (Path);
7277 llvm::sys::path::remove_filename (DiagnosticDocsPath); // Remove /swift
7378 llvm::sys::path::remove_filename (DiagnosticDocsPath); // Remove /bin
@@ -990,6 +995,18 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
990995 StringRef workingDirectory) {
991996 using namespace options ;
992997
998+ if (const Arg *a = Args.getLastArg (OPT_tools_directory)) {
999+ // If a custom tools directory is specified, try to find Clang there.
1000+ // This is useful when the Swift executable is located in a different
1001+ // directory than the Clang/LLVM executables, for example, when building
1002+ // the Swift project itself.
1003+ llvm::SmallString<128 > clangPath (a->getValue ());
1004+ llvm::sys::path::append (clangPath, " clang" );
1005+ if (llvm::sys::fs::exists (clangPath)) {
1006+ Opts.clangPath = std::string (clangPath);
1007+ }
1008+ }
1009+
9931010 if (const Arg *A = Args.getLastArg (OPT_module_cache_path)) {
9941011 Opts.ModuleCachePath = A->getValue ();
9951012 }
0 commit comments