6
6
# This file is part of python-isal which is distributed under the
7
7
# PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2.
8
8
9
- import copy
10
9
import functools
11
10
import os
12
11
import shutil
@@ -72,19 +71,7 @@ def build_extension(self, ext):
72
71
raise NotImplementedError (
73
72
f"Unsupported platform: { sys .platform } " )
74
73
else :
75
- if self .compiler .compiler_type == "msvc" :
76
- compiler = copy .deepcopy (self .compiler )
77
- if not compiler .initialized :
78
- compiler .initialize ()
79
- compiler_command = f'"{ compiler .cc } "'
80
- compiler_args = compiler .compile_options
81
- elif self .compiler .compiler_type == "unix" :
82
- compiler_command = self .compiler .compiler [0 ]
83
- compiler_args = self .compiler .compiler [1 :]
84
- else :
85
- raise NotImplementedError ("Unknown compiler" )
86
- isa_l_prefix_dir = build_isa_l (compiler_command ,
87
- " " .join (compiler_args ))
74
+ isa_l_prefix_dir = build_isa_l ()
88
75
if SYSTEM_IS_UNIX :
89
76
ext .extra_objects = [
90
77
os .path .join (isa_l_prefix_dir , "lib" , "libisal.a" )]
@@ -106,7 +93,7 @@ def build_extension(self, ext):
106
93
# 'cache' is only available from python 3.9 onwards.
107
94
# see: https://docs.python.org/3/library/functools.html#functools.cache
108
95
@functools .lru_cache (maxsize = None )
109
- def build_isa_l (compiler_command : str , compiler_options : str ):
96
+ def build_isa_l ():
110
97
# Check for cache
111
98
if BUILD_CACHE :
112
99
if BUILD_CACHE_FILE .exists ():
@@ -122,14 +109,8 @@ def build_isa_l(compiler_command: str, compiler_options: str):
122
109
# Build environment is a copy of OS environment to allow user to influence
123
110
# it.
124
111
build_env = os .environ .copy ()
125
- # Add -fPIC flag to allow static compilation
126
- build_env ["CC" ] = compiler_command
127
112
if SYSTEM_IS_UNIX :
128
- build_env ["CFLAGS" ] = compiler_options + " -fPIC"
129
- elif SYSTEM_IS_WINDOWS :
130
- # The nmake file has CLFAGS_REL for all the compiler options.
131
- # This is added to CFLAGS with all the necessary include options.
132
- build_env ["CFLAGS_REL" ] = compiler_options
113
+ build_env ["CFLAGS" ] = build_env .get ("CFLAGS" , "" ) + " -O2 -fPIC"
133
114
if hasattr (os , "sched_getaffinity" ):
134
115
cpu_count = len (os .sched_getaffinity (0 ))
135
116
else : # sched_getaffinity not available on all platforms
@@ -142,7 +123,8 @@ def build_isa_l(compiler_command: str, compiler_options: str):
142
123
subprocess .run (["make" , "-j" , str (cpu_count )], ** run_args )
143
124
subprocess .run (["make" , "-j" , str (cpu_count ), "install" ], ** run_args )
144
125
elif SYSTEM_IS_WINDOWS :
145
- subprocess .run (["nmake" , "/E" , "/f" , "Makefile.nmake" ], ** run_args )
126
+ print (build_env , file = sys .stderr )
127
+ subprocess .run (["nmake" , "/f" , "Makefile.nmake" ], ** run_args )
146
128
Path (temp_prefix , "include" ).mkdir ()
147
129
print (temp_prefix , file = sys .stderr )
148
130
shutil .copytree (os .path .join (build_dir , "include" ),
0 commit comments