Skip to content

Commit c442763

Browse files
committed
Cache VCVARS variables for incremental building on Windows
The initial configure & generate of a build on Windows should have the necessary VCVARS set in the environment. After that, we should be incrementally building with those same vars to avoid conflicts between Windows SDKs. Cache these vars so that the same Windows SDKs are consistently used in future incremental builds.
1 parent b875dca commit c442763

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ include(SwiftAndroidSupport)
1212
function(_report_sdk prefix)
1313
message(STATUS "${SWIFT_SDK_${prefix}_NAME} SDK:")
1414
if("${prefix}" STREQUAL "WINDOWS")
15-
message(STATUS " UCRT Version: $ENV{UCRTVersion}")
16-
message(STATUS " UCRT SDK Dir: $ENV{UniversalCRTSdkDir}")
17-
message(STATUS " VC Dir: $ENV{VCToolsInstallDir}")
15+
message(STATUS " UCRT Version: ${UCRTVersion}")
16+
message(STATUS " UCRT SDK Dir: ${UniversalCRTSdkDir}")
17+
message(STATUS " VC Dir: ${VCToolsInstallDir}")
1818
if("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
1919
message(STATUS " ${CMAKE_BUILD_TYPE} VC++ CRT: MDd")
2020
else()
@@ -250,6 +250,8 @@ macro(configure_sdk_windows name environment architectures)
250250
# Note: this has to be implemented as a macro because it sets global
251251
# variables.
252252

253+
swift_windows_cache_VCVARS()
254+
253255
string(TOUPPER ${name} prefix)
254256
string(TOLOWER ${name} platform)
255257

@@ -274,10 +276,10 @@ macro(configure_sdk_windows name environment architectures)
274276
# NOTE(compnerd) workaround incorrectly extensioned import libraries from
275277
# the Windows SDK on case sensitive file systems.
276278
swift_windows_arch_spelling(${arch} WinSDKArchitecture)
277-
set(WinSDK${arch}UMDir "$ENV{UniversalCRTSdkDir}/Lib/$ENV{UCRTVersion}/um/${WinSDKArchitecture}")
279+
set(WinSDK${arch}UMDir "${UniversalCRTSdkDir}/Lib/${UCRTVersion}/um/${WinSDKArchitecture}")
278280
set(OverlayDirectory "${CMAKE_BINARY_DIR}/winsdk_lib_${arch}_symlinks")
279281

280-
if(NOT EXISTS "$ENV{UniversalCRTSdkDir}/Include/$ENV{UCRTVersion}/um/WINDOWS.H")
282+
if(NOT EXISTS "${UniversalCRTSdkDir}/Include/${UCRTVersion}/um/WINDOWS.H")
281283
file(MAKE_DIRECTORY ${OverlayDirectory})
282284

283285
file(GLOB libraries RELATIVE "${WinSDK${arch}UMDir}" "${WinSDK${arch}UMDir}/*")

cmake/modules/SwiftWindowsSupport.cmake

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,65 +15,44 @@ function(swift_windows_arch_spelling arch var)
1515
endif()
1616
endfunction()
1717

18-
function(swift_verify_windows_environment_variables)
19-
set(VCToolsInstallDir $ENV{VCToolsInstallDir})
20-
set(UniversalCRTSdkDir $ENV{UniversalCRTSdkDir})
21-
set(UCRTVersion $ENV{UCRTVersion})
22-
23-
precondition(VCToolsInstallDir
24-
MESSAGE
25-
"VCToolsInstallDir environment variable must be set")
26-
precondition(UniversalCRTSdkDir
27-
MESSAGE
28-
"UniversalCRTSdkDir environment variable must be set")
29-
precondition(UCRTVersion
30-
MESSAGE
31-
"UCRTVersion environment variable must be set")
32-
endfunction()
33-
3418
function(swift_windows_include_for_arch arch var)
35-
swift_verify_windows_environment_variables()
36-
3719
set(paths
38-
"$ENV{VCToolsInstallDir}/include"
39-
"$ENV{UniversalCRTSdkDir}/Include/$ENV{UCRTVersion}/ucrt"
40-
"$ENV{UniversalCRTSdkDir}/Include/$ENV{UCRTVersion}/shared"
41-
"$ENV{UniversalCRTSdkDir}/Include/$ENV{UCRTVersion}/um")
20+
"${VCToolsInstallDir}/include"
21+
"${UniversalCRTSdkDir}/Include/${UCRTVersion}/ucrt"
22+
"${UniversalCRTSdkDir}/Include/${UCRTVersion}/shared"
23+
"${UniversalCRTSdkDir}/Include/${UCRTVersion}/um")
4224
set(${var} ${paths} PARENT_SCOPE)
4325
endfunction()
4426

