3535from ctypes import cdll
3636from collections import namedtuple
3737
38- libwolfssl_path = ""
39-
40-
4138def local_path (path ):
4239 """ Return path relative to the root of this project
4340 """
@@ -223,8 +220,13 @@ def build_wolfssl(ref, debug=False):
223220
224221
225222def make_optional_func_list (libwolfssl_path , funcs ):
223+ defined = []
226224 sys .stderr .write ("\n libwolfssl Path: %s\n " % libwolfssl_path )
227- if libwolfssl_path .endswith (".so" ):
225+ if not libwolfssl_path or not os .path .exists (libwolfssl_path ):
226+ sys .stderr .write ("WARNING: libwolfssl not found, skipping optional "
227+ "function detection\n " )
228+ return []
229+ if libwolfssl_path .endswith (".so" ) or libwolfssl_path .endswith (".dylib" ):
228230 libwolfssl = cdll .LoadLibrary (libwolfssl_path )
229231 defined = []
230232 for func in funcs :
@@ -244,16 +246,13 @@ def make_optional_func_list(libwolfssl_path, funcs):
244246 return defined
245247
246248
247- def get_libwolfssl ():
248- libwolfssl_path = os .path .join (wolfssl_lib_path (), "libwolfssl.a" )
249- if not os .path .exists (libwolfssl_path ):
250- libwolfssl_path = os .path .join (wolfssl_lib_path (), "libwolfssl.so" )
251- if not os .path .exists (libwolfssl_path ):
252- return 0
253- else :
254- return 1
255- else :
256- return 1
249+ def get_libwolfssl_path ():
250+ lib_dir = wolfssl_lib_path ()
251+ for ext in (".so" , ".dylib" , ".a" ):
252+ path = os .path .join (lib_dir , "libwolfssl" + ext )
253+ if os .path .exists (path ):
254+ return path
255+ return None
257256
258257
259258def generate_libwolfssl ():
@@ -282,6 +281,7 @@ def generate_libwolfssl():
282281 raise RuntimeError ("wolfSSL needs to be compiled with "
283282 "--enable-opensslextra" )
284283 featureDetection = 1
284+ libwolfssl_path = get_libwolfssl_path ()
285285 sys .stderr .write ("\n DEBUG: Found <wolfssl/options.h>, attempting native "
286286 "feature detection\n " )
287287
@@ -290,9 +290,10 @@ def generate_libwolfssl():
290290 featureDetection = 0
291291 sys .stderr .write ("\n DEBUG: Skipping native feature detection, build not "
292292 "using USE_LOCAL_WOLFSSL\n " )
293- if get_libwolfssl () == 0 :
293+ libwolfssl_path = get_libwolfssl_path ()
294+ if libwolfssl_path is None :
294295 generate_libwolfssl ()
295- get_libwolfssl ()
296+ libwolfssl_path = get_libwolfssl_path ()
296297
297298# default values
298299OLDTLS_ENABLED = 0
@@ -328,13 +329,23 @@ def generate_libwolfssl():
328329
329330ffi = FFI ()
330331
331- ffi .set_source (
332- "wolfssl._ffi" ,
333- ffi_source ,
334- include_dirs = [wolfssl_inc_path ()],
335- library_dirs = [wolfssl_lib_path ()],
336- libraries = ["wolfssl" ],
337- )
332+ if libwolfssl_path and libwolfssl_path .endswith (".a" ):
333+ # Static linking: pass the .a file directly via extra_objects
334+ ffi .set_source (
335+ "wolfssl._ffi" ,
336+ ffi_source ,
337+ include_dirs = [wolfssl_inc_path ()],
338+ extra_objects = [libwolfssl_path ],
339+ )
340+ else :
341+ # Dynamic linking: use library_dirs + libraries
342+ ffi .set_source (
343+ "wolfssl._ffi" ,
344+ ffi_source ,
345+ include_dirs = [wolfssl_inc_path ()],
346+ library_dirs = [wolfssl_lib_path ()],
347+ libraries = ["wolfssl" ],
348+ )
338349
339350cdef = """
340351 /*
0 commit comments