Skip to content

Commit 0bebd9d

Browse files
committed
CMake: Runtime: Extract runtime version number
This extracts the version number computation out into a separate module to be shared between the runtimes. Setting `SWIFT_RUNTIME_VERSION` allows external build orchestration tools to override the version number specified in source if necessary, while centralizing the location of the default version number across the runtime libraries.
1 parent e26e2a6 commit 0bebd9d

File tree

9 files changed

+73
-68
lines changed

9 files changed

+73
-68
lines changed

Runtimes/Core/CMakeLists.txt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,16 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
4343
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
4444

4545
set(SwiftCore_CMAKE_MODULES_DIR "${CMAKE_SOURCE_DIR}/cmake/modules")
46-
list(APPEND CMAKE_MODULE_PATH ${SwiftCore_CMAKE_MODULES_DIR})
46+
list(APPEND CMAKE_MODULE_PATH
47+
${SwiftCore_CMAKE_MODULES_DIR}
48+
"${CMAKE_SOURCE_DIR}/../cmake/modules")
4749

4850
include(CMakeWorkarounds)
49-
# NOTE: always use the 3-component style as the expansion as
50-
# `${PROJECT_VERSION}` will not extend this to the complete form and this can
51-
# change the behaviour for comparison with non-SemVer compliant parsing. If
52-
# possible, use the 4-version component as that is used to differentiate the
53-
# builds of the runtime for Windows.
54-
if($ENV{BUILD_NUMBER})
55-
# NOTE: SxS modules have a limit on each component being [0-65535].
56-
# https://learn.microsoft.com/en-us/windows/win32/sbscs/assembly-versions
57-
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
58-
set(BUILD_NUMBER ".${BUILD_NUMBER}")
59-
endif()
51+
52+
include(SwiftProjectVersion)
6053
project(SwiftCore
6154
LANGUAGES C CXX Swift
62-
VERSION 6.3.0${BUILD_NUMBER})
55+
VERSION ${SWIFT_RUNTIME_VERSION})
6356

6457
# The Swift standard library is not intended for use as a sub-library as part of
6558
# another project. It is tightly coupled with the compiler version.

Runtimes/Overlay/CMakeLists.txt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,18 @@ set(CMAKE_C_VISIBILITY_PRESET "hidden")
1010
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
1111
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
1212

13-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
13+
list(APPEND CMAKE_MODULE_PATH
14+
"${CMAKE_SOURCE_DIR}/cmake/modules"
15+
"${CMAKE_SOURCE_DIR}/../cmake/modules")
1416

1517
if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER)
1618
cmake_policy(SET CMP0157 OLD)
1719
endif()
1820

19-
# NOTE: always use the 3-component style as the expansion as
20-
# `${PROJECT_VERSION}` will not extend this to the complete form and this can
21-
# change the behaviour for comparison with non-SemVer compliant parsing. If
22-
# possible, use the 4-version component as that is used to differentiate the
23-
# builds of the runtime for Windows.
24-
if($ENV{BUILD_NUMBER})
25-
# NOTE: SxS modules have a limit on each component being [0-65535].
26-
# https://learn.microsoft.com/en-us/windows/win32/sbscs/assembly-versions
27-
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
28-
set(BUILD_NUMBER ".${BUILD_NUMBER}")
29-
endif()
21+
include(SwiftProjectVersion)
3022
project(SwiftOverlay
3123
LANGUAGES C CXX Swift
32-
VERSION 6.3.0${BUILD_NUMBER})
24+
VERSION ${SWIFT_RUNTIME_VERSION})
3325

3426
set(CMAKE_Swift_LANGUAGE_VERSION 5)
3527

Runtimes/Supplemental/Differentiation/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER)
99
cmake_policy(SET CMP0157 OLD)
1010
endif()
1111

