25
25
# sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET').
26
26
MACOS_DEPLOYMENT_TARGET_MIN = "10.15"
27
27
28
+ # This is the minimum version of the Windows SDK needed for schannel.h with SCH_CREDENTIALS and
29
+ # TLS_PARAMETERS. These are required to build Windows Binaries with TLS 1.3 support.
30
+ WINDOWS_SDK_VERSION_TLS1_3_SUPPORT = "10.0.17763.0"
31
+
28
32
29
33
def parse_version (version_string ):
30
34
return tuple (int (x ) for x in version_string .split ("." ))
@@ -84,7 +88,7 @@ def determine_cross_compile_args():
84
88
return []
85
89
86
90
87
- def determine_generator_args ():
91
+ def determine_generator_args (cmake_version = None , windows_sdk_version = None ):
88
92
if sys .platform == 'win32' :
89
93
try :
90
94
# See which compiler python picks
@@ -110,11 +114,10 @@ def determine_generator_args():
110
114
assert (vs_version and vs_year )
111
115
except Exception :
112
116
raise RuntimeError ('No supported version of MSVC compiler could be found!' )
117
+ vs_version_gen_str = "Visual Studio {} {}" .format (vs_version , vs_year )
113
118
114
119
print ('Using Visual Studio' , vs_version , vs_year )
115
120
116
- vs_version_gen_str = "Visual Studio {} {}" .format (vs_version , vs_year )
117
-
118
121
if vs_year <= 2017 :
119
122
# For VS2017 and earlier, architecture goes at end of generator string
120
123
if is_64bit ():
@@ -123,6 +126,17 @@ def determine_generator_args():
123
126
124
127
# For VS2019 (and presumably later), architecture is passed via -A flag
125
128
arch_str = "x64" if is_64bit () else "Win32"
129
+
130
+ # Set the target windows SDK version. We have a minimum required version of the Windows SDK needed for schannel.h with SCH_CREDENTIALS and
131
+ # TLS_PARAMETERS. These are required to build Windows Binaries with TLS 1.3 support.
132
+ # Introduced in cmake 3.27+, the generator string supports a version field to specify the windows sdk version in use
133
+ # https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_PLATFORM.html#variable:CMAKE_GENERATOR_PLATFORM
134
+ if cmake_version >= (3 , 27 ):
135
+ # Set windows sdk version to the one that supports TLS 1.3
136
+ arch_str += f",version={ windows_sdk_version } "
137
+
138
+ print ('Using Visual Studio' , vs_version , vs_year , 'with architecture' , arch_str )
139
+
126
140
return ['-G' , vs_version_gen_str , '-A' , arch_str ]
127
141
128
142
return []
@@ -144,6 +158,21 @@ def get_cmake_path():
144
158
raise Exception ("CMake must be installed to build from source." )
145
159
146
160
161
+ def get_cmake_version ():
162
+ """Return the version of CMake installed on the system."""
163
+ cmake_path = get_cmake_path ()
164
+ if not cmake_path :
165
+ return (0 , 0 , 0 )
166
+ try :
167
+ output = subprocess .check_output ([cmake_path , '--version' ], text = True )
168
+ version_line = output .split ('\n ' )[0 ]
169
+ version = version_line .split (' ' )[- 1 ]
170
+ print (f"Found CMake version: { version } " )
171
+ return parse_version (version )
172
+ except BaseException :
173
+ return (0 , 0 , 0 ) # Return a default version if cmake is not found or fails
174
+
175
+
147
176
def using_system_libs ():
148
177
"""If true, don't build any dependencies. Use the libs that are already on the system."""
149
178
return (os .getenv ('AWS_CRT_BUILD_USE_SYSTEM_LIBS' ) == '1'
@@ -227,7 +256,27 @@ def _build_dependencies_impl(self, build_dir, install_path, osx_arch=None):
227
256
cmake_args = [cmake ]
228
257
cmake_args .append (f'-H{ source_dir } ' )
229
258
cmake_args .append (f'-B{ build_dir } ' )
230
- cmake_args .extend (determine_generator_args ())
259
+
260
+ if sys .platform == 'win32' :
261
+ windows_sdk_version = os .getenv ('AWS_CRT_WINDOWS_SDK_VERSION' )
262
+ if windows_sdk_version is None :
263
+ windows_sdk_version = WINDOWS_SDK_VERSION_TLS1_3_SUPPORT
264
+
265
+ cmake_version = get_cmake_version ()
266
+
267
+ cmake_args .extend (
268
+ determine_generator_args (
269
+ cmake_version = cmake_version ,
270
+ windows_sdk_version = windows_sdk_version ))
271
+
272
+ if cmake_version < (3 , 27 ):
273
+ # Set the target windows SDK version. We have a minimum required version of the Windows SDK needed for schannel.h with SCH_CREDENTIALS and
274
+ # TLS_PARAMETERS. These are required to build Windows Binaries with TLS 1.3 support.
275
+ # for cmake < 3.27, we have to specify the version with CMAKE_SYSTEM_VERSION. Please note this flag will be
276
+ # ignored by cmake versions >= 3.27.
277
+ # checkout determine_generator_args() for the case of cmake >= 3.27
278
+ cmake_args .append (f'-DCMAKE_SYSTEM_VERSION={ windows_sdk_version } ' )
279
+
231
280
cmake_args .extend (determine_cross_compile_args ())
232
281
cmake_args .extend ([
233
282
f'-DCMAKE_INSTALL_PREFIX={ install_path } ' ,
0 commit comments