@@ -42,21 +42,35 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
4242 setRuntimeResourcePath (LibPath.str ());
4343}
4444
45- static void updateRuntimeLibraryPath (SearchPathOptions &SearchPathOpts,
46- llvm::Triple &Triple) {
45+ static void updateRuntimeLibraryPaths (SearchPathOptions &SearchPathOpts,
46+ llvm::Triple &Triple) {
4747 llvm::SmallString<128 > LibPath (SearchPathOpts.RuntimeResourcePath );
4848
4949 llvm::sys::path::append (LibPath, getPlatformNameForTriple (Triple));
5050 SearchPathOpts.RuntimeLibraryPath = LibPath.str ();
5151
52+ // Set up the import paths containing the swiftmodules for the libraries in
53+ // RuntimeLibraryPath.
54+ SearchPathOpts.RuntimeLibraryImportPaths .clear ();
55+
56+ // If this is set, we don't want any runtime import paths.
57+ if (SearchPathOpts.SkipRuntimeLibraryImportPaths )
58+ return ;
59+
5260 if (!Triple.isOSDarwin ())
5361 llvm::sys::path::append (LibPath, swift::getMajorArchitectureName (Triple));
54- SearchPathOpts.RuntimeLibraryImportPath = LibPath.str ();
62+ SearchPathOpts.RuntimeLibraryImportPaths .push_back (LibPath.str ());
63+
64+ if (!SearchPathOpts.SDKPath .empty ()) {
65+ LibPath = SearchPathOpts.SDKPath ;
66+ llvm::sys::path::append (LibPath, " usr" , " lib" , " swift" );
67+ SearchPathOpts.RuntimeLibraryImportPaths .push_back (LibPath.str ());
68+ }
5569}
5670
5771void CompilerInvocation::setRuntimeResourcePath (StringRef Path) {
5872 SearchPathOpts.RuntimeResourcePath = Path;
59- updateRuntimeLibraryPath (SearchPathOpts, LangOpts.Target );
73+ updateRuntimeLibraryPaths (SearchPathOpts, LangOpts.Target );
6074}
6175
6276void CompilerInvocation::setTargetTriple (StringRef Triple) {
@@ -65,7 +79,12 @@ void CompilerInvocation::setTargetTriple(StringRef Triple) {
6579
6680void CompilerInvocation::setTargetTriple (const llvm::Triple &Triple) {
6781 LangOpts.setTarget (Triple);
68- updateRuntimeLibraryPath (SearchPathOpts, LangOpts.Target );
82+ updateRuntimeLibraryPaths (SearchPathOpts, LangOpts.Target );
83+ }
84+
85+ void CompilerInvocation::setSDKPath (const std::string &Path) {
86+ SearchPathOpts.SDKPath = Path;
87+ updateRuntimeLibraryPaths (SearchPathOpts, LangOpts.Target );
6988}
7089
7190SourceFileKind CompilerInvocation::getSourceFileKind () const {
@@ -562,7 +581,7 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts,
562581 if (const Arg *A = Args.getLastArg (OPT_resource_dir))
563582 Opts.RuntimeResourcePath = A->getValue ();
564583
565- Opts.SkipRuntimeLibraryImportPath |= Args.hasArg (OPT_nostdimport);
584+ Opts.SkipRuntimeLibraryImportPaths |= Args.hasArg (OPT_nostdimport);
566585
567586 // Opts.RuntimeIncludePath is set by calls to
568587 // setRuntimeIncludePath() or setMainExecutablePath().
@@ -1279,7 +1298,7 @@ bool CompilerInvocation::parseArgs(
12791298 return true ;
12801299 }
12811300
1282- updateRuntimeLibraryPath (SearchPathOpts, LangOpts.Target );
1301+ updateRuntimeLibraryPaths (SearchPathOpts, LangOpts.Target );
12831302
12841303 return false ;
12851304}
0 commit comments