Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building dll on windows #63

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
python-version: [3.8]
steps:
# refer to https://github.com/actions/checkout
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -48,7 +48,7 @@ jobs:
key: ${{ matrix.os }}-${{ matrix.python-version }}

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/build-pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ concurrency:

jobs:
build-pip:
name: ${{ matrix.os }} ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
Expand All @@ -50,7 +51,7 @@ jobs:
uses: microsoft/setup-msbuild@v1.0.2

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -61,7 +62,7 @@ jobs:
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --version

python3 -m pip install -U pip wheel numpy
python3 -m pip install -U pip wheel numpy setuptools
python3 setup.py bdist_wheel
ls -lh dist
python3 -m pip install ./dist/kaldifst*.whl
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-wheels-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
python-version: ["cp37", "cp38", "cp39", "cp310", "cp311", "cp312"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

# see https://cibuildwheel.readthedocs.io/en/stable/changelog/
# for a list of versions
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-wheels-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
python-version: ["cp38", "cp39", "cp310", "cp311", "cp312"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

# see https://cibuildwheel.readthedocs.io/en/stable/changelog/
# for a list of versions
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-wheels-win32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
python-version: ["cp37", "cp38", "cp39", "cp310", "cp311", "cp312"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

# see https://cibuildwheel.readthedocs.io/en/stable/changelog/
# for a list of versions
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-wheels-win64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
python-version: ["cp37", "cp38", "cp39", "cp310", "cp311", "cp312"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

# see https://cibuildwheel.readthedocs.io/en/stable/changelog/
# for a list of versions
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ concurrency:

jobs:
build-windows:
name: ${{ matrix.python-version }}
# 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]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
os: [windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -48,7 +49,7 @@ jobs:
uses: microsoft/setup-msbuild@v1.0.2

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -57,7 +58,7 @@ jobs:

- name: Install Python dependencies
run: |
pip3 install -qq wheel twine dataclasses numpy typing_extensions
pip3 install -qq wheel twine dataclasses numpy typing_extensions setuptools

- name: Display CMake version
run: |
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ concurrency:

jobs:
build:
name: ${{ matrix.os }} ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -47,13 +48,13 @@ jobs:
key: ${{ matrix.os }}-${{ matrix.python-version }}

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
pip3 install -qq wheel twine dataclasses numpy typing_extensions
pip3 install -qq wheel twine dataclasses numpy typing_extensions setuptools

- name: Display CMake version
run: |
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ jobs:
nightly-pip:
# see https://github.com/actions/virtual-environments/blob/win19/20210525.0/images/win/Windows2019-Readme.md
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} ${{ matrix.python-version }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -43,7 +44,7 @@ jobs:
uses: microsoft/setup-msbuild@v1.0.2

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -52,7 +53,7 @@ jobs:

- name: Install Python dependencies
run: |
pip3 install -qq wheel twine dataclasses numpy typing_extensions
pip3 install -qq wheel twine dataclasses numpy typing_extensions setuptools

- name: Display CMake version
run: |
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/test-pip-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ permissions:

jobs:
test_pip_install:
name: ${{ matrix.os }} ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -42,7 +43,7 @@ jobs:
key: ${{ matrix.os }}-${{ matrix.python-version }}

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cmake_minimum_required(VERSION 3.13 FATAL_ERROR)

project(kaldifst CXX)

set(KALDIFST_VERSION "1.7.10")
set(KALDIFST_VERSION "1.7.11")

# Disable warning about
#
Expand All @@ -33,15 +33,14 @@ option(KALDIFST_BUILD_TESTS "Whether to build tests or not" OFF)
option(KALDIFST_BUILD_PYTHON "Whether to build Python" ON)
option(BUILD_SHARED_LIBS "Whether to build shared libraries" ON)

if(BUILD_SHARED_LIBS AND MSVC)
message(STATUS "Disable building shared libraries for Windows")
set(BUILD_SHARED_LIBS OFF)
endif()

message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}")

if(BUILD_SHARED_LIBS AND MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
Expand Down
32 changes: 19 additions & 13 deletions cmake/openfst.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
function(download_openfst)
include(FetchContent)

set(openfst_URL "https://github.com/kkm000/openfst/archive/refs/tags/win/1.6.5.1.tar.gz")
set(openfst_URL2 "https://huggingface.co/csukuangfj/kaldi-hmm-gmm-cmake-deps/resolve/main/openfst-win-1.6.5.1.tar.gz")
set(openfst_HASH "SHA256=02c49b559c3976a536876063369efc0e41ab374be1035918036474343877046e")
set(openfst_URL "https://github.com/csukuangfj/openfst/archive/refs/tags/sherpa-onnx-2024-06-13.tar.gz")
set(openfst_URL2 "https://hub.nuaa.cf/csukuangfj/openfst/archive/refs/tags/sherpa-onnx-2024-06-13.tar.gz")
set(openfst_HASH "SHA256=f10a71c6b64d89eabdc316d372b956c30c825c7c298e2f20c780320e8181ffb6")

# If you don't have access to the Internet,
# please pre-download it
set(possible_file_locations
$ENV{HOME}/Downloads/openfst-win-1.6.5.1.tar.gz
${CMAKE_SOURCE_DIR}/openfst-win-1.6.5.1.tar.gz
${CMAKE_BINARY_DIR}/openfst-win-1.6.5.1.tar.gz
/tmp/openfst-win-1.6.5.1.tar.gz
/star-fj/fangjun/download/github/openfst-win-1.6.5.1.tar.gz
$ENV{HOME}/Downloads/openfst-sherpa-onnx-2024-06-13.tar.gz
${CMAKE_SOURCE_DIR}/openfst-sherpa-onnx-2024-06-13.tar.gz
${CMAKE_BINARY_DIR}/openfst-sherpa-onnx-2024-06-13.tar.gz
/tmp/openfst-sherpa-onnx-2024-06-13.tar.gz
/star-fj/fangjun/download/github/openfst-sherpa-onnx-2024-06-13.tar.gz
)

foreach(f IN LISTS possible_file_locations)
Expand Down Expand Up @@ -70,8 +70,6 @@ function(download_openfst)
add_subdirectory(${openfst_SOURCE_DIR} ${openfst_BINARY_DIR} EXCLUDE_FROM_ALL)
set(openfst_SOURCE_DIR ${openfst_SOURCE_DIR} PARENT_SCOPE)

# Rename libfst.so.6 to libkaldifst_fst.so.6 to avoid potential conflicts
# when kaldifst is installed.
set_target_properties(fst PROPERTIES OUTPUT_NAME "kaldifst_fst")

install(TARGETS fst
Expand All @@ -80,10 +78,18 @@ function(download_openfst)

if(KALDIFST_BUILD_PYTHON)
set_target_properties(fstscript PROPERTIES OUTPUT_NAME "kaldifst_fstscript")
install(TARGETS fstscript
DESTINATION lib
)
endif()

if(KALDIFST_BUILD_PYTHON AND WIN32)
install(TARGETS fst fstscript DESTINATION ..)
else()
install(TARGETS fst fstscript DESTINATION lib)
endif()

if(WIN32 AND BUILD_SHARED_LIBS)
install(TARGETS fst fstscript DESTINATION bin)
endif()

endfunction()

download_openfst()
12 changes: 9 additions & 3 deletions kaldifst/csrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ if(KALDIFST_BUILD_TESTS)
endforeach()
endif()

install(TARGETS kaldifst_core
DESTINATION lib
)
if(KALDIFST_BUILD_PYTHON AND WIN32)
install(TARGETS kaldifst_core DESTINATION ..)
else()
install(TARGETS kaldifst_core DESTINATION lib)
endif()

if(WIN32 AND BUILD_SHARED_LIBS)
install(TARGETS kaldifst_core DESTINATION bin)
endif()
6 changes: 5 additions & 1 deletion kaldifst/python/csrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ if(APPLE)
OUTPUT_VARIABLE PYTHON_SITE_PACKAGE_DIR
)
message(STATUS "PYTHON_SITE_PACKAGE_DIR: ${PYTHON_SITE_PACKAGE_DIR}")
target_link_libraries(_kaldifst PRIVATE "-Wl,-rpath,${PYTHON_SITE_PACKAGE_DIR}")
if(PYTHON_SITE_PACKAGE_DIR STREQUAL "")
message(WARNING "PYTHON_SITE_PACKAGE_DIR is empty!")
else()
target_link_libraries(_kaldifst PRIVATE "-Wl,-rpath,${PYTHON_SITE_PACKAGE_DIR}")
endif()
endif()

if(NOT WIN32)
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ def build_extension(self, ext: setuptools.extension.Extension):
extra_cmake_args = " -DKALDIFST_BUILD_TESTS=OFF "
extra_cmake_args += f" -DCMAKE_INSTALL_PREFIX={install_dir} "

if is_windows():
extra_cmake_args += " -DBUILD_SHARED_LIBS=OFF "

if make_args == "" and system_make_args == "":
print("For fast compilation, run:")
print('export KALDIFST_MAKE_ARGS="-j"; python setup.py install')
Expand Down
Loading