Skip to content

Commit 89e381c

Browse files
committed
[CMake/Tests] CMake and lit.cfg support for running macCatalyst tests
Add support for testing with macCatalyst to lit.cfg and the test CMake. This adds lit test features for whether the standard library and runtime was built with macCatalyst support: REQUIRES: maccatalyst_support The test suite can also be run in two modes: one where the macOS tests are run as usual (against a zippered standard library, runtime, and overlays) and another where iOS tests are compiled with the macCatalyst target triple and executed as macCatalyst processes. The iOS tests for macCatalyst can be run by passing `--maccatalyst-ios-tests` to build-script. There are new lit test features to enable a test to specify whether it supports that environment: REQUIRES: OS=maccatalyst UNSUPPORTED: OS=macCatalyst
1 parent 63ce243 commit 89e381c

File tree

7 files changed

+138
-14
lines changed

7 files changed

+138
-14
lines changed

test/CMakeLists.txt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,28 @@ endif()
163163

164164
foreach(SDK ${SWIFT_SDKS})
165165
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
166+
# macCatalyst needs to run two sets of tests: one with the normal macosx target triple
167+
# and one with the the macCatalyst ios-macabi triple. The build_flavors list will
168+
# have have only the "default" flavor for all SDKs and architectures except
169+
# OSX when macCatalyst support is enabled.
170+
set(build_flavors "default")
171+
if(SWIFT_ENABLE_MACCATALYST AND "${SDK}" STREQUAL "OSX")
172+
list(APPEND build_flavors "ios-like" )
173+
endif()
174+
175+
foreach(BUILD_FLAVOR ${build_flavors})
166176
# Configure variables for this subdirectory.
167177
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-${ARCH}")
168178
set(VARIANT_TRIPLE "${SWIFT_SDK_${SDK}_ARCH_${ARCH}_TRIPLE}${SWIFT_SDK_${SDK}_DEPLOYMENT_VERSION}")
169179
set(VARIANT_SDK "${SWIFT_SDK_${SDK}_ARCH_${ARCH}_PATH}")
180+
set(DEFAULT_OSX_VARIANT_SUFFIX "")
181+
182+
if(BUILD_FLAVOR STREQUAL "ios-like")
183+
set(DEFAULT_OSX_VARIANT_SUFFIX "${VARIANT_SUFFIX}")
184+
# Use the macCatalyst target triple and compiler resources for the iOS-like build flavor.
185+
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-maccatalyst-${ARCH}")
186+
set(VARIANT_TRIPLE "${ARCH}-apple-ios13.0-macabi")
187+
endif()
170188

