diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index a32c529832bec..5438376242de5 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -753,23 +753,11 @@ void importer::getNormalInvocationArguments( invocationArgStrs.push_back("-fapinotes-swift-version=" + languageVersion.asAPINotesVersionString()); - // Prefer `-sdk` paths. - if (!searchPathOpts.getSDKPath().empty()) { - llvm::SmallString<261> path{searchPathOpts.getSDKPath()}; - llvm::sys::path::append(path, "usr", "lib", "swift", "apinotes"); - - invocationArgStrs.push_back("-iapinotes-modules"); - invocationArgStrs.push_back(path.str().str()); - } - - // Fallback to "legacy" `-resource-dir` paths. - { llvm::SmallString<261> path{searchPathOpts.RuntimeResourcePath}; llvm::sys::path::append(path, "apinotes"); invocationArgStrs.push_back("-iapinotes-modules"); invocationArgStrs.push_back(path.str().str()); - } } static void diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index d3681b51d1614..bc8cfc49ca8cf 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2166,6 +2166,7 @@ static bool validateSwiftModuleFileArgumentAndAdd(const std::string &swiftModule static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args, DiagnosticEngine &Diags, + const llvm::Triple &Triple, const CASOptions &CASOpts, const FrontendOptions &FrontendOpts, StringRef workingDirectory) { @@ -2300,6 +2301,22 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args, if (const Arg *A = Args.getLastArg(OPT_resource_dir)) Opts.RuntimeResourcePath = A->getValue(); + else if (!Triple.isOSDarwin() && Args.hasArg(OPT_sdk)) { + llvm::SmallString<128> SDKResourcePath(Opts.getSDKPath()); + llvm::sys::path::append( + SDKResourcePath, "usr", "lib", + FrontendOpts.UseSharedResourceFolder ? "swift" : "swift_static"); + // Check for eg /usr/lib/swift/ + if (llvm::sys::fs::exists(SDKResourcePath)) + Opts.RuntimeResourcePath = SDKResourcePath.str(); + else { + llvm::outs() << "You passed in an external -sdk without a Swift runtime.\n"; + llvm::outs() << "Either specify a directory containing the runtime libraries with\n"; + llvm::outs() << "the -resource-dir flag, or use -sysroot instead to point at a C/C++\n"; + llvm::outs() << "sysroot alone. Falling back to << Opts.RuntimeResourcePath << for\n"; + llvm::outs() << "the Swift runtime modules and libraries.\n"; + } + } Opts.SkipRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdimport); Opts.ExcludeSDKPathsFromRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdlibimport); @@ -3908,7 +3925,7 @@ bool CompilerInvocation::parseArgs( ParseSymbolGraphArgs(SymbolGraphOpts, ParsedArgs, Diags, LangOpts); - if (ParseSearchPathArgs(SearchPathOpts, ParsedArgs, Diags, + if (ParseSearchPathArgs(SearchPathOpts, ParsedArgs, Diags, LangOpts.Target, CASOpts, FrontendOpts, workingDirectory)) { return true; }