43
43
using namespace swift ;
44
44
using namespace llvm ::opt;
45
45
46
- // / The path for Swift libraries in the OS on Darwin.
47
- #define DARWIN_OS_LIBRARY_PATH " /usr/lib/swift"
48
-
49
46
static constexpr const char *const localeCodes[] = {
50
47
#define SUPPORTED_LOCALE (Code, Language ) #Code,
51
48
#include " swift/AST/LocalizationLanguages.def"
@@ -211,6 +208,12 @@ void CompilerInvocation::setDefaultInProcessPluginServerPathIfNecessary() {
211
208
static void updateRuntimeLibraryPaths (SearchPathOptions &SearchPathOpts,
212
209
const FrontendOptions &FrontendOpts,
213
210
const LangOptions &LangOpts) {
211
+ // If this is set, we don't want any runtime import paths.
212
+ if (SearchPathOpts.SkipAllImportPaths ) {
213
+ SearchPathOpts.setRuntimeLibraryImportPaths ({});
214
+ return ;
215
+ }
216
+
214
217
const llvm::Triple &Triple = LangOpts.Target ;
215
218
llvm::SmallString<128 > LibPath (SearchPathOpts.RuntimeResourcePath );
216
219
@@ -220,44 +223,7 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
220
223
if (LangOpts.hasFeature (Feature::Embedded))
221
224
LibSubDir = " embedded" ;
222
225
223
- SearchPathOpts.RuntimeLibraryPaths .clear ();
224
-
225
- #if defined(_WIN32)
226
- // Resource path looks like this:
227
- //
228
- // C:\...\Swift\Toolchains\6.0.0+Asserts\usr\lib\swift
229
- //
230
- // The runtimes are in
231
- //
232
- // C:\...\Swift\Runtimes\6.0.0\usr\bin
233
- //
234
- llvm::SmallString<128 > RuntimePath (LibPath);
235
-
236
- llvm::sys::path::remove_filename (RuntimePath);
237
- llvm::sys::path::remove_filename (RuntimePath);
238
- llvm::sys::path::remove_filename (RuntimePath);
239
-
240
- llvm::SmallString<128 > VersionWithAttrs (llvm::sys::path::filename (RuntimePath));
241
- size_t MaybePlus = VersionWithAttrs.find_first_of (' +' );
242
- StringRef Version = VersionWithAttrs.substr (0 , MaybePlus);
243
-
244
- llvm::sys::path::remove_filename (RuntimePath);
245
- llvm::sys::path::remove_filename (RuntimePath);
246
- llvm::sys::path::append (RuntimePath, " Runtimes" , Version, " usr" , " bin" );
247
-
248
- SearchPathOpts.RuntimeLibraryPaths .push_back (std::string (RuntimePath.str ()));
249
- #endif
250
-
251
226
llvm::sys::path::append (LibPath, LibSubDir);
252
- SearchPathOpts.RuntimeLibraryPaths .push_back (std::string (LibPath.str ()));
253
- if (Triple.isOSDarwin ())
254
- SearchPathOpts.RuntimeLibraryPaths .push_back (DARWIN_OS_LIBRARY_PATH);
255
-
256
- // If this is set, we don't want any runtime import paths.
257
- if (SearchPathOpts.SkipRuntimeLibraryImportPaths ) {
258
- SearchPathOpts.setRuntimeLibraryImportPaths ({});
259
- return ;
260
- }
261
227
262
228
// Set up the import paths containing the swiftmodules for the libraries in
263
229
// RuntimeLibraryPath.
@@ -270,7 +236,7 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
270
236
RuntimeLibraryImportPaths.push_back (std::string (LibPath.str ()));
271
237
}
272
238
273
- if (!SearchPathOpts.ExcludeSDKPathsFromRuntimeLibraryImportPaths && !SearchPathOpts.getSDKPath ().empty ()) {
239
+ if (!SearchPathOpts.SkipSDKImportPaths && !SearchPathOpts.getSDKPath ().empty ()) {
274
240
const char *swiftDir = FrontendOpts.UseSharedResourceFolder
275
241
? " swift" : " swift_static" ;
276
242
@@ -300,6 +266,35 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
300
266
SearchPathOpts.setRuntimeLibraryImportPaths (RuntimeLibraryImportPaths);
301
267
}
302
268
269
+ static void
270
+ updateImplicitFrameworkSearchPaths (SearchPathOptions &SearchPathOpts,
271
+ const LangOptions &LangOpts) {
272
+ if (SearchPathOpts.SkipAllImportPaths ) {
273
+ SearchPathOpts.setImplicitFrameworkSearchPaths ({});
274
+ return ;
275
+ }
276
+
277
+ std::vector<std::string> ImplicitFrameworkSearchPaths;
278
+ if (LangOpts.Target .isOSDarwin ()) {
279
+ if (!SearchPathOpts.SkipSDKImportPaths &&
280
+ !SearchPathOpts.getSDKPath ().empty ()) {
281
+ StringRef SDKPath = SearchPathOpts.getSDKPath ();
282
+ SmallString<128 > systemFrameworksScratch (SDKPath);
283
+ llvm::sys::path::append (systemFrameworksScratch, " System" , " Library" ,
284
+ " Frameworks" );
285
+ SmallString<128 > systemSubFrameworksScratch (SDKPath);
286
+ llvm::sys::path::append (systemSubFrameworksScratch, " System" , " Library" ,
287
+ " SubFrameworks" );
288
+ SmallString<128 > frameworksScratch (SDKPath);
289
+ llvm::sys::path::append (frameworksScratch, " Library" , " Frameworks" );
290
+ ImplicitFrameworkSearchPaths = {systemFrameworksScratch.str ().str (),
291
+ systemSubFrameworksScratch.str ().str (),
292
+ frameworksScratch.str ().str ()};
293
+ }
294
+ }
295
+ SearchPathOpts.setImplicitFrameworkSearchPaths (ImplicitFrameworkSearchPaths);
296
+ }
297
+
303
298
static void
304
299
setIRGenOutputOptsFromFrontendOptions (IRGenOptions &IRGenOpts,
305
300
const FrontendOptions &FrontendOpts) {
@@ -411,11 +406,13 @@ void CompilerInvocation::setTargetTriple(StringRef Triple) {
411
406
void CompilerInvocation::setTargetTriple (const llvm::Triple &Triple) {
412
407
LangOpts.setTarget (Triple);
413
408
updateRuntimeLibraryPaths (SearchPathOpts, FrontendOpts, LangOpts);
409
+ updateImplicitFrameworkSearchPaths (SearchPathOpts, LangOpts);
414
410
}
415
411
416
412
void CompilerInvocation::setSDKPath (const std::string &Path) {
417
413
SearchPathOpts.setSDKPath (Path);
418
414
updateRuntimeLibraryPaths (SearchPathOpts, FrontendOpts, LangOpts);
415
+ updateImplicitFrameworkSearchPaths (SearchPathOpts, LangOpts);
419
416
}
420
417
421
418
bool CompilerInvocation::setModuleAliasMap (std::vector<std::string> args,
@@ -2387,8 +2384,8 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
2387
2384
if (const Arg *A = Args.getLastArg (OPT_resource_dir))
2388
2385
Opts.RuntimeResourcePath = A->getValue ();
2389
2386
2390
- Opts.SkipRuntimeLibraryImportPaths |= Args.hasArg (OPT_nostdimport);
2391
- Opts.ExcludeSDKPathsFromRuntimeLibraryImportPaths |= Args.hasArg (OPT_nostdlibimport);
2387
+ Opts.SkipAllImportPaths |= Args.hasArg (OPT_nostdimport);
2388
+ Opts.SkipSDKImportPaths |= Args.hasArg (OPT_nostdlibimport);
2392
2389
2393
2390
Opts.DisableModulesValidateSystemDependencies |=
2394
2391
Args.hasArg (OPT_disable_modules_validate_system_headers);
@@ -4043,6 +4040,7 @@ bool CompilerInvocation::parseArgs(
4043
4040
}
4044
4041
4045
4042
updateRuntimeLibraryPaths (SearchPathOpts, FrontendOpts, LangOpts);
4043
+ updateImplicitFrameworkSearchPaths (SearchPathOpts, LangOpts);
4046
4044
setDefaultPrebuiltCacheIfNecessary ();
4047
4045
setDefaultBlocklistsIfNecessary ();
4048
4046
setDefaultInProcessPluginServerPathIfNecessary ();
0 commit comments