mirror of
https://github.com/csukuangfj/kaldifeat.git
synced 2025-08-09 18:12:17 +00:00
Merge pull request #30 from csukuangfj/fix-windows
Fix building on windows
This commit is contained in:
commit
1313e9dc61
4
.github/workflows/build_conda.yml
vendored
4
.github/workflows/build_conda.yml
vendored
@ -20,8 +20,8 @@ name: build_conda_cuda
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- conda-cuda
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
KALDIFEAT_BUILD_TYPE: Release
|
||||
|
88
.github/workflows/build_windows.yml
vendored
Normal file
88
.github/workflows/build_windows.yml
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
name: build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build-windows:
|
||||
# see https://github.com/actions/virtual-environments/blob/win19/20210525.0/images/win/Windows2019-Readme.md
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-2019]
|
||||
torch: ["1.6.0", "1.7.0", "1.7.1", "1.8.0", "1.8.1", "1.9.0", "1.10.0", "1.11.0"]
|
||||
python-version: [3.6, 3.7, 3.8, 3.9]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
# see https://github.com/microsoft/setup-msbuild
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.0.2
|
||||
|
||||
- name: Setup Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Display Python version
|
||||
run: python -c "import sys; print(sys.version)"
|
||||
|
||||
- name: Install PyTorch ${{ matrix.torch }}
|
||||
run: |
|
||||
pip3 install -qq torch==${{ matrix.torch }}+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
||||
pip3 install -qq wheel twine dataclasses numpy typing_extensions soundfile
|
||||
|
||||
- name: Display CMake version
|
||||
run: |
|
||||
cmake --version
|
||||
cmake --help
|
||||
|
||||
- name: Configure CMake
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir build_release
|
||||
cd build_release
|
||||
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
|
||||
ls -lh
|
||||
|
||||
- name: Build kaldifeat
|
||||
run: |
|
||||
cd build_release
|
||||
cmake --build . --target _kaldifeat --config Release
|
||||
|
||||
- name: Display generated files
|
||||
shell: bash
|
||||
run: |
|
||||
cd build_release
|
||||
ls -lh lib/*/*
|
||||
|
||||
- name: Build wheel
|
||||
shell: bash
|
||||
run: |
|
||||
python3 setup.py bdist_wheel
|
||||
ls -lh dist/
|
||||
pip install ./dist/*.whl
|
||||
python3 -c "import kaldifeat; print(kaldifeat.__version__)"
|
||||
|
||||
- name: Upload Wheel
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: python-${{ matrix.python-version }}-${{ matrix.os }}-cpu
|
||||
path: dist/*.whl
|
||||
|
||||
- name: Build tests
|
||||
shell: bash
|
||||
run: |
|
||||
cd build_release
|
||||
cmake --build . --target ALL_BUILD --config Release
|
||||
ls -lh bin/*/*
|
||||
ctest -C Release --verbose --output-on-failure
|
@ -18,6 +18,12 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN")
|
||||
set(CMAKE_BUILD_RPATH "$ORIGIN")
|
||||
|
||||
set(BUILD_SHARED_LIBS ON)
|
||||
if(WIN32)
|
||||
message(STATUS "Set BUILD_SHARED_LIBS to OFF for Windows")
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
message(STATUS "No CMAKE_BUILD_TYPE given, default to Release")
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
|
@ -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,34 +67,64 @@ 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}"
|
||||
|
||||
build_cmd = f"""
|
||||
cd {self.build_temp}
|
||||
|
||||
cmake {cmake_args} {kaldifeat_dir}
|
||||
|
||||
|
||||
make {make_args} _kaldifeat
|
||||
"""
|
||||
print(f"build command is:\n{build_cmd}")
|
||||
|
||||
ret = os.system(build_cmd)
|
||||
if ret != 0:
|
||||
raise Exception(
|
||||
"\nBuild kaldifeat failed. Please check the error message.\n"
|
||||
"You can ask for help by creating an issue on GitHub.\n"
|
||||
"\nClick:\n\thttps://github.com/csukuangfj/kaldifeat/issues/new\n" # noqa
|
||||
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}
|
||||
|
||||
cmake {cmake_args} {kaldifeat_dir}
|
||||
|
||||
|
||||
make {make_args} _kaldifeat
|
||||
"""
|
||||
print(f"build command is:\n{build_cmd}")
|
||||
|
||||
ret = os.system(build_cmd)
|
||||
if ret != 0:
|
||||
raise Exception(
|
||||
"\nBuild kaldifeat failed. Please check the error message.\n"
|
||||
"You can ask for help by creating an issue on GitHub.\n"
|
||||
"\nClick:\n\thttps://github.com/csukuangfj/kaldifeat/issues/new\n" # noqa
|
||||
)
|
||||
|
||||
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/_kaldifeat.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}/")
|
||||
|
@ -12,7 +12,7 @@ set(kaldifeat_srcs
|
||||
online-feature.cc
|
||||
)
|
||||
|
||||
add_library(kaldifeat_core SHARED ${kaldifeat_srcs})
|
||||
add_library(kaldifeat_core ${kaldifeat_srcs})
|
||||
target_link_libraries(kaldifeat_core PUBLIC ${TORCH_LIBRARIES})
|
||||
|
||||
target_compile_definitions(kaldifeat_core PUBLIC KALDIFEAT_TORCH_VERSION_MAJOR=${KALDIFEAT_TORCH_VERSION_MAJOR})
|
||||
|
@ -14,4 +14,7 @@ target_link_libraries(_kaldifeat PRIVATE kaldifeat_core)
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(_kaldifeat PUBLIC ${TORCH_DIR}/lib/libtorch_python.so)
|
||||
target_link_libraries(_kaldifeat PUBLIC ${PYTHON_LIBRARY})
|
||||
elseif(WIN32)
|
||||
target_link_libraries(_kaldifeat PUBLIC ${TORCH_DIR}/lib/torch_python.lib)
|
||||
target_link_libraries(_kaldifeat PUBLIC ${PYTHON_LIBRARIES})
|
||||
endif()
|
||||
|
1
setup.py
1
setup.py
@ -41,6 +41,7 @@ setuptools.setup(
|
||||
long_description_content_type="text/markdown",
|
||||
ext_modules=[cmake_extension("_kaldifeat")],
|
||||
cmdclass={"build_ext": BuildExtension, "bdist_wheel": bdist_wheel},
|
||||
zip_safe=False,
|
||||
classifiers=[
|
||||
"Programming Language :: C++",
|
||||
"Programming Language :: Python",
|
||||
|
Loading…
x
Reference in New Issue
Block a user