2525# sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET').
2626MACOS_DEPLOYMENT_TARGET_MIN = "10.15"
2727
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+
2832
2933def parse_version (version_string ):
3034 return tuple (int (x ) for x in version_string .split ("." ))
@@ -84,7 +88,7 @@ def determine_cross_compile_args():
8488 return []
8589
8690
87- def determine_generator_args ():
91+ def determine_generator_args (cmake_version = None , windows_sdk_version = None ):
8892 if sys .platform == 'win32' :
8993 try :
9094 # See which compiler python picks
@@ -110,11 +114,10 @@ def determine_generator_args():
110114 assert (vs_version and vs_year )
111115 except Exception :
112116 raise RuntimeError ('No supported version of MSVC compiler could be found!' )
117+ vs_version_gen_str = "Visual Studio {} {}" .format (vs_version , vs_year )
113118
114119 print ('Using Visual Studio' , vs_version , vs_year )
115120
116- vs_version_gen_str = "Visual Studio {} {}" .format (vs_version , vs_year )
117-
118121 if vs_year <= 2017 :
119122 # For VS2017 and earlier, architecture goes at end of generator string
120123 if is_64bit ():
@@ -123,6 +126,17 @@ def determine_generator_args():
123126
124127 # For VS2019 (and presumably later), architecture is passed via -A flag
125128 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+
126140 return ['-G' , vs_version_gen_str , '-A' , arch_str ]
127141
128142 return []
@@ -144,6 +158,21 @@ def get_cmake_path():
144158 raise Exception ("CMake must be installed to build from source." )
145159
146160
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+
147176def using_system_libs ():
148177 """If true, don't build any dependencies. Use the libs that are already on the system."""
149178 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):
227256 cmake_args = [cmake ]
228257 cmake_args .append (f'-H{ source_dir } ' )
229258 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+
231280 cmake_args .extend (determine_cross_compile_args ())
232281 cmake_args .extend ([
233282 f'-DCMAKE_INSTALL_PREFIX={ install_path } ' ,
0 commit comments