Skip to content

Commit c42d0d2

Browse files
committed
[stdlib] Only add Apple reflection test targets
When building on a macOS host, and when `SWIFT_INCLUDE_TESTS` is specified, the `swiftSwiftReflectionTest` target is added to all platforms. However, this target has a dependency upon Foundation, which is not available on non-Apple platforms. Use `add_swift_library`'s `TARGET_SDKS` parameter and other gating logic to ensure the target is only added for platforms that actually have Darwin available.
1 parent e52e043 commit c42d0d2

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ include_directories(BEFORE
419419
# endif()
420420
set(SWIFT_DARWIN_VARIANTS "^(macosx|iphoneos|iphonesimulator|appletvos|appletvsimulator|watchos|watchsimulator)")
421421

422+
# A convenient list to match Darwin SDKs. Example:
423+
# if("${SWIFT_HOST_VARIANT_SDK}" IN_LIST SWIFT_APPLE_PLATFORMS)
424+
# ...
425+
# endif()
426+
set(SWIFT_APPLE_PLATFORMS "IOS" "IOS_SIMULATOR" "TVOS" "TVOS_SIMULATOR" "WATCHOS" "WATCHOS_SIMULATOR" "OSX")
427+
422428
# Configuration flags passed to all of our invocations of gyb. Try to
423429
# avoid making up new variable names here if you can find a CMake
424430
# variable that will do the job.

cmake/modules/AddSwift.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ function(add_swift_library name)
12301230
set(SWIFTLIB_TARGET_SDKS ${SWIFT_SDKS})
12311231
endif()
12321232
list_replace(SWIFTLIB_TARGET_SDKS ALL_POSIX_PLATFORMS "ALL_APPLE_PLATFORMS;ANDROID;CYGWIN;FREEBSD;LINUX")
1233-
list_replace(SWIFTLIB_TARGET_SDKS ALL_APPLE_PLATFORMS "IOS;IOS_SIMULATOR;TVOS;TVOS_SIMULATOR;WATCHOS;WATCHOS_SIMULATOR;OSX")
1233+
list_replace(SWIFTLIB_TARGET_SDKS ALL_APPLE_PLATFORMS "${SWIFT_APPLE_PLATFORMS}")
12341234

12351235
# All Swift code depends on the standard library, except for the standard
12361236
# library itself.

stdlib/private/SwiftReflectionTest/CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ if (SWIFT_INCLUDE_TESTS)
33
add_swift_library(swiftSwiftReflectionTest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
44
SwiftReflectionTest.swift
55
SWIFT_MODULE_DEPENDS Darwin
6+
TARGET_SDKS ALL_APPLE_PLATFORMS
67
INSTALL_IN_COMPONENT stdlib-experimental)
78

89
foreach(SDK ${SWIFT_SDKS})
9-
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
10-
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-${ARCH}")
11-
add_dependencies(
12-
"swiftSwiftReflectionTest${VARIANT_SUFFIX}"
13-
"swift-reflection-test${VARIANT_SUFFIX}")
14-
endforeach()
10+
if("${SDK}" IN_LIST SWIFT_APPLE_PLATFORMS)
11+
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
12+
set(VARIANT_SUFFIX "-${SWIFT_SDK_${SDK}_LIB_SUBDIR}-${ARCH}")
13+
add_dependencies(
14+
"swiftSwiftReflectionTest${VARIANT_SUFFIX}"
15+
"swift-reflection-test${VARIANT_SUFFIX}")
16+
endforeach()
17+
endif()
1518
endforeach()
1619
endif()

0 commit comments

Comments
 (0)