12-
if($ENV{BUILD_NUMBER})
13-
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
14-
set(BUILD_NUMBER ".${BUILD_NUMBER}")
15-
endif()
12+
list(APPEND CMAKE_MODULE_PATH
13+
"${CMAKE_SOURCE_DIR}/../cmake/modules"
14+
"${CMAKE_SOURCE_DIR}/../../cmake/modules")
15+
16+
include(SwiftProjectVersion)
1617
project(SwiftDifferentiation
1718
LANGUAGES Swift C
18-
VERSION 6.3.0${BUILD_NUMBER})
19+
VERSION ${SWIFT_RUNTIME_VERSION})
1920

2021
if(NOT PROJECT_IS_TOP_LEVEL)
2122
message(SEND_ERROR "Swift Differentiation must build as a standalone project")
@@ -24,8 +25,6 @@ endif()
2425
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
2526
set(CMAKE_Swift_LANGUAGE_VERSION 5)
2627

27-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules")
28-
2928
set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR
3029
"${PROJECT_SOURCE_DIR}/../../../"
3130
CACHE FILEPATH "Path to the root source directory of the Swift compiler")

Runtimes/Supplemental/Distributed/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER)
99
cmake_policy(SET CMP0157 OLD)
1010
endif()
1111

12-
if($ENV{BUILD_NUMBER})
13-
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
14-
set(BUILD_NUMBER ".${BUILD_NUMBER}")
15-
endif()
12+
list(APPEND CMAKE_MODULE_PATH
13+
"${CMAKE_SOURCE_DIR}/../cmake/modules"
14+
"${CMAKE_SOURCE_DIR}/../../cmake/modules")
15+
16+
include(SwiftProjectVersion)
1617
project(SwiftDistributed
1718
LANGUAGES C CXX Swift
18-
VERSION 6.3.0${BUILD_NUMBER})
19+
VERSION ${SWIFT_RUNTIME_VERSION})
1920

2021
if(NOT PROJECT_IS_TOP_LEVEL)
2122
message(SEND_ERROR "Swift Distributed must build as a standalone project")
@@ -34,8 +35,6 @@ set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
3435

3536
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
3637

37-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules")
38-
3938
set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR
4039
"${PROJECT_SOURCE_DIR}/../../../"
4140
CACHE FILEPATH "Path to the root source directory of the Swift compiler")

Runtimes/Supplemental/Observation/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER)
99
cmake_policy(SET CMP0157 OLD)
1010
endif()
1111

12-
if($ENV{BUILD_NUMBER})
13-
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
14-
set(BUILD_NUMBER ".${BUILD_NUMBER}")
15-
endif()
12+
list(APPEND CMAKE_MODULE_PATH
13+
"${CMAKE_SOURCE_DIR}/../cmake/modules"
14+
"${CMAKE_SOURCE_DIR}/../../cmake/modules")
15+
16+
include(SwiftProjectVersion)
1617
project(SwiftObservation
1718
LANGUAGES Swift CXX
18-
VERSION 6.3.0${BUILD_NUMBER})
19+
VERSION ${SWIFT_RUNTIME_VERSION})
1920

2021
if(NOT PROJECT_IS_TOP_LEVEL)
2122
message(SEND_ERROR "Swift Observation must build as a standalone project")
@@ -26,8 +27,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES)
2627
set(CMAKE_CXX_EXTENSIONS NO)
2728
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
2829

29-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules")
30-
3130
set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR
3231
"${PROJECT_SOURCE_DIR}/../../../"
3332
CACHE FILEPATH "Path to the root source directory of the Swift compiler")

Runtimes/Supplemental/StringProcessing/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER)
99
cmake_policy(SET CMP0157 OLD)
1010
endif()
1111

12-
if($ENV{BUILD_NUMBER})
13-
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
14-
set(BUILD_NUMBER ".${BUILD_NUMBER}")
15-
endif()
12+
13+
list(APPEND CMAKE_MODULE_PATH
14+
"${CMAKE_SOURCE_DIR}/../cmake/modules"
15+
"${CMAKE_SOURCE_DIR}/../../cmake/modules")
16+
17+
include(SwiftProjectVersion)
1618
project(SwiftStringProcessing
1719
LANGUAGES Swift C
18-
VERSION 6.3.0${BUILD_NUMBER})
20+
VERSION ${SWIFT_RUNTIME_VERSION})
1921

