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..f07b8ca 100644 --- a/.github/workflows/build-pip.yml +++ b/.github/workflows/build-pip.yml @@ -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 @@ -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 }} @@ -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-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..b0af361 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -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 @@ -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 }} @@ -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 0d9a29f..deef025 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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: | diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 02ef2a7..b5fcc93 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -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 @@ -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 }} @@ -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 b723a8c..6daf2dd 100644 --- a/.github/workflows/test-pip-install.yaml +++ b/.github/workflows/test-pip-install.yaml @@ -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 @@ -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 }} 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..26415c1 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 @@ -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() 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() 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) 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')