Skip to content

Split SWIFT_DARWIN_PLATFORMS and SWIFT_APPLE_PLATFORMS in CMake. SWIFT_APPLE_PLATFORMS may contain 'FREESTANDING' when building the freestanding SDK and SWIFT_FREESTANDING_FLAVOR is set to 'apple'. #38997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,15 @@ set(SWIFT_DARWIN_VARIANTS "^(macosx|iphoneos|iphonesimulator|appletvos|appletvsi
set(SWIFT_DARWIN_EMBEDDED_VARIANTS "^(iphoneos|iphonesimulator|appletvos|appletvsimulator|watchos|watchsimulator)")

# A convenient list to match Darwin SDKs. Example:
# if("${SWIFT_HOST_VARIANT_SDK}" IN_LIST SWIFT_APPLE_PLATFORMS)
# if("${SWIFT_HOST_VARIANT_SDK}" IN_LIST SWIFT_DARWIN_PLATFORMS)
# ...
# endif()
set(SWIFT_APPLE_PLATFORMS "IOS" "IOS_SIMULATOR" "TVOS" "TVOS_SIMULATOR" "WATCHOS" "WATCHOS_SIMULATOR" "OSX")
set(SWIFT_DARWIN_PLATFORMS "IOS" "IOS_SIMULATOR" "TVOS" "TVOS_SIMULATOR" "WATCHOS" "WATCHOS_SIMULATOR" "OSX")

set(SWIFT_APPLE_PLATFORMS ${SWIFT_DARWIN_PLATFORMS})
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "apple")
list(APPEND SWIFT_APPLE_PLATFORMS "FREESTANDING")
endif()

# Configuration flags passed to all of our invocations of gyb. Try to
# avoid making up new variable names here if you can find a CMake
Expand Down
12 changes: 6 additions & 6 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ endfunction()
# Usage:
# _add_host_variant_c_compile_link_flags(name)
function(_add_host_variant_c_compile_link_flags name)
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
set(DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}")
endif()

Expand Down Expand Up @@ -153,7 +153,7 @@ function(_add_host_variant_c_compile_link_flags name)
endif()
endif()

if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
# We collate -F with the framework path to avoid unwanted deduplication
# of options by target_compile_options -- this way no undesired
# side effects are introduced should a new search path be added.
Expand Down Expand Up @@ -537,7 +537,7 @@ function(add_swift_host_library name)
BINARY_DIR ${SWIFT_RUNTIME_OUTPUT_INTDIR}
LIBRARY_DIR ${SWIFT_LIBRARY_OUTPUT_INTDIR})

if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
set_target_properties(${name} PROPERTIES
INSTALL_NAME_DIR "@rpath")
elseif(SWIFT_HOST_VARIANT_SDK STREQUAL LINUX)
Expand Down Expand Up @@ -596,7 +596,7 @@ function(add_swift_host_library name)
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE CXX)
endif()

