Skip to content

Commit 5bbc43c

Browse files
committed
[CMake] Add -simulator to simulator target triples.
The build systems that drive Swift compilation have been using the "simulator" environment as part of the increasingly inaccurately named "target triple" to specify simulator targets for several years... except our own hand-rolled build system. Identify simulator targets and append "-simulator" to their target triples.
1 parent fccfa29 commit 5bbc43c

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function(_report_sdk prefix)
3030
message(STATUS " Deployment version: ${SWIFT_SDK_${prefix}_DEPLOYMENT_VERSION}")
3131
message(STATUS " Version min name: ${SWIFT_SDK_${prefix}_VERSION_MIN_NAME}")
3232
message(STATUS " Triple name: ${SWIFT_SDK_${prefix}_TRIPLE_NAME}")
33+
message(STATUS " Simulator: ${SWIFT_SDK_${prefix}_IS_SIMULATOR}")
3334
endif()
3435
if(SWIFT_SDK_${prefix}_MODULE_ARCHITECTURES)
3536
message(STATUS " Module Architectures: ${SWIFT_SDK_${prefix}_MODULE_ARCHITECTURES}")
@@ -112,6 +113,7 @@ endfunction()
112113
# SWIFT_SDK_${prefix}_VERSION_MIN_NAME Version min name for this SDK
113114
# SWIFT_SDK_${prefix}_TRIPLE_NAME Triple name for this SDK
114115
# SWIFT_SDK_${prefix}_ARCHITECTURES Architectures (as a list)
116+
# SWIFT_SDK_${prefix}_IS_SIMULATOR Whether this is a simulator target.
115117
# SWIFT_SDK_${prefix}_ARCH_${ARCH}_TRIPLE Triple name
116118
macro(configure_sdk_darwin
117119
prefix name deployment_version xcrun_name
@@ -172,6 +174,13 @@ macro(configure_sdk_darwin
172174
"${SWIFT_SDK_${prefix}_ARCHITECTURES}" # rhs
173175
SWIFT_SDK_${prefix}_MODULE_ARCHITECTURES) # result
174176

177+
# Determine whether this is a simulator SDK.
178+
if ( ${xcrun_name} MATCHES "simulator" )
179+
set(SWIFT_SDK_${prefix}_IS_SIMULATOR TRUE)
180+
else()
181+
set(SWIFT_SDK_${prefix}_IS_SIMULATOR FALSE)
182+
endif()
183+
175184
# Configure variables for _all_ architectures even if we aren't "building"
176185
# them because they aren't supported.
177186
foreach(arch ${architectures})
@@ -181,6 +190,12 @@ macro(configure_sdk_darwin
181190
set(SWIFT_SDK_${prefix}_ARCH_${arch}_TRIPLE
182191
"${arch}-apple-${SWIFT_SDK_${prefix}_TRIPLE_NAME}")
183192

193+
# If this is a simulator target, append -simulator.
194+
if (SWIFT_SDK_${prefix}_IS_SIMULATOR)
195+
set(SWIFT_SDK_${prefix}_ARCH_${arch}_TRIPLE
196+
"${SWIFT_SDK_${prefix}_ARCH_${arch}_TRIPLE}-simulator")
197+
endif ()
198+
184199
if(SWIFT_ENABLE_MACCATALYST AND "${prefix}" STREQUAL "OSX")
185200
# For macCatalyst append the '-macabi' environment to the target triple.
186201
set(SWIFT_SDK_MACCATALYST_ARCH_${arch}_TRIPLE

cmake/modules/macCatalystUtils.cmake

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ function(get_maccatalyst_build_flavor out_var sdk flavor)
3535
endif()
3636
endfunction()
3737

38+
# Form a versioned target triple for the given SDK.
39+
function(get_versioned_target_triple target_out_var sdk arch version)
40+
if (SWIFT_SDK_${sdk}_IS_SIMULATOR)
41+
# The version goes before the "-simulator".
42+
set(target "${SWIFT_SDK_${sdk}_ARCH_${arch}_TRIPLE}")
43+
string(REPLACE "-simulator" "" target "${target}")
44+
set(target "${target}${version}-simulator")
45+
else ()
46+
set(target "${SWIFT_SDK_${sdk}_ARCH_${arch}_TRIPLE}${version}")
47+
endif()
48+
49+
set(${target_out_var} "${target}" PARENT_SCOPE)
50+
endfunction()
3851

3952
# Sets target_out_var to the target triple for the given SDK and maccatalyst flavor.
4053
# For zippered flavors also sets the target_variant_out_var. For other
@@ -53,7 +66,8 @@ function(get_target_triple target_out_var target_variant_out_var sdk arch)
5366
set(deployment_version "${TARGET_DEPLOYMENT_VERSION}")
5467

5568
# Default target triple
56-
set(target "${SWIFT_SDK_${sdk}_ARCH_${arch}_TRIPLE}${deployment_version}")
69+
get_versioned_target_triple(target ${sdk} ${arch} "${deployment_version}")
70+
5771
set(target_variant)
5872

5973
get_maccatalyst_build_flavor(maccatalyst_build_flavor

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ foreach(SDK ${SWIFT_SDKS})
194194
foreach(BUILD_FLAVOR ${build_flavors})
195195
# Configure variables for this subdirectory.
196196
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-${ARCH}")
197-
set(VARIANT_TRIPLE "${SWIFT_SDK_${SDK}_ARCH_${ARCH}_TRIPLE}${SWIFT_SDK_${SDK}_DEPLOYMENT_VERSION}")
197+
get_versioned_target_triple(VARIANT_TRIPLE ${SDK} ${ARCH} "${SWIFT_SDK_${SDK}_DEPLOYMENT_VERSION}")
198198
set(VARIANT_SDK "${SWIFT_SDK_${SDK}_ARCH_${ARCH}_PATH}")
199199
set(DEFAULT_OSX_VARIANT_SUFFIX "")
200200

test/lit.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ lit_config.note('Using resource dir: ' + test_resource_dir)
326326
if run_os == 'ios' and run_vers.endswith('-macabi'):
327327
run_vers = run_vers[0:-len('-macabi')]
328328
run_os = 'maccatalyst'
329+
if run_vers.endswith('-simulator'):
330+
run_vers = run_vers[0:-len('-simulator')]
329331

330332
run_ptrsize = '64' if ('64' in run_cpu or run_cpu == "s390x") else '32'
331333
run_ptrauth = 'ptrauth' if run_cpu == 'arm64e' else 'noptrauth'

0 commit comments

Comments
 (0)