Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def _build_dependencies_impl(self, build_dir, install_path, osx_arch=None):
run_cmd(build_cmd)

def _build_dependencies(self):

build_dir = os.path.join(self.build_temp, 'deps')
install_path = os.path.join(self.build_temp, 'deps', 'install')

Expand Down Expand Up @@ -375,6 +376,33 @@ def _build_dependencies(self):

self.library_dirs.insert(0, os.path.join(install_path, lib_dir))

def build_extension(self, ext):

# Warning: very hacky. feel free to replace with something cleaner
# Problem: if you install python through homebrew, python config ldflags
# will point to homebrew lib folder.
# setuptools puts python ldflags before any of our lib paths, so if there is openssl or
# another libcrypto in homebrew libs, it will get picked up before aws-lc we are building against.
# And then we have fun failures due to lib mismatch.
# I could not find a cleaner way, so lets just hook into linker command and make sure
# our libs appear before other libs.
if sys.platform == 'darwin' and using_libcrypto() and not using_system_libs() and not using_system_libcrypto():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just think out load, do we want to enable this all the time?
eg:

  • when we are using the system lib, I'd expect us to not build aws-lc, so that it won't override the libcrypto path as well.
  • It's the same condition for other platforms as well, right? I believe the last time I saw something similar was with linux.


orig_linker_so = self.compiler.linker_so[:]

for i, item in enumerate(self.compiler.linker_so):
if item.startswith('-L'):
self.compiler.linker_so[i:i] = [
f"-L{item}" for item in self.library_dirs] + ['-Wl,-search_paths_first']
break

try:
super().build_extension(ext)
finally:
self.compiler.linker_so = orig_linker_so
else:
super().build_extension(ext)

def run(self):
if using_system_libs():
print("Skip building dependencies")
Expand Down Expand Up @@ -422,7 +450,6 @@ def awscrt_ext():

elif sys.platform == 'darwin':
extra_link_args += ['-framework', 'Security']

else: # unix
if forcing_static_libs():
# linker will prefer shared libraries over static if it can find both.
Expand Down