2022
if(NOT PROJECT_IS_TOP_LEVEL)
2123
message(FATAL_ERROR "Swift StringProcessing must build as a standalone project")
2224
endif()
2325

2426
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
2527

26-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules")
27-
2828
set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR
2929
"${PROJECT_SOURCE_DIR}/../../../"
3030
CACHE FILEPATH "Path to the root source directory of the Swift compiler")

Runtimes/Supplemental/Synchronization/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER)
99
cmake_policy(SET CMP0157 OLD)
1010
endif()
1111

12-
if($ENV{BUILD_NUMBER})
13-
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
14-
set(BUILD_NUMBER ".${BUILD_NUMBER}")
15-
endif()
12+
list(APPEND CMAKE_MODULE_PATH
13+
"${CMAKE_SOURCE_DIR}/../cmake/modules"
14+
"${CMAKE_SOURCE_DIR}/../../cmake/modules")
15+
16+
include(SwiftProjectVersion)
1617
project(SwiftSynchronization
1718
LANGUAGES Swift
18-
VERSION 6.3.0${BUILD_NUMBER})
19+
VERSION ${SWIFT_RUNTIME_VERSION})
20+
1921
# FIXME(compnerd) this is a workaround for `GNUInstallDirs` which cannot be used
2022
# with a pure Swift project.
2123
enable_language(C)
@@ -26,8 +28,6 @@ endif()
2628

2729
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
2830

29-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules")
30-
3131
set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR
3232
"${PROJECT_SOURCE_DIR}/../../../"
3333
CACHE FILEPATH "Path to the root source directory of the Swift compiler")

Runtimes/Supplemental/Volatile/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER)
99
cmake_policy(SET CMP0157 OLD)
1010
endif()
1111

12-
if($ENV{BUILD_NUMBER})
13-
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
14-
set(BUILD_NUMBER ".${BUILD_NUMBER}")
15-
endif()
12+
list(APPEND CMAKE_MODULE_PATH
13+
"${CMAKE_SOURCE_DIR}/../cmake/modules"
14+
"${CMAKE_SOURCE_DIR}/../../cmake/modules")
15+
16+
include(SwiftProjectVersion)
1617
project(SwiftVolatile
1718
LANGUAGES Swift
18-
VERSION 6.3.0${BUILD_NUMBER})
19+
VERSION ${SWIFT_RUNTIME_VERSION})
20+
1921
# FIXME(compnerd) this is a workaround for `GNUInstallDirs` which cannot be used
2022
# with a pure Swift project.
2123
enable_language(C)
@@ -24,8 +26,6 @@ if(NOT PROJECT_IS_TOP_LEVEL)
2426
message(SEND_ERROR "Swift Observation must build as a standalone project")
2527
endif()
2628

27-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules")
28-
2929
set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR
3030
"${PROJECT_SOURCE_DIR}/../../../"
3131
CACHE FILEPATH "Path to the root source directory of the Swift compiler")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This module sets the Swift version number variable consistently across the
2+
# Swift runtime projects.
3+
4+
## Result Variable
5+
#
6+
# ``SWIFT_RUNTIME_VERSION``
7+
# The computed version number applied to apply to the project.
8+
# If ``SWIFT_RUNTIME_VERSION`` is set prior to entering the module, the version
9+
# is not modified.
10+
11+
block(PROPAGATE SWIFT_RUNTIME_VERSION)
12+
if(SWIFT_RUNTIME_VERSION)
13+
return()
14+
endif()
15+
16+
if($ENV{BUILD_NUMBER})
17+
# Microsoft build numbers limit each version number component to [0 - 65535]
18+
# https://learn.microsoft.com/en-us/windows/win32/sbscs/assembly-versions
19+
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
20+
set(BUILD_NUMBER ".${BUILD_NUMBER}")
21+
endif()
22+
set(SWIFT_RUNTIME_VERSION 6.3.0${BUILD_NUMBER})
23+
endblock()

0 commit comments

Comments
 (0)