@@ -55,11 +55,7 @@ def run_cmd(args):
5555
5656
5757def copy_tree (src , dst ):
58- if sys .version_info >= (3 , 8 ):
59- shutil .copytree (src , dst , dirs_exist_ok = True )
60- else :
61- shutil .rmtree (dst , ignore_errors = True )
62- shutil .copytree (src , dst )
58+ shutil .copytree (src , dst , dirs_exist_ok = True )
6359
6460
6561def is_macos_universal2 ():
@@ -144,6 +140,16 @@ def using_system_libs():
144140 or not os .path .exists (os .path .join (PROJECT_DIR , 'crt' , 'aws-c-common' , 'CMakeLists.txt' )))
145141
146142
143+ def using_libcrypto ():
144+ """If true, libcrypto is used, even on win/mac."""
145+ if sys .platform == 'darwin' or sys .platform == 'win32' :
146+ # use libcrypto on mac/win to support ed25519, unless its disabled via env-var
147+ return not os .getenv ('AWS_CRT_BUILD_DISABLE_LIBCRYPTO_USE_FOR_ED25519_EVERYWHERE' ) == '1'
148+ else :
149+ # on Unix we always use libcrypto
150+ return True
151+
152+
147153def using_system_libcrypto ():
148154 """If true, don't build AWS-LC. Use the libcrypto that's already on the system."""
149155 return using_system_libs () or os .getenv ('AWS_CRT_BUILD_USE_SYSTEM_LIBCRYPTO' ) == '1'
@@ -154,11 +160,6 @@ def forcing_static_libs():
154160 return os .getenv ('AWS_CRT_BUILD_FORCE_STATIC_LIBS' ) == '1'
155161
156162
157- def disable_libcrypto_use_for_ed25519_everywhere ():
158- """If true, libcrypto is not used on mac/win to support ed25519 and apis instead return not supported."""
159- return os .getenv ('AWS_CRT_BUILD_DISABLE_LIBCRYPTO_USE_FOR_ED25519_EVERYWHERE' ) == '1'
160-
161-
162163class AwsLib :
163164 def __init__ (self , name , extra_cmake_args = [], libname = None ):
164165 self .name = name
@@ -170,7 +171,7 @@ def __init__(self, name, extra_cmake_args=[], libname=None):
170171# They're built along with the extension (unless using_system_libs() is True)
171172AWS_LIBS = []
172173
173- if not disable_libcrypto_use_for_ed25519_everywhere () or ( sys . platform != 'darwin' and sys . platform != 'win32' ):
174+ if using_libcrypto ( ):
174175 # aws-lc produces libcrypto.a
175176 AWS_LIBS .append (AwsLib ('aws-lc' , libname = 'crypto' ))
176177
@@ -223,10 +224,10 @@ def _build_dependencies_impl(self, build_dir, install_path, osx_arch=None):
223224 f'-DCMAKE_BUILD_TYPE={ build_type } ' ,
224225 ])
225226
226- if using_system_libcrypto ():
227- cmake_args .append ('-DUSE_OPENSSL=ON' )
227+ if using_libcrypto ():
228+ if using_system_libcrypto ():
229+ cmake_args .append ('-DUSE_OPENSSL=ON' )
228230
229- if not disable_libcrypto_use_for_ed25519_everywhere ():
230231 cmake_args .append ('-DAWS_USE_LIBCRYPTO_TO_SUPPORT_ED25519_EVERYWHERE=ON' )
231232
232233 if sys .platform == 'darwin' :
@@ -360,6 +361,19 @@ def awscrt_ext():
360361 extra_link_args += ['-framework' , 'Security' ]
361362
362363 else : # unix
364+ if forcing_static_libs ():
365+ # linker will prefer shared libraries over static if it can find both.
366+ # force linker to choose static variant by using
367+ # "-l:libaws-c-common.a" syntax instead of just "-laws-c-common".
368+ #
369+ # This helps AWS developers creating Lambda applications from Brazil.
370+ # In Brazil, both shared and static libs are available.
371+ # But Lambda requires all shared libs to be explicitly packaged up.
372+ # So it's simpler to link them in statically and have less runtime dependencies.
373+ #
374+ # Don't apply this trick to dependencies that are always on the OS (e.g. librt)
375+ libraries = [':lib{}.a' .format (x ) for x in libraries ]
376+
363377 # OpenBSD doesn't have librt; functions are found in libc instead.
364378 if not sys .platform .startswith ('openbsd' ):
365379 libraries += ['rt' ]
@@ -386,20 +400,6 @@ def awscrt_ext():
386400 # Do this even if using system libcrypto, since it could still be a static lib.
387401 extra_link_args += ['-Wl,--exclude-libs,libcrypto.a' ]
388402
389- if not disable_libcrypto_use_for_ed25519_everywhere () or (sys .platform != 'darwin' and sys .platform != 'win32' ):
390- if forcing_static_libs ():
391- # linker will prefer shared libraries over static if it can find both.
392- # force linker to choose static variant by using
393- # "-l:libaws-c-common.a" syntax instead of just "-laws-c-common".
394- #
395- # This helps AWS developers creating Lambda applications from Brazil.
396- # In Brazil, both shared and static libs are available.
397- # But Lambda requires all shared libs to be explicitly packaged up.
398- # So it's simpler to link them in statically and have less runtime dependencies.
399- #
400- # Don't apply this trick to dependencies that are always on the OS (e.g. librt)
401- libraries = [':lib{}.a' .format (x ) for x in libraries ]
402-
403403 if sys .platform != 'win32' or distutils .ccompiler .get_default_compiler () != 'msvc' :
404404 extra_compile_args += ['-Wno-strict-aliasing' , '-std=gnu99' ]
405405
0 commit comments