Skip to content

Commit cfc90a9

Browse files
committed
Fix windows compilation
1 parent 486c49d commit cfc90a9

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

setup.py

Lines changed: 20 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,11 @@ 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+
build_env["CFLAGS_REL"] = compiler_options
127143
if hasattr(os, "sched_getaffinity"):
128144
cpu_count = len(os.sched_getaffinity(0))
129145
else: # sched_getaffinity not available on all platforms
@@ -137,7 +153,7 @@ def build_isa_l(compiler):
137153
**run_args)
138154
subprocess.run(["make", "install"], **run_args)
139155
elif SYSTEM_IS_WINDOWS:
140-
subprocess.run(["nmake", "/f", "Makefile.nmake"], **run_args)
156+
subprocess.run(["nmake", "/E", "/f", "Makefile.nmake"], **run_args)
141157
Path(temp_prefix, "include").mkdir()
142158
print(temp_prefix, file=sys.stderr)
143159
shutil.copytree(os.path.join(build_dir, "include"),

0 commit comments

Comments
 (0)