4527
function(swift_windows_lib_for_arch arch var)
46-
swift_verify_windows_environment_variables()
4728
swift_windows_arch_spelling(${arch} ARCH)
4829

4930
set(paths)
5031

5132
# NOTE(compnerd) provide compatibility with VS2015 which had the libraries in
5233
# a directory called "Lib" rather than VS2017 which normalizes the layout and
5334
# places them in a directory named "lib".
54-
if(IS_DIRECTORY "$ENV{VCToolsInstallDir}/Lib")
35+
if(IS_DIRECTORY "${VCToolsInstallDir}/Lib")
5536
if(${ARCH} STREQUAL x86)
56-
list(APPEND paths "$ENV{VCToolsInstallDir}/Lib/")
37+
list(APPEND paths "${VCToolsInstallDir}/Lib/")
5738
else()
58-
list(APPEND paths "$ENV{VCToolsInstallDir}/Lib/${ARCH}")
39+
list(APPEND paths "${VCToolsInstallDir}/Lib/${ARCH}")
5940
endif()
6041
else()
61-
list(APPEND paths "$ENV{VCToolsInstallDir}/lib/${ARCH}")
42+
list(APPEND paths "${VCToolsInstallDir}/lib/${ARCH}")
6243
endif()
6344

6445
list(APPEND paths
65-
"$ENV{UniversalCRTSdkDir}/Lib/$ENV{UCRTVersion}/ucrt/${ARCH}"
66-
"$ENV{UniversalCRTSdkDir}/Lib/$ENV{UCRTVersion}/um/${ARCH}")
46+
"${UniversalCRTSdkDir}/Lib/${UCRTVersion}/ucrt/${ARCH}"
47+
"${UniversalCRTSdkDir}/Lib/${UCRTVersion}/um/${ARCH}")
6748

6849
set(${var} ${paths} PARENT_SCOPE)
6950
endfunction()
7051

7152
function(swift_windows_generate_sdk_vfs_overlay flags)
72-
swift_verify_windows_environment_variables()
73-
74-
get_filename_component(VCToolsInstallDir $ENV{VCToolsInstallDir} ABSOLUTE)
75-
get_filename_component(UniversalCRTSdkDir $ENV{UniversalCRTSdkDir} ABSOLUTE)
76-
set(UCRTVersion $ENV{UCRTVersion})
53+
get_filename_component(VCToolsInstallDir ${VCToolsInstallDir} ABSOLUTE)
54+
get_filename_component(UniversalCRTSdkDir ${UniversalCRTSdkDir} ABSOLUTE)
55+
set(UCRTVersion ${UCRTVersion})
7756

7857
# TODO(compnerd) use a target to avoid re-creating this file all the time
7958
configure_file("${SWIFT_SOURCE_DIR}/utils/WindowsSDKVFSOverlay.yaml.in"
@@ -85,3 +64,19 @@ function(swift_windows_generate_sdk_vfs_overlay flags)
8564
PARENT_SCOPE)
8665
endfunction()
8766

67+
function(swift_verify_windows_VCVAR var)
68+
if (NOT DEFINED "${var}" AND NOT DEFINED "ENV{${var}}")
69+
message(FATAL_ERROR "${var} environment variable must be set")
70+
endif()
71+
endfunction()
72+
73+
function(swift_windows_cache_VCVARS)
74+
swift_verify_windows_VCVAR(VCToolsInstallDir)
75+
swift_verify_windows_VCVAR(UniversalCRTSdkDir)
76+
swift_verify_windows_VCVAR(UCRTVersion)
77+
78+
set(VCToolsInstallDir $ENV{VCToolsInstallDir} CACHE STRING "")
79+
set(UniversalCRTSdkDir $ENV{UniversalCRTSdkDir} CACHE STRING "")
80+
set(UCRTVersion $ENV{UCRTVersion} CACHE STRING "")
81+
endfunction()
82+

0 commit comments

Comments
 (0)