171189
# A directory where to put the xUnit-style XML test results.
172190
set(SWIFT_TEST_RESULTS_DIR
@@ -232,8 +250,17 @@ _Block_release(void) { }\n")
232250
if(SWIFT_BUILD_STDLIB AND SWIFT_INCLUDE_TESTS)
233251
list(APPEND test_dependencies
234252
"swift-test-stdlib-${SWIFT_SDK_${SDK}_LIB_SUBDIR}")
235-
list(APPEND test_dependencies
236-
"swift-reflection-test${VARIANT_SUFFIX}_signed")
253+
254+
if(BUILD_FLAVOR STREQUAL "ios-like")
255+
# When testing the iOS-like build flavor, use the the normal macOS
256+
# swift-reflection-test-tool. That tool runs out of process so it
257+
# doesn't need to be build for macCatalyst.
258+
list(APPEND test_dependencies
259+
"swift-reflection-test${DEFAULT_OSX_VARIANT_SUFFIX}")
260+
else()
261+
list(APPEND test_dependencies
262+
"swift-reflection-test${VARIANT_SUFFIX}_signed")
263+
endif()
237264
endif()
238265

239266
if(NOT "${COVERAGE_DB}" STREQUAL "")
@@ -391,6 +418,7 @@ _Block_release(void) { }\n")
391418
endforeach()
392419
endforeach()
393420
endforeach()
421+
endforeach()
394422
endforeach()
395423

396424
# Add shortcuts for the default variant.

test/lit.cfg

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ lit_config.note('Using resource dir: ' + test_resource_dir)
319319

320320
# Parse the variant triple.
321321
(run_cpu, run_vendor, run_os, run_vers) = re.match('([^-]+)-([^-]+)-([^0-9]+)(.*)', config.variant_triple).groups()
322+
if run_os == 'ios' and run_vers.endswith('-macabi'):
323+
run_vers = run_vers[0:-len('-macabi')]
324+
run_os = 'maccatalyst'
325+
322326
run_ptrsize = '64' if ('64' in run_cpu or run_cpu == "s390x") else '32'
323327
run_endian = 'little' if run_cpu != 's390x' else 'big'
324328

@@ -602,7 +606,12 @@ if config.benchmark_o != 'Benchmark_O':
602606
config.substitutions.append(('%target-triple', config.variant_triple))
603607

604608
if run_vendor == 'apple':
605-
if True:
609+
if run_os == 'maccatalyst':
610+
config.stable_abi_triple = '%s-%s-ios13.0-macabi' % (run_cpu, run_vendor)
611+
config.pre_stable_abi_triple = config.stable_abi_triple
612+
config.next_stable_abi_triple = config.stable_abi_triple
613+
config.available_features.add('swift_stable_abi')
614+
else:
606615
# iOS 12.2 does not support 32-bit targets, so we cannot run tests that
607616
# want to deploy to an iOS that has Swift in the OS.
608617
if run_os == 'ios' and run_ptrsize == '32':
@@ -612,6 +621,7 @@ if run_vendor == 'apple':
612621
PRE_STABLE_VERSION = {
613622
'macosx': '10.14.3',
614623
'ios': '12.1',
624+
'maccatalyst': '12.1',
615625
'tvos': '12.1',
616626
'watchos': '5.1'
617627
}
@@ -622,6 +632,7 @@ if run_vendor == 'apple':
622632
STABLE_VERSION = {
623633
'macosx': '10.14.4',
624634
'ios': '12.2',
635+
'maccatalyst': '12.2',
625636
'tvos': '12.2',
626637
'watchos': '5.2'
627638
}
@@ -632,6 +643,7 @@ if run_vendor == 'apple':
632643
NEXT_STABLE_VERSION = {
633644
'macosx': '10.15',
634645
'ios': '13',
646+
'maccatalyst': '13',
635647
'tvos': '13',
636648
'watchos': '6'
637649
}
@@ -668,6 +680,17 @@ config.substitutions.append(('%sanitizers-target-triple',
668680
config.variant_triple.replace("ios7", "ios8")))
669681

670682
config.substitutions.append(('%target-cpu', run_cpu))
683+
684+
target_os_abi = run_os
685+
target_os_is_maccatalyst = "FALSE"
686+
if (run_os == 'maccatalyst'):
687+
# For purposes of ABI, treat maccatalyst as macosx since the maccatalyst ABI
688+
# must match the macosx ABI.
689+
target_os_abi = 'macosx'
690+
target_os_is_maccatalyst = "TRUE"
691+
config.available_features.add("OS=ios")
692+
config.substitutions.append(('%target-os-abi', target_os_abi))
693+
config.substitutions.append(('%target-os-is-maccatalyst', target_os_is_maccatalyst))
671694
config.substitutions.append(('%target-endian', run_endian))
672695
config.substitutions.append(('%target-os', run_os))
673696
config.substitutions.append(('%target-ptrsize', run_ptrsize))
@@ -703,7 +726,12 @@ if 'swift_interpreter' in config.available_features:
703726

704727
config.target_runtime = "unknown"
705728

706-
swift_reflection_test_name = 'swift-reflection-test' + config.variant_suffix
729+
if (getattr(config, 'darwin_enable_maccatalyst', False) and
730+
config.darwin_maccatalyst_build_flavor == "ios-like"):
731+
variant_suffix = config.darwin_osx_variant_suffix
732+
else:
733+
variant_suffix = config.variant_suffix
734+
swift_reflection_test_name = 'swift-reflection-test' + variant_suffix
707735

708736
def use_interpreter_for_simple_runs():
709737
def make_simple_target_run(gyb=False, stdlib=False, parameterized=False):
@@ -858,25 +886,49 @@ if run_vendor == 'apple':
858886
lit_config.fatal('Could not get or decode sw_vers output. ' +
859887
'Perhaps the simulator is not working.')
860888

861-
elif run_os == 'macosx':
889+
elif run_os == 'macosx' or run_os == 'maccatalyst':
862890
# OS X
863891
lit_config.note("Testing OS X " + config.variant_triple)
864892

865893
xcrun_sdk_name = "macosx"
866-
config.target_cc_options = (
867-
"-arch %s -m%s-version-min=%s %s" %
868-
(run_cpu, run_os, run_vers, clang_mcp_opt))
894+
895+
if run_os == 'maccatalyst':
896+
# For maccatalyst, pass the target triple to clang
897+
# rather than arch and version separately.
898+
config.target_cc_options = (
899+
"-target %s %s" %
900+
(config.variant_triple, clang_mcp_opt))
901+
else:
902+
config.target_cc_options = (
903+
"-arch %s -m%s-version-min=%s %s" %
904+
(run_cpu, run_os, run_vers, clang_mcp_opt))
905+
906+
maccatalyst_frameworks_component = ""
907+
if run_os == 'maccatalyst':
908+
# Additional framework search paths for macCatalyst.
909+
# These have to come before other search paths so that for
910+
# unzippered twin frameworks the unzippered twin version
911+
# is favored under macCatalyst.
912+
maccatalyst_frameworks_dir = make_path(config.variant_sdk,
913+
"System", "iOSSupport", "System", "Library", "Frameworks")
914+
maccatalyst_frameworks_component = ( "-F %r" % maccatalyst_frameworks_dir )
915+
# Module triples end in ios-macabi.
916+
target_specific_module_triple = '{}-apple-ios-macabi'.format(
917+
{ 'aarch64': 'arm64', 'amd64': 'x86_64' }.get(run_cpu, run_cpu)
918+
)
869919

870920
config.target_build_swift = (
871-
("%s %s %s -F %r -toolchain-stdlib-rpath "
921+
("%s %s %s %s -F %r -toolchain-stdlib-rpath "
872922
+ "-Xlinker -rpath -Xlinker %r %s %s %s %s "
873923
+ "-F %r -Xlinker -rpath -Xlinker %r")
874924
% (xcrun_prefix, config.swiftc, target_options,
925+
maccatalyst_frameworks_component,
875926
extra_frameworks_dir, extra_frameworks_dir,
876927
sdk_overlay_linker_opt, config.swift_test_options,
877928
config.swift_driver_test_options,
878929
swift_execution_tests_extra_flags, sourcekitd_framework_dir,
879930
sourcekitd_framework_dir))
931+
880932
config.target_run = ""
881933
target_future_version = "10.99"
882934

@@ -896,9 +948,13 @@ if run_vendor == 'apple':
896948

897949
config.target_sdk_name = xcrun_sdk_name
898950
config.target_ld = "%s ld -L%r" % (xcrun_prefix, make_path(test_resource_dir, config.target_sdk_name))
951+
952+
maccatalyst_extra_frameworks = ""
953+
if run_os == 'maccatalyst':
954+
maccatalyst_extra_frameworks = "-F {}/System/iOSSupport/System/Library/Frameworks".format(config.variant_sdk)
899955
config.target_swift_frontend = (
900-
"%s -frontend %s -sdk %r %s %s" %
901-
(config.swiftc, target_options, config.variant_sdk,
956+
"%s -frontend %s -sdk %r %s %s %s" %
957+
(config.swiftc, target_options, config.variant_sdk, maccatalyst_extra_frameworks,
902958
config.swift_test_options, config.swift_frontend_test_options))
903959
subst_target_swift_frontend_mock_sdk = (
904960
"%s -frontend %s -sdk %r %s %s" %
@@ -940,6 +996,7 @@ if run_vendor == 'apple':
940996
config.target_add_rpath = r'-Xlinker -rpath -Xlinker \1'
941997

942998
target_future = format('%s-apple-%s%s' % (run_cpu, run_os, target_future_version))
999+
config.otool_classic = ("%s otool-classic" % (xcrun_prefix))
9431000

9441001
elif run_os in ['windows-msvc']:
9451002
lit_config.note('Testing Windows ' + config.variant_triple)
@@ -1480,6 +1537,13 @@ if platform.system() != 'Darwin' or swift_test_mode == 'optimize_none_with_impli
14801537
platform_module_dir = make_path(test_resource_dir, config.target_sdk_name)
14811538
if run_vendor != 'apple':
14821539
platform_module_dir = make_path(platform_module_dir, run_cpu)
1540+
1541+
platform_dylib_dir = platform_module_dir
1542+
if run_os == 'maccatalyst' and config.darwin_maccatalyst_build_flavor == "ios-like":
1543+
# When using the ios-macabi triple, look for module files
1544+
# in the 'maccatalyst' compiler resource directory.
1545+
platform_module_dir = make_path(test_resource_dir, 'maccatalyst')
1546+
14831547
lit_config.note('Using platform module dir: ' + platform_module_dir)
14841548
if test_sdk_overlay_dir:
14851549
platform_sdk_overlay_dir = test_sdk_overlay_dir
@@ -1496,10 +1560,15 @@ if os.path.exists(static_libswiftCore_path):
14961560

14971561
# Set up testing with the standard libraries coming from the OS / just-built libraries
14981562
# default Swift tests to use the just-built libraries
1499-
target_stdlib_path = platform_module_dir
1563+
target_stdlib_path = platform_dylib_dir
15001564
if not kIsWindows:
15011565
libdispatch_path = getattr(config, 'libdispatch_artifact_dir', '')
15021566
if 'use_os_stdlib' not in lit_config.params:
1567+
if run_os == 'maccatalyst':
1568+
# Under macCatalyst we need to have the unzippered twin dylib dir come before
1569+
# the zippered/macosx dylib dir so that unzippered twins are picked upload_dylibs
1570+
# before the macOS variant.
1571+
target_stdlib_path = "{0}:{1}".format(platform_module_dir, target_stdlib_path)
15031572
lit_config.note('Testing with the just-built libraries at ' + target_stdlib_path)
15041573
config.target_run = (
15051574
"/usr/bin/env "
@@ -1513,6 +1582,8 @@ if not kIsWindows:
15131582
if run_vendor == 'apple':
15141583
#If we get swift-in-the-OS for non-Apple platforms, add a condition here
15151584
os_stdlib_path = "/usr/lib/swift"
1585+
if run_os == 'maccatalyst':
1586+
os_stdlib_path = "/System/iOSSupport/usr/lib/swift:/usr/lib/swift"
15161587
all_stdlib_path = os.path.pathsep.join((os_stdlib_path, target_stdlib_path))
15171588
lit_config.note('Testing with the standard libraries coming from the OS ' + all_stdlib_path)
15181589
config.target_run = (
@@ -1667,6 +1738,8 @@ config.substitutions.append(('%target-swift-emit-pcm',
16671738

16681739
config.substitutions.insert(0, ('%platform-module-dir', platform_module_dir))
16691740
config.substitutions.insert(0, ('%platform-sdk-overlay-dir', platform_sdk_overlay_dir))
1741+
config.substitutions.insert(0, ('%platform-dylib-dir', platform_dylib_dir))
1742+
config.substitutions.insert(0, ('%test-resource-dir', test_resource_dir))
16701743

16711744
if run_vendor != 'apple':
16721745
extra_frameworks_dir = ''
@@ -1690,6 +1763,9 @@ config.substitutions.append(('%target-resilience-test', config.target_resilience
16901763
config.substitutions.append(('%llvm-profdata', config.llvm_profdata))
16911764
config.substitutions.append(('%llvm-cov', config.llvm_cov))
16921765

1766+
if hasattr(config, 'otool_classic'):
1767+
config.substitutions.append(('%otool-classic', config.otool_classic))
1768+
16931769
config.substitutions.append(('%FileCheck',
16941770
'%r %r --sanitize BUILD_DIR=%r --sanitize SOURCE_DIR=%r --use-filecheck %r %s' % (
16951771
sys.executable,

test/lit.site.cfg.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ msvc_runtime_flags = {
5151
config.swift_stdlib_msvc_runtime = \
5252
msvc_runtime_flags["@SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY@"]
5353

54+
config.darwin_enable_maccatalyst = "@SWIFT_ENABLE_MACCATALYST@" == "TRUE"
55+
config.darwin_maccatalyst_build_flavor = "@BUILD_FLAVOR@"
56+
config.darwin_osx_variant_suffix = "@DEFAULT_OSX_VARIANT_SUFFIX@"
57+
5458
# Please remember to handle empty strings and/or unset variables correctly.
5559

5660
if "@SWIFT_ASAN_BUILD@" == "TRUE":
@@ -103,6 +107,9 @@ if "@CMAKE_GENERATOR@" == "Xcode":
103107

104108
config.available_features.add("CMAKE_GENERATOR=@CMAKE_GENERATOR@")
105109

110+
if "@SWIFT_ENABLE_MACCATALYST@" == "TRUE":
111+
config.available_features.add('maccatalyst_support')
112+
106113
if "@SWIFT_BUILD_SYNTAXPARSERLIB@" == "TRUE":
107114
config.available_features.add('syntax_parser_lib')
108115

utils/build-script

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,8 @@ class BuildScriptInvocation(object):
599599
# Enable macCatalyst
600600
if args.maccatalyst:
601601
args.extra_cmake_options.append('-DSWIFT_ENABLE_MACCATALYST:BOOL=TRUE')
602+
if args.maccatalyst_ios_tests:
603+
impl_args += [ "--darwin-test-maccatalyst-ios-like=1" ]
602604

603605
# If we have extra_cmake_options, combine all of them together and then
604606
# add them as one command.

utils/build-script-impl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ KNOWN_SETTINGS=(
175175
skip-test-linux "" "set to skip testing Swift stdlibs for Linux"
176176
skip-test-llbuild "" "set to skip testing llbuild"
177177
skip-test-lldb "" "set to skip testing lldb"
178+
skip-test-maccatalyst "" "set to skip testing Swift stdlibs for macCatalyst"
178179
skip-test-osx "" "set to skip testing Swift stdlibs for OS X"
179180
skip-test-playgroundsupport "" "set to skip testing PlaygroundSupport"
180181
skip-test-swift "" "set to skip testing Swift"

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ def create_argument_parser():
338338
option('--maccatalyst', toggle_true,
339339
help='Enable building Swift with macCatalyst support')
340340

341+
option('--maccatalyst-ios-tests', toggle_true,
342+
help='When building for macCatalyst run tests with iOS-like target triple')
343+
341344
option('--android', toggle_true,
342345
help='also build for Android')
343346

utils/swift_build_support/swift_build_support/host_specific_configuration.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,15 @@ def __init__(self, host_target, args):
149149
subset_suffix = "-only_stress"
150150
else:
151151
subset_suffix = ""
152-
self.swift_test_run_targets.append("check-swift{}{}-{}".format(
153-
subset_suffix, suffix, name))
152+
153+
# Support for running the macCatalyst tests with
154+
# the iOS-like target triple.
155+
if name == "macosx-x86_64" and args.maccatalyst and args.maccatalyst_ios_tests:
156+
self.swift_test_run_targets.append("check-swift{}{}-{}".format(
157+
subset_suffix, suffix, "macosx-maccatalyst-x86_64"))
158+
else:
159+
self.swift_test_run_targets.append("check-swift{}{}-{}".format(
160+
subset_suffix, suffix, name))
154161
if args.test_optimized and not test_host_only:
155162
self.swift_test_run_targets.append(
156163
"check-swift{}-optimize-{}".format(

0 commit comments

Comments
 (0)