From cd2a7b354b5619d360d3e623b5cc1abbd8722dd2 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Thu, 25 Sep 2025 17:14:41 -0700 Subject: [PATCH 1/2] CMake: Set language version across supplemental libs The Swift language version appears in the Swift interface and impacts how the interface is handled by the compiler when importing the module. The version only appears if it is set, which means that downstream projects setting the version explicitly may interpret the swift interface file differently. This also factors the setting out into a separate file, which is used to set the C++ standard and Swift language version since it is the same across these libraries at this time. If this assumption changes, we can refactor as necessary and this structure shouldn't be seen as enforcement. Finally, this patch moves setting the language version and standard variables before the languages are enabled. This ensures that the try-compile applies the appropriate flags when verifying that the compiler works. --- Runtimes/Supplemental/Distributed/CMakeLists.txt | 8 +------- Runtimes/Supplemental/Observation/CMakeLists.txt | 4 +--- Runtimes/Supplemental/StringProcessing/CMakeLists.txt | 1 + Runtimes/Supplemental/Synchronization/CMakeLists.txt | 1 + Runtimes/Supplemental/Volatile/CMakeLists.txt | 1 + .../Supplemental/cmake/modules/LanguageVersions.cmake | 5 +++++ 6 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 Runtimes/Supplemental/cmake/modules/LanguageVersions.cmake diff --git a/Runtimes/Supplemental/Distributed/CMakeLists.txt b/Runtimes/Supplemental/Distributed/CMakeLists.txt index 6bea6fa1cc292..5cee2147edefc 100644 --- a/Runtimes/Supplemental/Distributed/CMakeLists.txt +++ b/Runtimes/Supplemental/Distributed/CMakeLists.txt @@ -13,6 +13,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules" "${CMAKE_SOURCE_DIR}/../../cmake/modules") +include(LanguageVersions) include(SwiftProjectVersion) project(SwiftDistributed LANGUAGES C CXX Swift @@ -22,17 +23,10 @@ if(NOT PROJECT_IS_TOP_LEVEL) message(SEND_ERROR "Swift Distributed must build as a standalone project") endif() -set(CMAKE_Swift_LANGUAGE_VERSION 5) - set(CMAKE_POSITION_INDEPENDENT_CODE YES) set(CMAKE_C_VISIBILITY_PRESET "hidden") - -set(CMAKE_CXX_EXTENSIONS NO) -set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to") -set(CMAKE_CXX_STANDARD_REQUIRED YES) set(CMAKE_CXX_VISIBILITY_PRESET "hidden") - set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR diff --git a/Runtimes/Supplemental/Observation/CMakeLists.txt b/Runtimes/Supplemental/Observation/CMakeLists.txt index 59434af525484..a9445db63e4bb 100644 --- a/Runtimes/Supplemental/Observation/CMakeLists.txt +++ b/Runtimes/Supplemental/Observation/CMakeLists.txt @@ -13,6 +13,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules" "${CMAKE_SOURCE_DIR}/../../cmake/modules") +include(LanguageVersions) include(SwiftProjectVersion) project(SwiftObservation LANGUAGES Swift CXX @@ -22,9 +23,6 @@ if(NOT PROJECT_IS_TOP_LEVEL) message(SEND_ERROR "Swift Observation must build as a standalone project") endif() -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED YES) -set(CMAKE_CXX_EXTENSIONS NO) set(CMAKE_POSITION_INDEPENDENT_CODE YES) set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR diff --git a/Runtimes/Supplemental/StringProcessing/CMakeLists.txt b/Runtimes/Supplemental/StringProcessing/CMakeLists.txt index 756f170dc0127..fd2e0c9bf9f56 100644 --- a/Runtimes/Supplemental/StringProcessing/CMakeLists.txt +++ b/Runtimes/Supplemental/StringProcessing/CMakeLists.txt @@ -14,6 +14,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules" "${CMAKE_SOURCE_DIR}/../../cmake/modules") +include(LanguageVersions) include(SwiftProjectVersion) project(SwiftStringProcessing LANGUAGES Swift C diff --git a/Runtimes/Supplemental/Synchronization/CMakeLists.txt b/Runtimes/Supplemental/Synchronization/CMakeLists.txt index 327ab796a1065..6652da194ea30 100644 --- a/Runtimes/Supplemental/Synchronization/CMakeLists.txt +++ b/Runtimes/Supplemental/Synchronization/CMakeLists.txt @@ -13,6 +13,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules" "${CMAKE_SOURCE_DIR}/../../cmake/modules") +include(LanguageVersions) include(SwiftProjectVersion) project(SwiftSynchronization LANGUAGES Swift diff --git a/Runtimes/Supplemental/Volatile/CMakeLists.txt b/Runtimes/Supplemental/Volatile/CMakeLists.txt index 30261e1face46..b58ed460f3755 100644 --- a/Runtimes/Supplemental/Volatile/CMakeLists.txt +++ b/Runtimes/Supplemental/Volatile/CMakeLists.txt @@ -13,6 +13,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules" "${CMAKE_SOURCE_DIR}/../../cmake/modules") +include(LanguageVersions) include(SwiftProjectVersion) project(SwiftVolatile LANGUAGES Swift diff --git a/Runtimes/Supplemental/cmake/modules/LanguageVersions.cmake b/Runtimes/Supplemental/cmake/modules/LanguageVersions.cmake new file mode 100644 index 0000000000000..706661f229ac3 --- /dev/null +++ b/Runtimes/Supplemental/cmake/modules/LanguageVersions.cmake @@ -0,0 +1,5 @@ +set(CMAKE_Swift_LANGUAGE_VERSION 5) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED YES) +set(CMAKE_CXX_EXTENSIONS NO) From a0538ae7cb9b22925996fd058282792558efb33f Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Thu, 25 Sep 2025 19:15:19 -0700 Subject: [PATCH 2/2] Revert "CMake: Runtimes: Specify language mode explicitly." Reverting since we can use `CMAKE_Swift_LANGUAGE_VERSION` instead. This reverts commit 6cc9a7d50959f0d26cbf1e60741e075fa4c90a91. --- Runtimes/Core/CMakeLists.txt | 1 - Runtimes/Overlay/Cxx/CMakeLists.txt | 1 - Runtimes/Supplemental/Differentiation/CMakeLists.txt | 1 - Runtimes/Supplemental/Distributed/CMakeLists.txt | 1 - Runtimes/Supplemental/Observation/CMakeLists.txt | 1 - Runtimes/Supplemental/StringProcessing/CMakeLists.txt | 1 - Runtimes/Supplemental/Synchronization/CMakeLists.txt | 1 - Runtimes/Supplemental/Volatile/CMakeLists.txt | 1 - 8 files changed, 8 deletions(-) diff --git a/Runtimes/Core/CMakeLists.txt b/Runtimes/Core/CMakeLists.txt index ff1b35cd93e82..c255750512c31 100644 --- a/Runtimes/Core/CMakeLists.txt +++ b/Runtimes/Core/CMakeLists.txt @@ -181,7 +181,6 @@ add_link_options($<$:LINKER:-z,defs>) add_compile_options( $<$:-explicit-module-build> "$<$:-nostdlibimport>" - "$<$:SHELL:-swift-version 5>" "$<$:SHELL:-library-level api>" "$<$:SHELL:-runtime-compatibility-version none>" "$<$:-disable-autolinking-runtime-compatibility-dynamic-replacements>" diff --git a/Runtimes/Overlay/Cxx/CMakeLists.txt b/Runtimes/Overlay/Cxx/CMakeLists.txt index f6317d066fdc1..5f43f25409f7c 100644 --- a/Runtimes/Overlay/Cxx/CMakeLists.txt +++ b/Runtimes/Overlay/Cxx/CMakeLists.txt @@ -31,7 +31,6 @@ target_compile_options(swiftCxx PRIVATE # This module should not pull in the C++ standard library, so we disable it # explicitly. For functionality that depends on the C++ stdlib, use C++ # stdlib overlay (`swiftstd` module). - "$<$:SHELL:-swift-version 5>" "$<$:SHELL:-Xcc -nostdinc++>" "$<$:SHELL:-enable-experimental-feature AllowUnsafeAttribute>" "$<$:SHELL:-enable-experimental-feature BuiltinModule>" diff --git a/Runtimes/Supplemental/Differentiation/CMakeLists.txt b/Runtimes/Supplemental/Differentiation/CMakeLists.txt index a7491307fc652..20cc38a989fbd 100644 --- a/Runtimes/Supplemental/Differentiation/CMakeLists.txt +++ b/Runtimes/Supplemental/Differentiation/CMakeLists.txt @@ -66,7 +66,6 @@ add_compile_options( $<$:-explicit-module-build> $<$:-nostdlibimport> $<$:-parse-stdlib> - "$<$:SHELL:-swift-version 5>" "$<$:SHELL:-library-level api>" "$<$:SHELL:-enable-experimental-feature NoncopyableGenerics2>" "$<$:SHELL:-enable-experimental-feature SuppressedAssociatedTypes>" diff --git a/Runtimes/Supplemental/Distributed/CMakeLists.txt b/Runtimes/Supplemental/Distributed/CMakeLists.txt index 5cee2147edefc..140236c76d8ec 100644 --- a/Runtimes/Supplemental/Distributed/CMakeLists.txt +++ b/Runtimes/Supplemental/Distributed/CMakeLists.txt @@ -69,7 +69,6 @@ add_compile_options( $<$:-explicit-module-build> $<$:-nostdlibimport> $<$:-strict-memory-safety> - "$<$:SHELL:-swift-version 5>" "$<$:SHELL:-enable-experimental-feature NoncopyableGenerics2>" "$<$:SHELL:-enable-experimental-feature SuppressedAssociatedTypes>" "$<$:SHELL:-enable-experimental-feature SE427NoInferenceOnExtension>" diff --git a/Runtimes/Supplemental/Observation/CMakeLists.txt b/Runtimes/Supplemental/Observation/CMakeLists.txt index a9445db63e4bb..b008a71329a61 100644 --- a/Runtimes/Supplemental/Observation/CMakeLists.txt +++ b/Runtimes/Supplemental/Observation/CMakeLists.txt @@ -64,7 +64,6 @@ option(${PROJECT_NAME}_ENABLE_PRESPECIALIZATION "Enable generic metadata prespec add_compile_options( $<$:-explicit-module-build> $<$:-nostdlibimport> - "$<$:SHELL:-swift-version 5>" "$<$:SHELL:-Xfrontend -enforce-exclusivity=unchecked>" "$<$:SHELL:-Xfrontend -target-min-inlining-version -Xfrontend min>" "$<$:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>" diff --git a/Runtimes/Supplemental/StringProcessing/CMakeLists.txt b/Runtimes/Supplemental/StringProcessing/CMakeLists.txt index fd2e0c9bf9f56..c12ccddba7d0c 100644 --- a/Runtimes/Supplemental/StringProcessing/CMakeLists.txt +++ b/Runtimes/Supplemental/StringProcessing/CMakeLists.txt @@ -53,7 +53,6 @@ option(${PROJECT_NAME}_ENABLE_PRESPECIALIZATION "Enable generic metadata prespec add_compile_options( $<$:-explicit-module-build> $<$:-nostdlibimport> - "$<$:SHELL:-swift-version 5>" "$<$:SHELL:-Xfrontend -disable-implicit-concurrency-module-import>" "$<$:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>" "$<$:-warn-implicit-overrides>" diff --git a/Runtimes/Supplemental/Synchronization/CMakeLists.txt b/Runtimes/Supplemental/Synchronization/CMakeLists.txt index 6652da194ea30..7fa91fd9edbf8 100644 --- a/Runtimes/Supplemental/Synchronization/CMakeLists.txt +++ b/Runtimes/Supplemental/Synchronization/CMakeLists.txt @@ -72,7 +72,6 @@ add_compile_options( $<$:-nostdlibimport> $<$:-enable-builtin-module> $<$:-strict-memory-safety> - "$<$:SHELL:-swift-version 5>" "$<$:SHELL:-enable-experimental-feature NoncopyableGenerics2>" "$<$:SHELL:-enable-experimental-feature SuppressedAssociatedTypes>" "$<$:SHELL:-enable-experimental-feature SE427NoInferenceOnExtension>" diff --git a/Runtimes/Supplemental/Volatile/CMakeLists.txt b/Runtimes/Supplemental/Volatile/CMakeLists.txt index b58ed460f3755..e11b51d58fb82 100644 --- a/Runtimes/Supplemental/Volatile/CMakeLists.txt +++ b/Runtimes/Supplemental/Volatile/CMakeLists.txt @@ -67,7 +67,6 @@ add_compile_options( $<$:-explicit-module-build> $<$:-nostdlibimport> $<$:-strict-memory-safety> - "$<$:SHELL:-swift-version 5>" "$<$,$>:-enable-library-evolution>" "$<$,$>:SHELL:-Xfrontend -prespecialize-generic-metadata>")