Skip to content

Commit 630545f

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 468371f commit 630545f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/Frontend/CompilerInvocation.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,7 @@ static bool validateSwiftModuleFileArgumentAndAdd(const std::string &swiftModule
21242124

21252125
static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
21262126
DiagnosticEngine &Diags,
2127+
const llvm::Triple &Triple,
21272128
const CASOptions &CASOpts,
21282129
const FrontendOptions &FrontendOpts,
21292130
StringRef workingDirectory) {
@@ -2258,6 +2259,18 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
22582259

22592260
if (const Arg *A = Args.getLastArg(OPT_resource_dir))
22602261
Opts.RuntimeResourcePath = A->getValue();
2262+
else if (!Triple.isOSDarwin() && Args.hasArg(OPT_sdk)) {
2263+
llvm::SmallString<128> SDKResourcePath(Opts.getSDKPath());
2264+
llvm::sys::path::append(
2265+
SDKResourcePath, "usr", "lib",
2266+
FrontendOpts.UseSharedResourceFolder ? "swift" : "swift_static",
2267+
getPlatformNameForTriple(Triple));
2268+
// Check for eg <sdkRoot>/usr/lib/swift/linux/
2269+
if (llvm::sys::fs::exists(SDKResourcePath)) {
2270+
llvm::sys::path::remove_filename(SDKResourcePath); // Remove <os> name
2271+
Opts.RuntimeResourcePath = SDKResourcePath.str();
2272+
}
2273+
}
22612274

22622275
Opts.SkipRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdimport);
22632276
Opts.ExcludeSDKPathsFromRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdlibimport);
@@ -3847,7 +3860,7 @@ bool CompilerInvocation::parseArgs(
38473860

38483861
ParseSymbolGraphArgs(SymbolGraphOpts, ParsedArgs, Diags, LangOpts);
38493862

3850-
if (ParseSearchPathArgs(SearchPathOpts, ParsedArgs, Diags,
3863+
if (ParseSearchPathArgs(SearchPathOpts, ParsedArgs, Diags, LangOpts.Target,
38513864
CASOpts, FrontendOpts, workingDirectory)) {
38523865
return true;
38533866
}

0 commit comments

Comments
 (0)