Skip to content

Commit 58f2ae6

Browse files
authored
Add a SWIFT_STDLIB_STABLE_ABI flag to be able to build the stdlib without -enable-library-evolution (swiftlang#33443)
1 parent 6ef4b0d commit 58f2ae6

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,6 @@ set(SWIFT_NATIVE_CLANG_TOOLS_PATH "" CACHE STRING
242242
set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "" CACHE STRING
243243
"Path to the directory that contains Swift tools that are executable on the build machine")
244244

245-
option(SWIFT_ENABLE_MODULE_INTERFACES
246-
"Generate .swiftinterface files alongside .swiftmodule files"
247-
TRUE)
248-
249245
option(SWIFT_STDLIB_ENABLE_SIB_TARGETS
250246
"Should we generate sib targets for the stdlib or not?"
251247
FALSE)

stdlib/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,43 @@ project(swift-stdlib LANGUAGES C CXX)
99
list(APPEND CMAKE_MODULE_PATH
1010
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
1111

12+
if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "OSX")
13+
# All Darwin platforms have ABI stability.
14+
set(SWIFT_STDLIB_STABLE_ABI_default TRUE)
15+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "LINUX")
16+
# TODO(mracek): This should get turned off, as this is not an ABI stable platform.
17+
set(SWIFT_STDLIB_STABLE_ABI_default TRUE)
18+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "FREEBSD")
19+
# TODO(mracek): This should get turned off, as this is not an ABI stable platform.
20+
set(SWIFT_STDLIB_STABLE_ABI_default TRUE)
21+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "OPENBSD")
22+
# TODO(mracek): This should get turned off, as this is not an ABI stable platform.
23+
set(SWIFT_STDLIB_STABLE_ABI_default TRUE)
24+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "CYGWIN")
25+
# TODO(mracek): This should get turned off, as this is not an ABI stable platform.
26+
set(SWIFT_STDLIB_STABLE_ABI_default TRUE)
27+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WINDOWS")
28+
# TODO(mracek): This should get turned off, as this is not an ABI stable platform.
29+
set(SWIFT_STDLIB_STABLE_ABI_default TRUE)
30+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "HAIKU")
31+
# TODO(mracek): This should get turned off, as this is not an ABI stable platform.
32+
set(SWIFT_STDLIB_STABLE_ABI_default TRUE)
33+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "ANDROID")
34+
# TODO(mracek): This should get turned off, as this is not an ABI stable platform.
35+
set(SWIFT_STDLIB_STABLE_ABI_default TRUE)
36+
else()
37+
# Any new platform should have non-stable ABI to start with.
38+
set(SWIFT_STDLIB_STABLE_ABI_default FALSE)
39+
endif()
40+
1241
#
1342
# User-configurable options for the standard library.
1443
#
1544

45+
option(SWIFT_STDLIB_STABLE_ABI
46+
"Should stdlib be built with stable ABI (library evolution, resilience)."
47+
"${SWIFT_STDLIB_STABLE_ABI_default}")
48+
1649
option(SWIFT_ENABLE_COMPATIBILITY_OVERRIDES
1750
"Support back-deploying compatibility fixes for newer apps running on older runtimes."
1851
TRUE)
@@ -29,6 +62,10 @@ option(SWIFT_STDLIB_OS_VERSIONING
2962
"Build stdlib with availability based on OS versions (Darwin only)."
3063
TRUE)
3164

65+
option(SWIFT_ENABLE_MODULE_INTERFACES
66+
"Generate .swiftinterface files alongside .swiftmodule files"
67+
"${SWIFT_STDLIB_STABLE_ABI}")
68+
3269
#
3370
# End of user-configurable options.
3471
#

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,11 @@ function(_add_target_variant_c_compile_flags)
318318
list(APPEND result "-DSWIFT_OBJC_INTEROP=0")
319319
endif()
320320

321-
# TODO(mracek): This should get turned off for non-ABI-stable environments.
322-
list(APPEND result "-DSWIFT_LIBRARY_EVOLUTION=1")
321+
if(SWIFT_STDLIB_STABLE_ABI)
322+
list(APPEND result "-DSWIFT_LIBRARY_EVOLUTION=1")
323+
else()
324+
list(APPEND result "-DSWIFT_LIBRARY_EVOLUTION=0")
325+
endif()
323326

324327
if(NOT SWIFT_ENABLE_COMPATIBILITY_OVERRIDES)
325328
list(APPEND result "-DSWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES")

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ function(_compile_swift_files
399399
list(APPEND swift_flags "-Xfrontend" "-sil-verify-all")
400400
endif()
401401

402-
# The standard library and overlays are always built resiliently.
403-
if(SWIFTFILE_IS_STDLIB)
402+
# The standard library and overlays are built resiliently when SWIFT_STDLIB_STABLE_ABI=On.
403+
if(SWIFTFILE_IS_STDLIB AND SWIFT_STDLIB_STABLE_ABI)
404404
list(APPEND swift_flags "-enable-library-evolution")
405405
endif()
406406

utils/build-script-impl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ KNOWN_SETTINGS=(
197197
swift-runtime-macho-no-dyld "0" "whether to build stdlib assuming the runtime environment does not support dynamic modules"
198198
swift-stdlib-single-threaded-runtime "0" "whether to build stdlib as a single-threaded runtime only"
199199
swift-stdlib-os-versioning "1" "whether to build stdlib with availability based on OS versions (Darwin only)"
200+
swift-stdlib-stable-abi "" "should stdlib be built with stable ABI, if not set defaults to true on Darwin, false otherwise"
200201

201202
## FREESTANDING Stdlib Options
202203
swift-freestanding-sdk "" "which SDK to use when building the FREESTANDING stdlib"
@@ -1872,6 +1873,13 @@ for host in "${ALL_HOSTS[@]}"; do
18721873
)
18731874
fi
18741875

1876+
if [[ "${SWIFT_STDLIB_STABLE_ABI}" ]] ; then
1877+
cmake_options=(
1878+
"${cmake_options[@]}"
1879+
-DSWIFT_STDLIB_STABLE_ABI:BOOL=$(true_false "${SWIFT_STDLIB_STABLE_ABI}")
1880+
)
1881+
fi
1882+
18751883
if [ "${SWIFT_INSTALL_COMPONENTS}" ] ; then
18761884
cmake_options=(
18771885
"${cmake_options[@]}"

0 commit comments

Comments
 (0)