17
17
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
18
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
19
# SOFTWARE.
20
+ import copy
20
21
import functools
21
22
import os
22
23
import shutil
@@ -76,7 +77,18 @@ def build_extension(self, ext):
76
77
raise NotImplementedError (
77
78
f"Unsupported platform: { sys .platform } " )
78
79
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 ))
80
92
if SYSTEM_IS_UNIX :
81
93
ext .extra_objects = [
82
94
os .path .join (isa_l_prefix_dir , "lib" , "libisal.a" )]
@@ -113,7 +125,7 @@ def build_extension(self, ext):
113
125
# 'cache' is only available from python 3.9 onwards.
114
126
# see: https://docs.python.org/3/library/functools.html#functools.cache
115
127
@functools .lru_cache (maxsize = None )
116
- def build_isa_l (compiler ):
128
+ def build_isa_l (compiler_command : str , compiler_options : str ):
117
129
# Creating temporary directories
118
130
build_dir = tempfile .mktemp ()
119
131
temp_prefix = tempfile .mkdtemp ()
@@ -123,7 +135,13 @@ def build_isa_l(compiler):
123
135
# it.
124
136
build_env = os .environ .copy ()
125
137
# 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
127
145
if hasattr (os , "sched_getaffinity" ):
128
146
cpu_count = len (os .sched_getaffinity (0 ))
129
147
else : # sched_getaffinity not available on all platforms
@@ -137,7 +155,7 @@ def build_isa_l(compiler):
137
155
** run_args )
138
156
subprocess .run (["make" , "install" ], ** run_args )
139
157
elif SYSTEM_IS_WINDOWS :
140
- subprocess .run (["nmake" , "/f" , "Makefile.nmake" ], ** run_args )
158
+ subprocess .run (["nmake" , "/E" , "/ f" , "Makefile.nmake" ], ** run_args )
141
159
Path (temp_prefix , "include" ).mkdir ()
142
160
print (temp_prefix , file = sys .stderr )
143
161
shutil .copytree (os .path .join (build_dir , "include" ),
0 commit comments