Skip to content

Commit 69a4e36

Browse files
committed
Build statically by default.
1 parent b377dbc commit 69a4e36

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

setup.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import subprocess
2424
import sys
2525
import tempfile
26-
from distutils.errors import CompileError
2726
from pathlib import Path
2827

2928
from setuptools import Extension, find_packages, setup
@@ -42,28 +41,28 @@ def build_extension(self, ext):
4241
if not isinstance(ext, IsalExtension):
4342
super().build_extension(ext)
4443
return
45-
# Check for isa-l include directories. This is useful when installing
46-
# in a conda environment.
47-
possible_prefixes = [sys.exec_prefix, sys.base_exec_prefix]
48-
for prefix in possible_prefixes:
49-
if os.path.exists(os.path.join(prefix, "include", "isa-l")):
50-
ext.include_dirs = [
51-
os.path.join(prefix, "include")]
52-
break # Only one include directory is needed.
53-
ext.libraries = ["isal"]
54-
try: # First try to link dynamically
55-
super().build_extension(ext)
56-
except CompileError:
57-
# Dynamic linking failed, build ISA-L and link statically.
58-
ext.libraries = [] # Make sure libraries are empty
44+
45+
# Add option to link dynamically for packaging systems such as conda.
46+
if os.getenv("PYTHON_ISAL_LINK_DYNAMIC") is not None:
47+
# Check for isa-l include directories. This is useful when
48+
# installing in a conda environment.
49+
possible_prefixes = [sys.exec_prefix, sys.base_exec_prefix]
50+
for prefix in possible_prefixes:
51+
if os.path.exists(os.path.join(prefix, "include", "isa-l")):
52+
ext.include_dirs = [
53+
os.path.join(prefix, "include")]
54+
break # Only one include directory is needed.
55+
ext.libraries = ["isal"]
56+
else:
5957
isa_l_prefix_dir = build_isa_l()
6058
ext.include_dirs = [os.path.join(isa_l_prefix_dir,
61-
"include")]
59+
"include")]
6260
# -fPIC needed for proper static linking
6361
ext.extra_compile_args = ["-fPIC"]
6462
ext.extra_objects = [
6563
os.path.join(isa_l_prefix_dir, "lib", "libisal.a")]
66-
super().build_extension(ext)
64+
65+
super().build_extension(ext)
6766

6867

6968
# Use a cache to prevent isa-l from being build twice. According to the

0 commit comments

Comments
 (0)