@@ -426,15 +426,55 @@ swift_version = lit_config.params.get('swift-version',
426
426
lit_config .note ('Compiling with -swift-version ' + swift_version )
427
427
config .swift_test_options = '-swift-version ' + swift_version
428
428
429
- # Load availability macros for known stdlib releases.
429
+ # Loads availability macros for known stdlib releases.
430
430
def load_availability_macros ():
431
431
path = os .path .join (os .path .dirname (__file__ ), "../utils/availability-macros.def" )
432
432
lines = open (path , 'r' ).read ().splitlines ()
433
433
pattern = re .compile (r"\s*(#.*)?" )
434
434
return filter (lambda l : pattern .fullmatch (l ) is None , lines )
435
+
436
+ # Returns a tuple with the Swift ABI version (e.g. '5.0') and the corresponding
437
+ # target triple (e.g. 'arm64-apple-ios12.2')
438
+ def availability_macro_to_swift_abi_target_triple (macro ):
439
+ # Use a regex and split to pull out the components of an availability macro
440
+ # that is formatted like this:
441
+ # SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2
442
+ matches = re .search (r'^[\s]*SwiftStdlib[\s]+([0-9\.]+)[\s]*:[\s]*(.+)' , macro )
443
+ stdlib_vers = matches .group (1 )
444
+ vers_by_platform = {}
445
+ for platform_vers in matches .group (2 ).split (', ' ):
446
+ components = platform_vers .split (' ' )
447
+ vers_by_platform [components [0 ]] = components [1 ]
448
+
449
+ platform = {
450
+ 'macosx' : 'macOS' ,
451
+ 'ios' : 'iOS' ,
452
+ 'maccatalyst' : 'iOS' ,
453
+ 'tvos' : 'tvOS' ,
454
+ 'watchos' : 'watchOS'
455
+ }.get (run_os )
456
+
457
+ if platform is None :
458
+ return stdlib_vers , config .variant_triple
459
+
460
+ os_vers = vers_by_platform .get (platform )
461
+ if os_vers is None :
462
+ return stdlib_vers , config .variant_triple
463
+
464
+ if run_os == 'maccatalyst' :
465
+ return stdlib_vers , '%s-%s-ios%s-macabi' % (run_cpu , run_vendor , os_vers )
466
+
467
+ return stdlib_vers , '%s-%s-%s%s%s' % (run_cpu , run_vendor , run_os ,
468
+ os_vers , run_environment )
469
+
470
+ # Add availability macros to the default frontend/driver flags and create target
471
+ # triple substitutions for each stdlib version.
435
472
for macro in load_availability_macros ():
436
473
config .swift_frontend_test_options += " -define-availability '{0}'" .format (macro )
437
474
config .swift_driver_test_options += " -Xfrontend -define-availability -Xfrontend '{0}'" .format (macro )
475
+ (stdlib_vers , triple ) = availability_macro_to_swift_abi_target_triple (macro )
476
+ config .substitutions .append (('%target-swift-abi-{}-triple' .format (stdlib_vers ), triple ))
477
+
438
478
439
479
differentiable_programming = lit_config .params .get ('differentiable_programming' , None )
440
480
if differentiable_programming is not None :
0 commit comments