if(${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
if(${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)
target_link_options(${name} PRIVATE
"LINKER:-compatibility_version,1")
if(SWIFT_COMPILER_VERSION)
Expand Down Expand Up @@ -723,7 +723,7 @@ function(add_libswift name)

set(build_dir ${CMAKE_CURRENT_BINARY_DIR})

if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
set(deployment_version "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}")
endif()
get_versioned_target_triple(target ${SWIFT_HOST_VARIANT_SDK}
Expand Down Expand Up @@ -821,7 +821,7 @@ function(add_swift_host_tool executable)
set_target_properties(${executable} PROPERTIES
JOB_POOL_LINK swift_link_job_pool)
endif()
if(${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
if(${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)
# If we found a swift compiler and are going to use swift code in swift
# host side tools but link with clang, add the appropriate -L paths so we
# find all of the necessary swift libraries on Darwin.
Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/Libdispatch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ endif()

# Build any target libdispatch if needed.
foreach(sdk ${SWIFT_SDKS})
# Apple targets have libdispatch available, do not build it.
if(NOT "${sdk}" IN_LIST SWIFT_APPLE_PLATFORMS)
# Darwin targets have libdispatch available, do not build it.
if(NOT "${sdk}" IN_LIST SWIFT_DARWIN_PLATFORMS)
list(APPEND DISPATCH_SDKS "${sdk}")
endif()
endforeach()
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/StandaloneOverlay.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ set(CMAKE_INSTALL_PREFIX
"${SWIFT_DEST_ROOT}${TOOLCHAIN_DIR}/usr")


set(SWIFT_APPLE_PLATFORMS
set(SWIFT_DARWIN_PLATFORMS
OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR)

# Flags used to indicate we are building a standalone overlay.
Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function(_report_sdk prefix)
message(STATUS " ${CMAKE_BUILD_TYPE} VC++ CRT: MD")
endif()
endif()
if(prefix IN_LIST SWIFT_APPLE_PLATFORMS)
if(prefix IN_LIST SWIFT_DARWIN_PLATFORMS)
message(STATUS " Version: ${SWIFT_SDK_${prefix}_VERSION}")
message(STATUS " Build number: ${SWIFT_SDK_${prefix}_BUILD_NUMBER}")
message(STATUS " Deployment version: ${SWIFT_SDK_${prefix}_DEPLOYMENT_VERSION}")
Expand Down Expand Up @@ -60,7 +60,7 @@ function(_report_sdk prefix)
endforeach()
endif()

if(NOT prefix IN_LIST SWIFT_APPLE_PLATFORMS)
if(NOT prefix IN_LIST SWIFT_DARWIN_PLATFORMS)
foreach(arch ${SWIFT_SDK_${prefix}_ARCHITECTURES})
message(STATUS " ${arch} libc header path: ${SWIFT_SDK_${prefix}_ARCH_${arch}_LIBC_INCLUDE_DIRECTORY}")
message(STATUS " ${arch} libc architecture specific header path: ${SWIFT_SDK_${prefix}_ARCH_${arch}_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY}")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ if(SWIFT_BUILD_DYNAMIC_STDLIB)
list(APPEND SWIFT_STDLIB_LIBRARY_BUILD_TYPES SHARED)
endif()
if(SWIFT_BUILD_STATIC_STDLIB)
list_intersect("${SWIFT_APPLE_PLATFORMS}" "${SWIFT_SDKS}" building_darwin_sdks)
list_intersect("${SWIFT_DARWIN_PLATFORMS}" "${SWIFT_SDKS}" building_darwin_sdks)
if(building_darwin_sdks)
message(SEND_ERROR "cannot build static standard library for Darwin SDKs")
else()
Expand Down
28 changes: 13 additions & 15 deletions stdlib/cmake/modules/AddSwiftStdlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function(_add_target_variant_c_compile_link_flags)

set(result ${${CFLAGS_RESULT_VAR_NAME}})

if("${CFLAGS_SDK}" IN_LIST SWIFT_APPLE_PLATFORMS)
if("${CFLAGS_SDK}" IN_LIST SWIFT_DARWIN_PLATFORMS)
# Check if there's a specific OS deployment version needed for this invocation
if("${CFLAGS_SDK}" STREQUAL "OSX")
if(DEFINED maccatalyst_build_flavor)
Expand Down Expand Up @@ -102,7 +102,7 @@ function(_add_target_variant_c_compile_link_flags)
endif()
endif()

if("${CFLAGS_SDK}" IN_LIST SWIFT_APPLE_PLATFORMS)
if("${CFLAGS_SDK}" IN_LIST SWIFT_DARWIN_PLATFORMS)
# We collate -F with the framework path to avoid unwanted deduplication
# of options by target_compile_options -- this way no undesired
# side effects are introduced should a new search path be added.
Expand Down Expand Up @@ -827,7 +827,7 @@ function(_add_swift_target_library_single target name)
endif()

# Only build the modules for any arch listed in the *_MODULE_ARCHITECTURES.
if(SWIFTLIB_SINGLE_SDK IN_LIST SWIFT_APPLE_PLATFORMS
if(SWIFTLIB_SINGLE_SDK IN_LIST SWIFT_DARWIN_PLATFORMS
AND SWIFTLIB_SINGLE_ARCHITECTURE IN_LIST SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_MODULE_ARCHITECTURES)
# Create dummy target to hook up the module target dependency.
add_custom_target("${target}"
Expand Down Expand Up @@ -959,7 +959,7 @@ function(_add_swift_target_library_single target name)
endforeach()
endif()

if(SWIFTLIB_SINGLE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
if(SWIFTLIB_SINGLE_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
set(install_name_dir "@rpath")

if(SWIFTLIB_SINGLE_IS_STDLIB)
Expand Down Expand Up @@ -1194,7 +1194,7 @@ function(_add_swift_target_library_single target name)

# Configure plist creation for OS X.
set(PLIST_INFO_PLIST "Info.plist" CACHE STRING "Plist name")
if("${SWIFTLIB_SINGLE_SDK}" IN_LIST SWIFT_APPLE_PLATFORMS AND SWIFTLIB_SINGLE_IS_STDLIB)
if("${SWIFTLIB_SINGLE_SDK}" IN_LIST SWIFT_DARWIN_PLATFORMS AND SWIFTLIB_SINGLE_IS_STDLIB)
set(PLIST_INFO_NAME ${name})
set(PLIST_INFO_UTI "com.apple.dt.runtime.${name}")
set(PLIST_INFO_VERSION "${SWIFT_VERSION}")
Expand Down Expand Up @@ -1251,7 +1251,7 @@ function(_add_swift_target_library_single target name)
${c_compile_flags})
target_link_options(${target} PRIVATE
${link_flags})
if(${SWIFTLIB_SINGLE_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
if(${SWIFTLIB_SINGLE_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)
target_link_options(${target} PRIVATE
"LINKER:-compatibility_version,1")
if(SWIFT_COMPILER_VERSION)
Expand Down Expand Up @@ -1614,7 +1614,7 @@ function(add_swift_target_library name)
if("${SWIFTLIB_TARGET_SDKS}" STREQUAL "")
set(SWIFTLIB_TARGET_SDKS ${SWIFT_SDKS})
endif()
list_replace(SWIFTLIB_TARGET_SDKS ALL_APPLE_PLATFORMS "${SWIFT_APPLE_PLATFORMS}")
list_replace(SWIFTLIB_TARGET_SDKS ALL_APPLE_PLATFORMS "${SWIFT_DARWIN_PLATFORMS}")

# All Swift code depends on the standard library, except for the standard
# library itself.
Expand Down Expand Up @@ -1832,7 +1832,7 @@ function(add_swift_target_library name)
list(APPEND swiftlib_link_flags_all "-Wl,-z,defs")
endif()
# Setting back linker flags which are not supported when making Android build on macOS cross-compile host.
if(SWIFTLIB_SHARED AND sdk IN_LIST SWIFT_APPLE_PLATFORMS)
if(SWIFTLIB_SHARED AND sdk IN_LIST SWIFT_DARWIN_PLATFORMS)
list(APPEND swiftlib_link_flags_all "-dynamiclib -Wl,-headerpad_max_install_names")
endif()

Expand Down Expand Up @@ -1952,7 +1952,7 @@ function(add_swift_target_library name)
list(APPEND swiftlib_link_flags_all "-F${ios_support_frameworks_path}")
endif()

if(sdk IN_LIST SWIFT_APPLE_PLATFORMS AND SWIFTLIB_IS_SDK_OVERLAY)
if(sdk IN_LIST SWIFT_DARWIN_PLATFORMS AND SWIFTLIB_IS_SDK_OVERLAY)
set(swiftlib_swift_compile_private_frameworks_flag "-Fsystem" "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}/System/Library/PrivateFrameworks/")
foreach(tbd_lib ${SWIFTLIB_SWIFT_MODULE_DEPENDS_FROM_SDK})
list(APPEND swiftlib_link_flags_all "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}/usr/lib/swift/libswift${tbd_lib}.tbd")
Expand Down Expand Up @@ -2066,8 +2066,7 @@ function(add_swift_target_library name)
endif()
endif()

if((sdk IN_LIST SWIFT_APPLE_PLATFORMS)
OR (sdk STREQUAL "FREESTANDING"))
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS)
# In the past, we relied on unsetting globally
# CMAKE_OSX_ARCHITECTURES to ensure that CMake would
# not add the -arch flag
Expand Down Expand Up @@ -2174,7 +2173,7 @@ function(add_swift_target_library name)
endif()

set(optional_arg)
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS)
if(sdk IN_LIST SWIFT_DARWIN_PLATFORMS)
# Allow installation of stdlib without building all variants on Darwin.
set(optional_arg "OPTIONAL")
endif()
Expand Down Expand Up @@ -2434,7 +2433,7 @@ function(_add_swift_target_executable_single name)
if (SWIFT_PARALLEL_LINK_JOBS)
set_property(TARGET ${name} PROPERTY JOB_POOL_LINK swift_link_job_pool)
endif()
if(${SWIFTEXE_SINGLE_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
if(${SWIFTEXE_SINGLE_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)
set_target_properties(${name} PROPERTIES
BUILD_WITH_INSTALL_RPATH YES
INSTALL_RPATH "@executable_path/../lib/swift/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}")
Expand Down Expand Up @@ -2516,8 +2515,7 @@ function(add_swift_target_executable name)
EXCLUDE_FROM_ALL TRUE)
endif()

if((${sdk} IN_LIST SWIFT_APPLE_PLATFORMS)
OR (sdk STREQUAL "FREESTANDING"))
if(${sdk} IN_LIST SWIFT_APPLE_PLATFORMS)
# In the past, we relied on unsetting globally
# CMAKE_OSX_ARCHITECTURES to ensure that CMake would
# not add the -arch flag
Expand Down
8 changes: 4 additions & 4 deletions stdlib/cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function(handle_swift_sources
# FIXME: We shouldn't /have/ to build things in a single process.
# <rdar://problem/15972329>
list(APPEND swift_compile_flags "-whole-module-optimization")
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS OR sdk STREQUAL "MACCATALYST")
if(sdk IN_LIST SWIFT_DARWIN_PLATFORMS OR sdk STREQUAL "MACCATALYST")
list(APPEND swift_compile_flags "-save-optimization-record=bitstream")
endif()
if (SWIFTSOURCES_ENABLE_LTO)
Expand Down Expand Up @@ -218,7 +218,7 @@ function(_add_target_variant_swift_compile_flags
list(APPEND result "-sdk" "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}")
endif()

if("${sdk}" IN_LIST SWIFT_APPLE_PLATFORMS)
if("${sdk}" IN_LIST SWIFT_DARWIN_PLATFORMS)
set(sdk_deployment_version "${SWIFT_SDK_${sdk}_DEPLOYMENT_VERSION}")
get_target_triple(target target_variant "${sdk}" "${arch}"
MACCATALYST_BUILD_FLAVOR "${VARIANT_MACCATALYST_BUILD_FLAVOR}"
Expand All @@ -237,7 +237,7 @@ function(_add_target_variant_swift_compile_flags
list(APPEND result "-resource-dir" "${SWIFTLIB_DIR}")
endif()

if("${sdk}" IN_LIST SWIFT_APPLE_PLATFORMS)
if("${sdk}" IN_LIST SWIFT_DARWIN_PLATFORMS)
# We collate -F with the framework path to avoid unwanted deduplication
# of options by target_compile_options -- this way no undesired
# side effects are introduced should a new search path be added.
Expand Down Expand Up @@ -543,7 +543,7 @@ function(_compile_swift_files
endif()

set(optional_arg)
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS OR
if(SWIFTFILE_SDK IN_LIST SWIFT_DARWIN_PLATFORMS OR
SWIFTFILE_SDK STREQUAL "MACCATALYST")
# Allow installation of stdlib without building all variants on Darwin.
set(optional_arg "OPTIONAL")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ set(swift_core_link_flags "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}")
set(swift_core_framework_depends)
set(swift_core_private_link_libraries)
set(swift_stdlib_compile_flags "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}")
if(SWIFT_PRIMARY_VARIANT_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
if(SWIFT_PRIMARY_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
list(APPEND swift_core_link_flags "-all_load")
list(APPEND swift_core_private_link_libraries icucore)
else()
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/stubs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ add_swift_target_library(swiftStdlibStubs
INSTALL_IN_COMPONENT
stdlib)

if("${SWIFT_PRIMARY_VARIANT_SDK}" IN_LIST SWIFT_APPLE_PLATFORMS)
if("${SWIFT_PRIMARY_VARIANT_SDK}" IN_LIST SWIFT_DARWIN_PLATFORMS)
set_property(SOURCE
SwiftNativeNSXXXBaseARC.m
APPEND_STRING PROPERTY COMPILE_FLAGS
Expand Down
2 changes: 1 addition & 1 deletion stdlib/toolchain/Compatibility50/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_swift_target_library("${library_name}" STATIC
ProtocolConformance.cpp
Overrides.cpp

TARGET_SDKS ${SWIFT_APPLE_PLATFORMS}
TARGET_SDKS ${SWIFT_DARWIN_PLATFORMS}

C_COMPILE_FLAGS ${CXX_COMPILE_FLAGS}
LINK_FLAGS ${CXX_LINK_FLAGS}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/toolchain/Compatibility51/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_swift_target_library("${library_name}" STATIC
Overrides.cpp
ProtocolConformance.cpp

TARGET_SDKS ${SWIFT_APPLE_PLATFORMS}
TARGET_SDKS ${SWIFT_DARWIN_PLATFORMS}

C_COMPILE_FLAGS ${CXX_COMPILE_FLAGS}
LINK_FLAGS ${CXX_LINK_FLAGS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(library_name "swiftCompatibilityDynamicReplacements")
add_swift_target_library("${library_name}" STATIC
DynamicReplaceable.cpp

TARGET_SDKS ${SWIFT_APPLE_PLATFORMS}
TARGET_SDKS ${SWIFT_DARWIN_PLATFORMS}

C_COMPILE_FLAGS ${CXX_COMPILE_FLAGS}
LINK_FLAGS ${CXX_LINK_FLAGS}
Expand Down
2 changes: 1 addition & 1 deletion unittests/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
swift_Concurrency${SWIFT_PRIMARY_VARIANT_SUFFIX}
)

if(NOT "${SWIFT_PRIMARY_VARIANT_SDK}" IN_LIST SWIFT_APPLE_PLATFORMS)
if(NOT "${SWIFT_PRIMARY_VARIANT_SDK}" IN_LIST SWIFT_DARWIN_PLATFORMS)
list(APPEND PLATFORM_TARGET_LINK_LIBRARIES
dispatch${SWIFT_PRIMARY_VARIANT_SUFFIX}
BlocksRuntime${SWIFT_PRIMARY_VARIANT_SUFFIX}
Expand Down