Skip to content

Commit bf16b27

Browse files
committed
Merge branch 'speed' of github.com:pycompression/python-isal into speed
2 parents 82f22c3 + 197c786 commit bf16b27

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

setup.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
20+
import copy
2021
import functools
2122
import os
2223
import shutil
@@ -76,7 +77,18 @@ def build_extension(self, ext):
7677
raise NotImplementedError(
7778
f"Unsupported platform: {sys.platform}")
7879
else:
79-
isa_l_prefix_dir = build_isa_l(" ".join(self.compiler.compiler))
80+
if self.compiler.compiler_type == "msvc":
81+
compiler = copy.deepcopy(self.compiler)
82+
compiler.initialize()
83+
compiler_command = f'"{compiler.cc}"'
84+
compiler_args = compiler.compile_options
85+
elif self.compiler.compiler_type == "unix":
86+
compiler_command = self.compiler.compiler[0]
87+
compiler_args = self.compiler.compiler[1:]
88+
else:
89+
raise NotImplementedError("Unknown compiler")
90+
isa_l_prefix_dir = build_isa_l(compiler_command,
91+
" ".join(compiler_args))
8092
if SYSTEM_IS_UNIX:
8193
ext.extra_objects = [
8294
os.path.join(isa_l_prefix_dir, "lib", "libisal.a")]
@@ -113,7 +125,7 @@ def build_extension(self, ext):
113125
# 'cache' is only available from python 3.9 onwards.
114126
# see: https://docs.python.org/3/library/functools.html#functools.cache
115127
@functools.lru_cache(maxsize=None)
116-
def build_isa_l(compiler):
128+
def build_isa_l(compiler_command: str, compiler_options: str):
117129
# Creating temporary directories
118130
build_dir = tempfile.mktemp()
119131
temp_prefix = tempfile.mkdtemp()
@@ -123,7 +135,13 @@ def build_isa_l(compiler):
123135
# it.
124136
build_env = os.environ.copy()
125137
# Add -fPIC flag to allow static compilation
126-
build_env["CC"] = compiler + " -fPIC"
138+
build_env["CC"] = compiler_command
139+
if SYSTEM_IS_UNIX:
140+
build_env["CFLAGS"] = compiler_options + " -fPIC"
141+
elif SYSTEM_IS_WINDOWS:
142+
# The nmake file has CLFAGS_REL for all the compiler options.
143+
# This is added to CFLAGS with all the necessary include options.
144+
build_env["CFLAGS_REL"] = compiler_options
127145
if hasattr(os, "sched_getaffinity"):
128146
cpu_count = len(os.sched_getaffinity(0))
129147
else: # sched_getaffinity not available on all platforms
@@ -137,7 +155,7 @@ def build_isa_l(compiler):
137155
**run_args)
138156
subprocess.run(["make", "install"], **run_args)
139157
elif SYSTEM_IS_WINDOWS:
140-
subprocess.run(["nmake", "/f", "Makefile.nmake"], **run_args)
158+
subprocess.run(["nmake", "/E", "/f", "Makefile.nmake"], **run_args)
141159
Path(temp_prefix, "include").mkdir()
142160
print(temp_prefix, file=sys.stderr)
143161
shutil.copytree(os.path.join(build_dir, "include"),

0 commit comments

Comments
 (0)