@@ -330,6 +330,26 @@ toolchains::Darwin::addSanitizerArgs(ArgStringList &Arguments,
330
330
/* shared=*/ false );
331
331
}
332
332
333
+ namespace {
334
+
335
+ enum class BackDeployLibFilter {
336
+ executable,
337
+ all
338
+ };
339
+
340
+ // Whether the given job matches the backward-deployment library filter.
341
+ bool jobMatchesFilter (LinkKind jobKind, BackDeployLibFilter filter) {
342
+ switch (filter) {
343
+ case BackDeployLibFilter::executable:
344
+ return jobKind == LinkKind::Executable;
345
+
346
+ case BackDeployLibFilter::all:
347
+ return true ;
348
+ }
349
+ }
350
+
351
+ }
352
+
333
353
void
334
354
toolchains::Darwin::addArgsToLinkStdlib (ArgStringList &Arguments,
335
355
const DynamicLinkJobAction &job,
@@ -359,47 +379,31 @@ toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments,
359
379
}
360
380
361
381
if (runtimeCompatibilityVersion) {
362
- if (*runtimeCompatibilityVersion <= llvm::VersionTuple (5 , 0 )) {
363
- // Swift 5.0 compatibility library
364
- SmallString<128 > BackDeployLib;
365
- BackDeployLib.append (SharedResourceDirPath);
366
- llvm::sys::path::append (BackDeployLib, " libswiftCompatibility50.a" );
367
-
368
- if (llvm::sys::fs::exists (BackDeployLib)) {
369
- Arguments.push_back (" -force_load" );
370
- Arguments.push_back (context.Args .MakeArgString (BackDeployLib));
371
- }
372
- }
382
+ auto addBackDeployLib = [&](llvm::VersionTuple version,
383
+ BackDeployLibFilter filter,
384
+ StringRef libraryName) {
385
+ if (*runtimeCompatibilityVersion > version)
386
+ return ;
373
387
374
- if (*runtimeCompatibilityVersion <= llvm::VersionTuple (5 , 1 )) {
375
- // Swift 5.1 compatibility library
388
+ if (!jobMatchesFilter (job.getKind (), filter))
389
+ return ;
390
+
376
391
SmallString<128 > BackDeployLib;
377
392
BackDeployLib.append (SharedResourceDirPath);
378
- llvm::sys::path::append (BackDeployLib, " libswiftCompatibility51 .a" );
393
+ llvm::sys::path::append (BackDeployLib, " lib " + libraryName + " .a" );
379
394
380
395
if (llvm::sys::fs::exists (BackDeployLib)) {
381
396
Arguments.push_back (" -force_load" );
382
397
Arguments.push_back (context.Args .MakeArgString (BackDeployLib));
383
398
}
384
- }
399
+ };
400
+
401
+ #define BACK_DEPLOYMENT_LIB (Version, Filter, LibraryName ) \
402
+ addBackDeployLib ( \
403
+ llvm::VersionTuple Version, BackDeployLibFilter::Filter, LibraryName);
404
+ #include " swift/Frontend/BackDeploymentLibs.def"
385
405
}
386
406
387
- if (job.getKind () == LinkKind::Executable) {
388
- if (runtimeCompatibilityVersion)
389
- if (*runtimeCompatibilityVersion <= llvm::VersionTuple (5 , 0 )) {
390
- // Swift 5.0 dynamic replacement compatibility library.
391
- SmallString<128 > BackDeployLib;
392
- BackDeployLib.append (SharedResourceDirPath);
393
- llvm::sys::path::append (BackDeployLib,
394
- " libswiftCompatibilityDynamicReplacements.a" );
395
-
396
- if (llvm::sys::fs::exists (BackDeployLib)) {
397
- Arguments.push_back (" -force_load" );
398
- Arguments.push_back (context.Args .MakeArgString (BackDeployLib));
399
- }
400
- }
401
- }
402
-
403
407
// Add the runtime library link path, which is platform-specific and found
404
408
// relative to the compiler.
405
409
SmallVector<std::string, 4 > RuntimeLibPaths;
0 commit comments