Fix building on Windows.

This commit is contained in:
Fangjun Kuang 2022-04-03 14:26:25 +08:00
parent 47ff9a2c35
commit 959da88b6e

View File

@ -20,6 +20,10 @@ def is_macos():
return platform.system() == "Darwin"
def is_windows():
return platform.system() == "Windows"
try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
@ -63,14 +67,34 @@ class BuildExtension(build_ext):
if cmake_args == "":
cmake_args = "-DCMAKE_BUILD_TYPE=Release"
if make_args == "" and system_make_args == "":
print("For fast compilation, run:")
print('export KALDIFEAT_MAKE_ARGS="-j"; python setup.py install')
if "PYTHON_EXECUTABLE" not in cmake_args:
print(f"Setting PYTHON_EXECUTABLE to {sys.executable}")
cmake_args += f" -DPYTHON_EXECUTABLE={sys.executable}"
if is_windows():
build_cmd = f"""
cmake {cmake_args} -B {self.build_temp} -S {kaldifeat_dir}
cmake --build {self.build_temp} --target _kaldifeat --config Release -- -m
"""
print(f"build command is:\n{build_cmd}")
ret = os.system(
f"cmake {cmake_args} -B {self.build_temp} -S {kaldifeat_dir}"
)
if ret != 0:
raise Exception("Failed to build kaldifeat")
ret = os.system(
f"cmake --build {self.build_temp} --target _kaldifeat --config Release -- -m"
)
if ret != 0:
raise Exception("Failed to build kaldifeat")
else:
if make_args == "" and system_make_args == "":
print("For fast compilation, run:")
print(
'export KALDIFEAT_MAKE_ARGS="-j"; python setup.py install'
)
build_cmd = f"""
cd {self.build_temp}
@ -91,6 +115,16 @@ class BuildExtension(build_ext):
lib_so = glob.glob(f"{self.build_temp}/lib/*kaldifeat*.so")
lib_so += glob.glob(f"{self.build_temp}/lib/*kaldifeat*.dylib") # macOS
# bin/Release/_k2.cp38-win_amd64.pyd
lib_so = glob.glob(
f"{self.build_temp}/**/*kaldifeat*.pyd", recursive=True
) # windows
# lib/Release/*.lib
lib_so = glob.glob(
f"{self.build_temp}/**/*kaldifeat*.lib", recursive=True
) # windows
for so in lib_so:
print(f"Copying {so} to {self.build_lib}/")
shutil.copy(f"{so}", f"{self.build_lib}/")