Skip to content

Introduce SWIFT_FREESTANDING_FLAVOR to select whether the FREESTANDING stdlib should be built/tested using an Apple SDK, or another SDK (e.g. Linux, not implemented yet) #34450

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 1 commit into from
Aug 19, 2021
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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,12 @@ if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "LINUX")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
endif()

is_sdk_requested(FREESTANDING swift_build_freestanding)
if(swift_build_freestanding AND (SWIFT_FREESTANDING_FLAVOR STREQUAL "linux"))
# TODO
# configure_sdk_unix("FREESTANDING" "${SWIFT_HOST_VARIANT_ARCH}")
endif()

elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "FREEBSD")

set(SWIFT_HOST_VARIANT "freebsd" CACHE STRING
Expand Down
4 changes: 3 additions & 1 deletion cmake/modules/DarwinSDKs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if(swift_build_osx)
endif()

is_sdk_requested(FREESTANDING swift_build_freestanding)
if(swift_build_freestanding)
if(swift_build_freestanding AND (SWIFT_FREESTANDING_FLAVOR STREQUAL "apple"))
set(SWIFT_FREESTANDING_SDK "" CACHE STRING
"Which SDK to use when building the FREESTANDING stdlib")
set(SWIFT_FREESTANDING_TRIPLE_NAME "" CACHE STRING
Expand All @@ -45,6 +45,8 @@ if(swift_build_freestanding)
configure_target_variant(FREESTANDING-RA "FREESTANDING Release+Asserts" FREESTANDING RA "Release+Asserts")
configure_target_variant(FREESTANDING-R "FREESTANDING Release" FREESTANDING R "Release")
configure_target_variant(FREESTANDING-S "FREESTANDING MinSizeRelease" FREESTANDING S "MinSizeRelease")

set(SWIFT_FREESTANDING_TEST_DEPENDENCIES "Darwin")
endif()

# Compatible cross-compile SDKS for Darwin OSes: IOS, IOS_SIMULATOR, TVOS,
Expand Down
3 changes: 3 additions & 0 deletions stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ option(SWIFT_BUILD_TEST_SUPPORT_MODULES
"Whether to build StdlibUnittest and other test support modules. Defaults to On when SWIFT_BUILD_SDK_OVERLAY is On, or when SWIFT_INCLUDE_TESTS is On."
"${SWIFT_BUILD_TEST_SUPPORT_MODULES_default}")

option(SWIFT_FREESTANDING_FLAVOR
"When building the FREESTANDING stdlib, which build style to use (options: apple, linux)")

set(SWIFT_STDLIB_ENABLE_LTO OFF CACHE STRING "Build Swift stdlib with LTO. One
must specify the form of LTO by setting this to one of: 'full', 'thin'. This
option only affects the standard library and runtime, not tools.")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibUnittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ add_swift_target_library(swiftStdlibUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
SWIFT_MODULE_DEPENDS_OSX Darwin
SWIFT_MODULE_DEPENDS_TVOS Darwin
SWIFT_MODULE_DEPENDS_WATCHOS Darwin
SWIFT_MODULE_DEPENDS_FREESTANDING Darwin
SWIFT_MODULE_DEPENDS_FREESTANDING "${SWIFT_FREESTANDING_TEST_DEPENDENCIES}"
SWIFT_MODULE_DEPENDS_LINUX Glibc
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
SWIFT_MODULE_DEPENDS_OPENBSD Glibc
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ add_swift_target_library(swiftSwiftPrivateLibcExtras ${SWIFT_STDLIB_LIBRARY_BUIL
SWIFT_MODULE_DEPENDS_IOS Darwin
SWIFT_MODULE_DEPENDS_TVOS Darwin
SWIFT_MODULE_DEPENDS_WATCHOS Darwin
SWIFT_MODULE_DEPENDS_FREESTANDING Darwin
SWIFT_MODULE_DEPENDS_FREESTANDING "${SWIFT_FREESTANDING_TEST_DEPENDENCIES}"
SWIFT_MODULE_DEPENDS_LINUX Glibc
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
SWIFT_MODULE_DEPENDS_OPENBSD Glibc
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftPrivateThreadExtras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ add_swift_target_library(swiftSwiftPrivateThreadExtras ${SWIFT_STDLIB_LIBRARY_BU
SWIFT_MODULE_DEPENDS_OSX Darwin
SWIFT_MODULE_DEPENDS_TVOS Darwin
SWIFT_MODULE_DEPENDS_WATCHOS Darwin
SWIFT_MODULE_DEPENDS_FREESTANDING Darwin
SWIFT_MODULE_DEPENDS_FREESTANDING "${SWIFT_FREESTANDING_TEST_DEPENDENCIES}"
SWIFT_MODULE_DEPENDS_LINUX Glibc
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
SWIFT_MODULE_DEPENDS_OPENBSD Glibc
Expand Down
12 changes: 10 additions & 2 deletions stdlib/public/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ if(NOT BUILD_STANDALONE)
list(APPEND darwin_depends copy_apinotes)
endif()

set(swiftDarwin_target_sdks ALL_APPLE_PLATFORMS)
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "apple")
set(swiftDarwin_target_sdks ALL_APPLE_PLATFORMS FREESTANDING)
endif()
add_swift_target_library(swiftDarwin ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
${swift_platform_sources}
POSIXError.swift
Expand All @@ -27,11 +31,15 @@ add_swift_target_library(swiftDarwin ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
-Xfrontend -disable-objc-attr-requires-foundation-module
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS ALL_APPLE_PLATFORMS FREESTANDING
TARGET_SDKS "${swiftDarwin_target_sdks}"
INSTALL_IN_COMPONENT sdk-overlay

DEPENDS ${darwin_depends})

set(swiftGlibc_target_sdks ANDROID CYGWIN FREEBSD OPENBSD LINUX HAIKU)
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "linux")
set(swiftGlibc_target_sdks ANDROID CYGWIN FREEBSD OPENBSD LINUX HAIKU FREESTANDING)
endif()
add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
${swift_platform_sources}
POSIXError.swift
Expand All @@ -44,7 +52,7 @@ add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_O
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS ANDROID CYGWIN FREEBSD OPENBSD LINUX HAIKU
TARGET_SDKS "${swiftGlibc_target_sdks}"
INSTALL_IN_COMPONENT sdk-overlay
DEPENDS glibc_modulemap)

Expand Down
1 change: 1 addition & 0 deletions utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2442,6 +2442,7 @@ mixin-preset=
stdlib-deployment-targets=freestanding-x86_64
swift-primary-variant-sdk=FREESTANDING
swift-primary-variant-arch=x86_64
swift-freestanding-flavor=apple
swift-freestanding-sdk=macosx
# For now, until clang/swiftc works correctly with "none-macho" as the OS part of target triple.
swift-freestanding-triple-name=macosx11.0
Expand Down
16 changes: 12 additions & 4 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ KNOWN_SETTINGS=(
common-swift-flags "" "Flags used for Swift targets other than the stdlib, like the corelibs"

## FREESTANDING Stdlib Options
swift-freestanding-sdk "" "which SDK to use when building the FREESTANDING stdlib"
swift-freestanding-triple-name "" "which triple name (e.g. 'none-macho') to use when building the FREESTANDING stdlib"
swift-freestanding-module-name "" "which .swiftmodule name (e.g. 'freestanding') to use when building the FREESTANDING stdlib"
swift-freestanding-archs "" "space-separated list of which architectures to build when building the FREESTANDING stdlib"
swift-freestanding-flavor "" "when building the FREESTANDING stdlib, which build style to use (options: apple, linux)"
swift-freestanding-sdk "" "which SDK to use when building the FREESTANDING stdlib"
swift-freestanding-triple-name "" "which triple name (e.g. 'none-macho') to use when building the FREESTANDING stdlib"
swift-freestanding-module-name "" "which .swiftmodule name (e.g. 'freestanding') to use when building the FREESTANDING stdlib"
swift-freestanding-archs "" "space-separated list of which architectures to build when building the FREESTANDING stdlib"

## Uncategorised
install-prefix "" "installation prefix"
Expand Down Expand Up @@ -2072,6 +2073,13 @@ for host in "${ALL_HOSTS[@]}"; do
)
fi

if [ "${SWIFT_FREESTANDING_FLAVOR}" ] ; then
cmake_options=(
"${cmake_options[@]}"
-DSWIFT_FREESTANDING_FLAVOR:STRING="${SWIFT_FREESTANDING_FLAVOR}"
)
fi

if [ "${SWIFT_FREESTANDING_SDK}" ] ; then
cmake_options=(
"${cmake_options[@]}"
Expand Down