Skip to content

Commit 2dae492

Browse files
authored
AWS_CRT_BUILD_USE_SYSTEM_LIBS (awslabs#593)
*Issue #:* awslabs#588 User wants explicit way to choose whether aws-crt-python builds its own dependencies (their source code is under `crt/`), or find them prebuilt on the system. There's currently a secret way to do this (delete `crt/` folder, or don't sync submodules), but it's not documented. *Description of changes:* Set `AWS_CRT_BUILD_USE_SYSTEM_LIBS=1` to explicitly disable building dependencies
1 parent b19fbd4 commit 2dae492

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ To simplify installation, aws-crt-python has its own copy of libcrypto.
4545
This lets you install a wheel from PyPI without having OpenSSL installed.
4646
Unix wheels on PyPI come with libcrypto statically compiled in.
4747
Code to build libcrypto comes from [AWS-LC](https://github.com/aws/aws-lc).
48-
AWS-LC's code is included in the PyPI source package,
48+
AWS-LC's code is included in the PyPI source package,
4949
and the git repository includes it as a submodule.
5050

51-
If you need aws-crt-python to use the libcrypto included on your system,
51+
If you need aws-crt-python to use the libcrypto included on your system,
5252
set environment variable `AWS_CRT_BUILD_USE_SYSTEM_LIBCRYPTO=1` while building from source:
5353

5454
```sh
@@ -59,6 +59,19 @@ AWS_CRT_BUILD_USE_SYSTEM_LIBCRYPTO=1 python3 -m pip install --no-binary :all: --
5959
You can ignore all this on Windows and Apple platforms, where aws-crt-python
6060
uses the OS's default libraries for TLS and cryptography math.
6161

62+
### AWS_CRT_BUILD_USE_SYSTEM_LIBS ###
63+
64+
aws-crt-python depends on several C libraries that make up the AWS Common Runtime (libaws-c-common, libaws-c-s3, etc).
65+
By default, these libraries are built along with aws-crt-python and statically compiled in
66+
(their source code is under [crt/](crt/)).
67+
68+
To skip building these dependencies, because they're already available on your system,
69+
set environment variable `AWS_CRT_BUILD_USE_SYSTEM_LIBS=1` while building from source:
70+
71+
```sh
72+
AWS_CRT_BUILD_USE_SYSTEM_LIBS=1 python3 -m pip install .
73+
```
74+
6275
## Mac-Only TLS Behavior
6376

6477
Please note that on Mac, once a private key is used with a certificate, that certificate-key pair is imported into the Mac Keychain. All subsequent uses of that certificate will use the stored private key and ignore anything passed in programmatically. Beginning in v0.6.2, when a stored private key from the Keychain is used, the following will be logged at the "info" log level:

awscrt/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ class AwsSignedBodyHeaderType(IntEnum):
507507
"""Do not add a header."""
508508

509509
X_AMZ_CONTENT_SHA_256 = 1
510-
"""Add the "x-amz-content-sha-256" header with the canonical request's signed body value"""
510+
"""Add the "x-amz-content-sha256" header with the canonical request's signed body value"""
511511

512512

513513
class AwsSigningConfig(NativeResource):

setup.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,14 @@ def get_cmake_path():
134134
raise Exception("CMake must be installed to build from source.")
135135

136136

137+
def using_system_libs():
138+
"""If true, don't build any dependencies. Use the libs that are already on the system."""
139+
return os.getenv('AWS_CRT_BUILD_USE_SYSTEM_LIBS') == '1'
140+
141+
137142
def using_system_libcrypto():
138-
return os.getenv('AWS_CRT_BUILD_USE_SYSTEM_LIBCRYPTO') == '1'
143+
"""If true, don't build AWS-LC. Use the libcrypto that's already on the system."""
144+
return using_system_libs() or os.getenv('AWS_CRT_BUILD_USE_SYSTEM_LIBCRYPTO') == '1'
139145

140146

141147
class AwsLib:
@@ -223,7 +229,10 @@ def _build_dependencies_impl(self, build_dir, install_path, osx_arch=None):
223229
]
224230
run_cmd(build_cmd)
225231

226-
def _build_dependencies(self, build_dir, install_path):
232+
def _build_dependencies(self):
233+
build_dir = os.path.join(self.build_temp, 'deps')
234+
install_path = os.path.join(self.build_temp, 'deps', 'install')
235+
227236
if is_macos_universal2() and not is_development_mode():
228237
# create macOS universal binary by compiling for x86_64 and arm64,
229238
# each in its own subfolder, and then creating a universal binary
@@ -266,30 +275,28 @@ def _build_dependencies(self, build_dir, install_path):
266275
# normal build for a single architecture
267276
self._build_dependencies_impl(build_dir, install_path)
268277

269-
def run(self):
270-
# build dependencies
271-
dep_build_dir = os.path.join(self.build_temp, 'deps')
272-
dep_install_path = os.path.join(self.build_temp, 'deps', 'install')
273-
274-
if os.path.exists(os.path.join(PROJECT_DIR, 'crt', 'aws-c-common', 'CMakeLists.txt')):
275-
self._build_dependencies(dep_build_dir, dep_install_path)
276-
else:
277-
print("Skip building dependencies, source not found.")
278-
279278
# update paths so awscrt_ext can access dependencies.
280279
# add to the front of any list so that our dependencies are preferred
281280
# over anything that might already be on the system (i.e. libcrypto.a)
282281

283-
self.include_dirs.insert(0, os.path.join(dep_install_path, 'include'))
282+
self.include_dirs.insert(0, os.path.join(install_path, 'include'))
284283

285284
# some platforms (ex: fedora) use /lib64 instead of just /lib
286285
lib_dir = 'lib'
287-
if is_64bit() and os.path.exists(os.path.join(dep_install_path, 'lib64')):
286+
if is_64bit() and os.path.exists(os.path.join(install_path, 'lib64')):
288287
lib_dir = 'lib64'
289-
if is_32bit() and os.path.exists(os.path.join(dep_install_path, 'lib32')):
288+
if is_32bit() and os.path.exists(os.path.join(install_path, 'lib32')):
290289
lib_dir = 'lib32'
291290

292-
self.library_dirs.insert(0, os.path.join(dep_install_path, lib_dir))
291+
self.library_dirs.insert(0, os.path.join(install_path, lib_dir))
292+
293+
def run(self):
294+
if using_system_libs():
295+
print("Skip building dependencies, using system libs.")
296+
elif not os.path.exists(os.path.join(PROJECT_DIR, 'crt', 'aws-c-common', 'CMakeLists.txt')):
297+
print("Skip building dependencies, source not found.")
298+
else:
299+
self._build_dependencies()
293300

294301
# continue with normal build_ext.run()
295302
super().run()

0 commit comments

Comments
 (0)