Skip to content

Commit 750ba09

Browse files
authored
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) (swiftlang#34450)
1 parent 949c137 commit 750ba09

File tree

9 files changed

+38
-10
lines changed

9 files changed

+38
-10
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,12 @@ if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "LINUX")
744744
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
745745
endif()
746746

747+
is_sdk_requested(FREESTANDING swift_build_freestanding)
748+
if(swift_build_freestanding AND (SWIFT_FREESTANDING_FLAVOR STREQUAL "linux"))
749+
# TODO
750+
# configure_sdk_unix("FREESTANDING" "${SWIFT_HOST_VARIANT_ARCH}")
751+
endif()
752+
747753
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "FREEBSD")
748754

749755
set(SWIFT_HOST_VARIANT "freebsd" CACHE STRING

cmake/modules/DarwinSDKs.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if(swift_build_osx)
2727
endif()
2828

2929
is_sdk_requested(FREESTANDING swift_build_freestanding)
30-
if(swift_build_freestanding)
30+
if(swift_build_freestanding AND (SWIFT_FREESTANDING_FLAVOR STREQUAL "apple"))
3131
set(SWIFT_FREESTANDING_SDK "" CACHE STRING
3232
"Which SDK to use when building the FREESTANDING stdlib")
3333
set(SWIFT_FREESTANDING_TRIPLE_NAME "" CACHE STRING
@@ -45,6 +45,8 @@ if(swift_build_freestanding)
4545
configure_target_variant(FREESTANDING-RA "FREESTANDING Release+Asserts" FREESTANDING RA "Release+Asserts")
4646
configure_target_variant(FREESTANDING-R "FREESTANDING Release" FREESTANDING R "Release")
4747
configure_target_variant(FREESTANDING-S "FREESTANDING MinSizeRelease" FREESTANDING S "MinSizeRelease")
48+
49+
set(SWIFT_FREESTANDING_TEST_DEPENDENCIES "Darwin")
4850
endif()
4951

5052
# Compatible cross-compile SDKS for Darwin OSes: IOS, IOS_SIMULATOR, TVOS,

stdlib/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ option(SWIFT_BUILD_TEST_SUPPORT_MODULES
7979
"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."
8080
"${SWIFT_BUILD_TEST_SUPPORT_MODULES_default}")
8181

82+
option(SWIFT_FREESTANDING_FLAVOR
83+
"When building the FREESTANDING stdlib, which build style to use (options: apple, linux)")
84+
8285
set(SWIFT_STDLIB_ENABLE_LTO OFF CACHE STRING "Build Swift stdlib with LTO. One
8386
must specify the form of LTO by setting this to one of: 'full', 'thin'. This
8487
option only affects the standard library and runtime, not tools.")

stdlib/private/StdlibUnittest/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ add_swift_target_library(swiftStdlibUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
4646
SWIFT_MODULE_DEPENDS_OSX Darwin
4747
SWIFT_MODULE_DEPENDS_TVOS Darwin
4848
SWIFT_MODULE_DEPENDS_WATCHOS Darwin
49-
SWIFT_MODULE_DEPENDS_FREESTANDING Darwin
49+
SWIFT_MODULE_DEPENDS_FREESTANDING "${SWIFT_FREESTANDING_TEST_DEPENDENCIES}"
5050
SWIFT_MODULE_DEPENDS_LINUX Glibc
5151
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
5252
SWIFT_MODULE_DEPENDS_OPENBSD Glibc

stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ add_swift_target_library(swiftSwiftPrivateLibcExtras ${SWIFT_STDLIB_LIBRARY_BUIL
1313
SWIFT_MODULE_DEPENDS_IOS Darwin
1414
SWIFT_MODULE_DEPENDS_TVOS Darwin
1515
SWIFT_MODULE_DEPENDS_WATCHOS Darwin
16-
SWIFT_MODULE_DEPENDS_FREESTANDING Darwin
16+
SWIFT_MODULE_DEPENDS_FREESTANDING "${SWIFT_FREESTANDING_TEST_DEPENDENCIES}"
1717
SWIFT_MODULE_DEPENDS_LINUX Glibc
1818
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
1919
SWIFT_MODULE_DEPENDS_OPENBSD Glibc

stdlib/private/SwiftPrivateThreadExtras/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ add_swift_target_library(swiftSwiftPrivateThreadExtras ${SWIFT_STDLIB_LIBRARY_BU
1010
SWIFT_MODULE_DEPENDS_OSX Darwin
1111
SWIFT_MODULE_DEPENDS_TVOS Darwin
1212
SWIFT_MODULE_DEPENDS_WATCHOS Darwin
13-
SWIFT_MODULE_DEPENDS_FREESTANDING Darwin
13+
SWIFT_MODULE_DEPENDS_FREESTANDING "${SWIFT_FREESTANDING_TEST_DEPENDENCIES}"
1414
SWIFT_MODULE_DEPENDS_LINUX Glibc
1515
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
1616
SWIFT_MODULE_DEPENDS_OPENBSD Glibc

stdlib/public/Platform/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ if(NOT BUILD_STANDALONE)
1111
list(APPEND darwin_depends copy_apinotes)
1212
endif()
1313

14+
set(swiftDarwin_target_sdks ALL_APPLE_PLATFORMS)
15+
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "apple")
16+
set(swiftDarwin_target_sdks ALL_APPLE_PLATFORMS FREESTANDING)
17+
endif()
1418
add_swift_target_library(swiftDarwin ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
1519
${swift_platform_sources}
1620
POSIXError.swift
@@ -27,11 +31,15 @@ add_swift_target_library(swiftDarwin ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_
2731
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
2832
-Xfrontend -disable-objc-attr-requires-foundation-module
2933
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
30-
TARGET_SDKS ALL_APPLE_PLATFORMS FREESTANDING
34+
TARGET_SDKS "${swiftDarwin_target_sdks}"
3135
INSTALL_IN_COMPONENT sdk-overlay
3236

3337
DEPENDS ${darwin_depends})
3438

39+
set(swiftGlibc_target_sdks ANDROID CYGWIN FREEBSD OPENBSD LINUX HAIKU)
40+
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "linux")
41+
set(swiftGlibc_target_sdks ANDROID CYGWIN FREEBSD OPENBSD LINUX HAIKU FREESTANDING)
42+
endif()
3543
add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
3644
${swift_platform_sources}
3745
POSIXError.swift
@@ -44,7 +52,7 @@ add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_O
4452
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
4553
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
4654
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
47-
TARGET_SDKS ANDROID CYGWIN FREEBSD OPENBSD LINUX HAIKU
55+
TARGET_SDKS "${swiftGlibc_target_sdks}"
4856
INSTALL_IN_COMPONENT sdk-overlay
4957
DEPENDS glibc_modulemap)
5058

utils/build-presets.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,7 @@ mixin-preset=
24432443
stdlib-deployment-targets=freestanding-x86_64
24442444
swift-primary-variant-sdk=FREESTANDING
24452445
swift-primary-variant-arch=x86_64
2446+
swift-freestanding-flavor=apple
24462447
swift-freestanding-sdk=macosx
24472448
# For now, until clang/swiftc works correctly with "none-macho" as the OS part of target triple.
24482449
swift-freestanding-triple-name=macosx11.0

utils/build-script-impl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ KNOWN_SETTINGS=(
207207
common-swift-flags "" "Flags used for Swift targets other than the stdlib, like the corelibs"
208208

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

215216
## Uncategorised
216217
install-prefix "" "installation prefix"
@@ -2072,6 +2073,13 @@ for host in "${ALL_HOSTS[@]}"; do
20722073
)
20732074
fi
20742075

2076+
if [ "${SWIFT_FREESTANDING_FLAVOR}" ] ; then
2077+
cmake_options=(
2078+
"${cmake_options[@]}"
2079+
-DSWIFT_FREESTANDING_FLAVOR:STRING="${SWIFT_FREESTANDING_FLAVOR}"
2080+
)
2081+
fi
2082+
20752083
if [ "${SWIFT_FREESTANDING_SDK}" ] ; then
20762084
cmake_options=(
20772085
"${cmake_options[@]}"

0 commit comments

Comments
 (0)