Skip to content

Commit 0ca4dd9

Browse files
committed
add USE_LOCAL_WOLFSSL to allow use of local wolfSSL library install
1 parent d26781d commit 0ca4dd9

4 files changed

Lines changed: 32 additions & 5 deletions

File tree

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ class cffiBuilder(build_ext, object):
6363
def build_extension(self, ext):
6464
""" Compile manually the wolfssl-py extension, bypass setuptools
6565
"""
66-
build_wolfssl(wolfssl.__wolfssl_version__)
66+
67+
# if USE_LOCAL_WOLFSSL environment variable has been defined,
68+
# do not clone and compile wolfSSL from GitHub
69+
if os.environ.get("USE_LOCAL_WOLFSSL") is None:
70+
build_wolfssl(wolfssl.__wolfssl_version__)
6771

6872
super(cffiBuilder, self).build_extension(ext)
6973

src/wolfssl/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ def __init__(self, sock=None, keyfile=None, certfile=None,
375375
self.ciphers = ciphers
376376
self.server_hostname = server_hostname
377377

378+
# set SNI if passed in
378379
if server_hostname is not None:
379380
self._context.use_sni(server_hostname)
380381

src/wolfssl/_build_ffi.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from distutils.util import get_platform
2626
from cffi import FFI
2727
from wolfssl.__about__ import __wolfssl_version__ as version
28-
from wolfssl._build_wolfssl import local_path
28+
from wolfssl._build_wolfssl import wolfssl_inc_path, wolfssl_lib_path
2929

3030
ffi = FFI()
3131

@@ -35,9 +35,8 @@
3535
#include <wolfssl/options.h>
3636
#include <wolfssl/ssl.h>
3737
""",
38-
include_dirs=[local_path("lib/wolfssl/src")],
39-
library_dirs=[local_path("lib/wolfssl/{}/{}/lib".format(
40-
get_platform(), version))],
38+
include_dirs=[wolfssl_inc_path()],
39+
library_dirs=[wolfssl_lib_path()],
4140
libraries=["wolfssl"],
4241
)
4342

src/wolfssl/_build_wolfssl.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ def local_path(path):
3737
WOLFSSL_SRC_PATH = local_path("lib/wolfssl/src")
3838

3939

40+
def wolfssl_inc_path():
41+
wolfssl_path = os.environ.get("USE_LOCAL_WOLFSSL")
42+
if wolfssl_path is None:
43+
return local_path("lib/wolfssl/src")
44+
else:
45+
if os.path.isdir(wolfssl_path) and os.path.exists(wolfssl_path):
46+
return wolfssl_path + "/include"
47+
else:
48+
return "/usr/local/include"
49+
50+
51+
def wolfssl_lib_path():
52+
wolfssl_path = os.environ.get("USE_LOCAL_WOLFSSL")
53+
if wolfssl_path is None:
54+
return local_path("lib/wolfssl/{}/{}/lib".format(
55+
get_platform(), version))
56+
else:
57+
if os.path.isdir(wolfssl_path) and os.path.exists(wolfssl_path):
58+
return wolfssl_path + "/lib"
59+
else:
60+
return "/usr/local/lib"
61+
62+
4063
def call(cmd):
4164
print("Calling: '{}' from working directory {}".format(cmd, os.getcwd()))
4265

0 commit comments

Comments
 (0)