From 0385d49af7959c00aefa035b0f7f868f230906d3 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Thu, 13 Jun 2024 12:29:04 +0800 Subject: [PATCH 1/4] fix CI --- .github/workflows/build-doc.yml | 4 ++-- .github/workflows/build-pip.yml | 6 +++--- .github/workflows/build-wheels-linux.yaml | 2 +- .github/workflows/build-wheels-macos.yaml | 2 +- .github/workflows/build-wheels-win32.yaml | 2 +- .github/workflows/build-wheels-win64.yaml | 2 +- .github/workflows/build-windows.yml | 8 ++++---- .github/workflows/build.yml | 6 +++--- .github/workflows/nightly.yml | 6 +++--- .github/workflows/test-pip-install.yaml | 6 +++--- CMakeLists.txt | 11 +++++------ cmake/openfst.cmake | 18 ++++++++---------- setup.py | 3 --- 13 files changed, 35 insertions(+), 41 deletions(-) diff --git a/.github/workflows/build-doc.yml b/.github/workflows/build-doc.yml index 955bb48..5bab4f5 100644 --- a/.github/workflows/build-doc.yml +++ b/.github/workflows/build-doc.yml @@ -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 @@ -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 }} diff --git a/.github/workflows/build-pip.yml b/.github/workflows/build-pip.yml index b0d84a2..7351e22 100644 --- a/.github/workflows/build-pip.yml +++ b/.github/workflows/build-pip.yml @@ -34,10 +34,10 @@ jobs: 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 @@ -50,7 +50,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 }} diff --git a/.github/workflows/build-wheels-linux.yaml b/.github/workflows/build-wheels-linux.yaml index 4d50c9e..5c8aca0 100644 --- a/.github/workflows/build-wheels-linux.yaml +++ b/.github/workflows/build-wheels-linux.yaml @@ -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 diff --git a/.github/workflows/build-wheels-macos.yaml b/.github/workflows/build-wheels-macos.yaml index 63cb0d9..7714059 100644 --- a/.github/workflows/build-wheels-macos.yaml +++ b/.github/workflows/build-wheels-macos.yaml @@ -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 diff --git a/.github/workflows/build-wheels-win32.yaml b/.github/workflows/build-wheels-win32.yaml index bc73a88..3d120c6 100644 --- a/.github/workflows/build-wheels-win32.yaml +++ b/.github/workflows/build-wheels-win32.yaml @@ -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 diff --git a/.github/workflows/build-wheels-win64.yaml b/.github/workflows/build-wheels-win64.yaml index c50d2e0..dc45b29 100644 --- a/.github/workflows/build-wheels-win64.yaml +++ b/.github/workflows/build-wheels-win64.yaml @@ -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 diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 5f87765..c53d5c6 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -35,11 +35,11 @@ jobs: 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 @@ -48,7 +48,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 }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0d9a29f..c51573e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,9 +35,9 @@ jobs: 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 @@ -47,7 +47,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 }} diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 02ef2a7..4478bfd 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -25,10 +25,10 @@ jobs: 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 @@ -43,7 +43,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 }} diff --git a/.github/workflows/test-pip-install.yaml b/.github/workflows/test-pip-install.yaml index b723a8c..f495c13 100644 --- a/.github/workflows/test-pip-install.yaml +++ b/.github/workflows/test-pip-install.yaml @@ -29,10 +29,10 @@ jobs: 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 @@ -42,7 +42,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 }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 2640b8d..c0960ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 # @@ -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") diff --git a/cmake/openfst.cmake b/cmake/openfst.cmake index 34073d2..8cede1f 100644 --- a/cmake/openfst.cmake +++ b/cmake/openfst.cmake @@ -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) @@ -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 diff --git a/setup.py b/setup.py index c305dab..8742d03 100644 --- a/setup.py +++ b/setup.py @@ -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') From 06fb21335a1c3a942dd0c33825ec4ae8979dd819 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Thu, 13 Jun 2024 12:35:15 +0800 Subject: [PATCH 2/4] Fix for macOS --- kaldifst/python/csrc/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kaldifst/python/csrc/CMakeLists.txt b/kaldifst/python/csrc/CMakeLists.txt index 5ce3ae4..f919502 100644 --- a/kaldifst/python/csrc/CMakeLists.txt +++ b/kaldifst/python/csrc/CMakeLists.txt @@ -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) From ec71b5abb4f6f080c4192d20bdb35a4e3737e9bb Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Thu, 13 Jun 2024 12:37:10 +0800 Subject: [PATCH 3/4] fix building pip wheels --- .github/workflows/build-pip.yml | 3 ++- .github/workflows/build-windows.yml | 3 ++- .github/workflows/build.yml | 3 ++- .github/workflows/nightly.yml | 3 ++- .github/workflows/test-pip-install.yaml | 1 + cmake/openfst.cmake | 14 +++++++++++--- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-pip.yml b/.github/workflows/build-pip.yml index 7351e22..f07b8ca 100644 --- a/.github/workflows/build-pip.yml +++ b/.github/workflows/build-pip.yml @@ -30,6 +30,7 @@ concurrency: jobs: build-pip: + name: ${{ matrix.os }} ${{ matrix.python-version }} runs-on: ${{ matrix.os }} strategy: matrix: @@ -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 diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index c53d5c6..b0af361 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -30,6 +30,7 @@ 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: @@ -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: | diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c51573e..deef025 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,6 +30,7 @@ concurrency: jobs: build: + name: ${{ matrix.os }} ${{ matrix.python-version }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -53,7 +54,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: | diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 4478bfd..b5fcc93 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -21,6 +21,7 @@ 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: @@ -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: | diff --git a/.github/workflows/test-pip-install.yaml b/.github/workflows/test-pip-install.yaml index f495c13..6daf2dd 100644 --- a/.github/workflows/test-pip-install.yaml +++ b/.github/workflows/test-pip-install.yaml @@ -24,6 +24,7 @@ permissions: jobs: test_pip_install: + name: ${{ matrix.os }} ${{ matrix.python-version }} runs-on: ${{ matrix.os }} strategy: fail-fast: false diff --git a/cmake/openfst.cmake b/cmake/openfst.cmake index 8cede1f..26415c1 100644 --- a/cmake/openfst.cmake +++ b/cmake/openfst.cmake @@ -78,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() From 7a71cfb8ceb4fe51865fd269fa314796bbd62c22 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Thu, 13 Jun 2024 13:01:01 +0800 Subject: [PATCH 4/4] fix installing on windows --- kaldifst/csrc/CMakeLists.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kaldifst/csrc/CMakeLists.txt b/kaldifst/csrc/CMakeLists.txt index cb500e6..8463be7 100644 --- a/kaldifst/csrc/CMakeLists.txt +++ b/kaldifst/csrc/CMakeLists.txt @@ -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()