Skip to content

Commit bbf58b9

Browse files
committed
Have the frontend and new swift-driver look in an external -sdk for non-Darwin platform runtime libraries and modules too
as done originally in #25990 with the legacy C++ Driver, but since lost in the new swift-driver
1 parent a866f5d commit bbf58b9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,7 @@ static bool validateSwiftModuleFileArgumentAndAdd(const std::string &swiftModule
21662166

21672167
static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
21682168
DiagnosticEngine &Diags,
2169+
const llvm::Triple &Triple,
21692170
const CASOptions &CASOpts,
21702171
const FrontendOptions &FrontendOpts,
21712172
StringRef workingDirectory) {
@@ -2300,6 +2301,18 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
23002301

23012302
if (const Arg *A = Args.getLastArg(OPT_resource_dir))
23022303
Opts.RuntimeResourcePath = A->getValue();
2304+
else if (!Triple.isOSDarwin() && Args.hasArg(OPT_sdk)) {
2305+
llvm::SmallString<128> SDKResourcePath(Opts.getSDKPath());
2306+
llvm::sys::path::append(
2307+
SDKResourcePath, "usr", "lib",
2308+
FrontendOpts.UseSharedResourceFolder ? "swift" : "swift_static",
2309+
getPlatformNameForTriple(Triple));
2310+
// Check for eg <sdkRoot>/usr/lib/swift/linux/
2311+
if (llvm::sys::fs::exists(SDKResourcePath)) {
2312+
llvm::sys::path::remove_filename(SDKResourcePath); // Remove <os> name
2313+
Opts.RuntimeResourcePath = SDKResourcePath.str();
2314+
}
2315+
}
23032316

23042317
Opts.SkipRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdimport);
23052318
Opts.ExcludeSDKPathsFromRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdlibimport);
@@ -3908,7 +3921,7 @@ bool CompilerInvocation::parseArgs(
39083921

39093922
ParseSymbolGraphArgs(SymbolGraphOpts, ParsedArgs, Diags, LangOpts);
39103923

3911-
if (ParseSearchPathArgs(SearchPathOpts, ParsedArgs, Diags,
3924+
if (ParseSearchPathArgs(SearchPathOpts, ParsedArgs, Diags, LangOpts.Target,
39123925
CASOpts, FrontendOpts, workingDirectory)) {
39133926
return true;
39143927
}

0 commit comments

Comments
 (0)