Prechádzať zdrojové kódy

Support windows x86 (#84)

Fangjun Kuang 2 rokov pred
rodič
commit
533a44c25a

+ 0 - 101
.github/workflows/linux-macos-windows.yaml

@@ -1,101 +0,0 @@
-name: linux-macos-windows
-
-on:
-  push:
-    branches:
-      - master
-    paths:
-      - '.github/workflows/linux-macos-windows.yaml'
-      - '.github/scripts/run-test.sh'
-      - 'CMakeLists.txt'
-      - 'cmake/**'
-      - 'sherpa-ncnn/csrc/*'
-  pull_request:
-    branches:
-      - master
-    paths:
-      - '.github/workflows/linux-macos-windows.yaml'
-      - '.github/scripts/run-test.sh'
-      - 'CMakeLists.txt'
-      - 'cmake/**'
-      - 'sherpa-ncnn/csrc/*'
-
-concurrency:
-  group: linux-macos-windows-${{ github.ref }}
-  cancel-in-progress: true
-
-permissions:
-  contents: read
-
-jobs:
-  linux_macos_windows:
-    runs-on: ${{ matrix.os }}
-    strategy:
-      fail-fast: false
-      matrix:
-        os: [ubuntu-latest, macos-latest, windows-latest]
-
-    steps:
-      - uses: actions/checkout@v2
-        with:
-          fetch-depth: 0
-
-      # see https://github.com/microsoft/setup-msbuild
-      - name: Add msbuild to PATH
-        if: startsWith(matrix.os, 'windows')
-        uses: microsoft/setup-msbuild@v1.0.2
-
-      - name: Configure CMake
-        shell: bash
-        run: |
-          mkdir build
-          cd build
-          cmake -D CMAKE_BUILD_TYPE=Release ..
-
-      - name: Build sherpa for ubuntu/macos
-        if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
-        run: |
-          cd build
-          make -j2
-
-          ls -lh lib
-          ls -lh bin
-
-          ls -lh bin/sherpa-ncnn
-          file bin/sherpa-ncnn
-
-          ls -lh bin/sherpa-ncnn-microphone
-          file bin/sherpa-ncnn-microphone
-
-      - name: Upload binary sherpa-ncnn and sherpa-ncnn-micrphone
-        uses: actions/upload-artifact@v2
-        if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
-        with:
-          name: sherpa-ncnn-pre-built-binaries-os-${{ matrix.os }}
-          path: ./build/bin
-
-      - name: Run tests for ubuntu/macos
-        if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
-        run: |
-          export PATH=$PWD/build/bin:$PATH
-          export EXE=sherpa-ncnn
-
-          .github/scripts/run-test.sh
-
-      - name: Build sherpa for windows
-        if: startsWith(matrix.os, 'windows')
-        shell: bash
-        run: |
-          cd build
-          cmake --build . --config Release -- -m:2
-
-          ls -lh ./bin/Release/sherpa-ncnn.exe
-
-      - name: Run tests for windows
-        if: startsWith(matrix.os, 'windows')
-        shell: bash
-        run: |
-          export PATH=$PWD/build/bin/Release:$PATH
-          export EXE=sherpa-ncnn.exe
-
-          .github/scripts/run-test.sh

+ 75 - 0
.github/workflows/linux.yaml

@@ -0,0 +1,75 @@
+name: linux
+
+on:
+  push:
+    branches:
+      - master
+    paths:
+      - '.github/workflows/linux.yaml'
+      - '.github/scripts/run-test.sh'
+      - 'CMakeLists.txt'
+      - 'cmake/**'
+      - 'sherpa-ncnn/csrc/*'
+  pull_request:
+    branches:
+      - master
+    paths:
+      - '.github/workflows/linux.yaml'
+      - '.github/scripts/run-test.sh'
+      - 'CMakeLists.txt'
+      - 'cmake/**'
+      - 'sherpa-ncnn/csrc/*'
+
+concurrency:
+  group: linux-${{ github.ref }}
+  cancel-in-progress: true
+
+permissions:
+  contents: read
+
+jobs:
+  linux:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ubuntu-latest]
+
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+
+      - name: Configure CMake
+        shell: bash
+        run: |
+          mkdir build
+          cd build
+          cmake -D CMAKE_BUILD_TYPE=Release ..
+
+      - name: Build sherpa for ubuntu
+        run: |
+          cd build
+          make -j2
+
+          ls -lh lib
+          ls -lh bin
+
+          ls -lh bin/sherpa-ncnn
+          file bin/sherpa-ncnn
+
+          ls -lh bin/sherpa-ncnn-microphone
+          file bin/sherpa-ncnn-microphone
+
+      - name: Upload binary sherpa-ncnn and sherpa-ncnn-microphone
+        uses: actions/upload-artifact@v2
+        with:
+          name: sherpa-ncnn-pre-built-binaries-os-${{ matrix.os }}
+          path: ./build/bin
+
+      - name: Run tests for ubuntu
+        run: |
+          export PATH=$PWD/build/bin:$PATH
+          export EXE=sherpa-ncnn
+
+          .github/scripts/run-test.sh

+ 75 - 0
.github/workflows/macos.yaml

@@ -0,0 +1,75 @@
+name: macos
+
+on:
+  push:
+    branches:
+      - master
+    paths:
+      - '.github/workflows/macos.yaml'
+      - '.github/scripts/run-test.sh'
+      - 'CMakeLists.txt'
+      - 'cmake/**'
+      - 'sherpa-ncnn/csrc/*'
+  pull_request:
+    branches:
+      - master
+    paths:
+      - '.github/workflows/macos.yaml'
+      - '.github/scripts/run-test.sh'
+      - 'CMakeLists.txt'
+      - 'cmake/**'
+      - 'sherpa-ncnn/csrc/*'
+
+concurrency:
+  group: macos-${{ github.ref }}
+  cancel-in-progress: true
+
+permissions:
+  contents: read
+
+jobs:
+  macos:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [macos-latest]
+
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+
+      - name: Configure CMake
+        shell: bash
+        run: |
+          mkdir build
+          cd build
+          cmake -D CMAKE_BUILD_TYPE=Release ..
+
+      - name: Build sherpa for macos
+        run: |
+          cd build
+          make -j2
+
+          ls -lh lib
+          ls -lh bin
+
+          ls -lh bin/sherpa-ncnn
+          file bin/sherpa-ncnn
+
+          ls -lh bin/sherpa-ncnn-microphone
+          file bin/sherpa-ncnn-microphone
+
+      - name: Upload binary sherpa-ncnn and sherpa-ncnn-microphone
+        uses: actions/upload-artifact@v2
+        with:
+          name: sherpa-ncnn-pre-built-binaries-os-${{ matrix.os }}
+          path: ./build/bin
+
+      - name: Run tests for macos
+        run: |
+          export PATH=$PWD/build/bin:$PATH
+          export EXE=sherpa-ncnn
+
+          .github/scripts/run-test.sh

+ 81 - 0
.github/workflows/windows-x64.yaml

@@ -0,0 +1,81 @@
+name: windows-x64
+
+on:
+  push:
+    branches:
+      - master
+    paths:
+      - '.github/workflows/windows-x64.yaml'
+      - '.github/scripts/run-test.sh'
+      - 'CMakeLists.txt'
+      - 'cmake/**'
+      - 'sherpa-ncnn/csrc/*'
+  pull_request:
+    branches:
+      - master
+    paths:
+      - '.github/workflows/windows-x64.yaml'
+      - '.github/scripts/run-test.sh'
+      - 'CMakeLists.txt'
+      - 'cmake/**'
+      - 'sherpa-ncnn/csrc/*'
+
+concurrency:
+  group: windows-x64-${{ github.ref }}
+  cancel-in-progress: true
+
+permissions:
+  contents: read
+
+jobs:
+  windows_x64:
+    runs-on: ${{ matrix.os }}
+    name: ${{ matrix.vs-version }}
+    strategy:
+      fail-fast: false
+      matrix:
+        include:
+          - vs-version: vs2015
+            toolset-version: v140
+            os: windows-2019
+
+          - vs-version: vs2017
+            toolset-version: v141
+            os: windows-2019
+
+          - vs-version: vs2019
+            toolset-version: v142
+            os: windows-2022
+
+          - vs-version: vs2022
+            toolset-version: v143
+            os: windows-2022
+
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+
+      - name: Configure CMake
+        shell: bash
+        run: |
+          mkdir build
+          cd build
+          cmake -T ${{ matrix.toolset-version}},host=x64 -A x64 -D CMAKE_BUILD_TYPE=Release ..
+
+      - name: Build sherpa for windows
+        shell: bash
+        run: |
+          cd build
+          cmake --build . --config Release -- -m:2
+
+          ls -lh ./bin/Release/sherpa-ncnn.exe
+          ls -lh ./bin/Release/sherpa-ncnn-microphone.exe
+
+      - name: Run tests for windows
+        shell: bash
+        run: |
+          export PATH=$PWD/build/bin/Release:$PATH
+          export EXE=sherpa-ncnn.exe
+
+          .github/scripts/run-test.sh

+ 81 - 0
.github/workflows/windows-x86.yaml

@@ -0,0 +1,81 @@
+name: windows-x86
+
+on:
+  push:
+    branches:
+      - master
+    paths:
+      - '.github/workflows/windows-x86.yaml'
+      - '.github/scripts/run-test.sh'
+      - 'CMakeLists.txt'
+      - 'cmake/**'
+      - 'sherpa-ncnn/csrc/*'
+  pull_request:
+    branches:
+      - master
+    paths:
+      - '.github/workflows/windows-x86.yaml'
+      - '.github/scripts/run-test.sh'
+      - 'CMakeLists.txt'
+      - 'cmake/**'
+      - 'sherpa-ncnn/csrc/*'
+
+concurrency:
+  group: windows-x86-${{ github.ref }}
+  cancel-in-progress: true
+
+permissions:
+  contents: read
+
+jobs:
+  windows_x86:
+    runs-on: ${{ matrix.os }}
+    name: ${{ matrix.vs-version }}
+    strategy:
+      fail-fast: false
+      matrix:
+        include:
+          - vs-version: vs2015
+            toolset-version: v140
+            os: windows-2019
+
+          - vs-version: vs2017
+            toolset-version: v141
+            os: windows-2019
+
+          - vs-version: vs2019
+            toolset-version: v142
+            os: windows-2022
+
+          - vs-version: vs2022
+            toolset-version: v143
+            os: windows-2022
+
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+
+      - name: Configure CMake
+        shell: bash
+        run: |
+          mkdir build
+          cd build
+          cmake -T ${{ matrix.toolset-version}},host=x64 -A Win32 -D CMAKE_BUILD_TYPE=Release ..
+
+      - name: Build sherpa for windows
+        shell: bash
+        run: |
+          cd build
+          cmake --build . --config Release -- -m:2
+
+          ls -lh ./bin/Release/sherpa-ncnn.exe
+          ls -lh ./bin/Release/sherpa-ncnn-microphone.exe
+
+      - name: Run tests for windows
+        shell: bash
+        run: |
+          export PATH=$PWD/build/bin/Release:$PATH
+          export EXE=sherpa-ncnn.exe
+
+          .github/scripts/run-test.sh

+ 35 - 0
CMakeLists.txt

@@ -3,6 +3,14 @@ project(sherpa-ncnn)
 
 set(SHERPA_NCNN_VERSION "1.3.2")
 
+# Disable warning about
+#
+# "The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
+#  not set.
+if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
+  cmake_policy(SET CMP0135 NEW)
+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")
@@ -58,6 +66,33 @@ endif()
 
 list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
 
+if(WIN32)
+  add_definitions(-DNOMINMAX) # Otherwise, std::max() and std::min() won't work
+endif()
+
+if(WIN32)
+  # disable various warnings for MSVC
+  # 4244: 'return': conversion from 'unsigned __int64' to 'int', possible loss of data
+  # 4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
+  # 4305: 'argument': truncation from 'double' to 'const float'
+  # 4334: '<<': result of 32-bit shift implicitly converted to 64 bits
+  # 4800: 'int': forcing value to bool 'true' or 'false'
+  # 4996: 'fopen': This function or variable may be unsafe
+  set(disabled_warnings
+      /wd4244
+      /wd4267
+      /wd4305
+      /wd4334
+      /wd4800
+      /wd4996
+  )
+  message(STATUS "Disabled warnings: ${disabled_warnings}")
+  foreach(w IN LISTS disabled_warnings)
+    string(APPEND CMAKE_CXX_FLAGS " ${w} ")
+  endforeach()
+endif()
+
+
 include(kaldi-native-fbank)
 include(ncnn)
 

+ 1 - 1
build-aarch64-linux-gnu.sh

@@ -44,8 +44,8 @@ cmake \
   -DSHERPA_NCNN_ENABLE_TEST=OFF \
   -DCMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-linux-gnu.toolchain.cmake \
   ..
-cp -v $SHERPA_NCNN_ALSA_LIB_DIR/libasound.so* ./install/lib/
 
 make VERBOSE=1 -j4
 make install/strip
 
+cp -v $SHERPA_NCNN_ALSA_LIB_DIR/libasound.so* ./install/lib/

+ 8 - 8
cmake/kaldi-native-fbank.cmake

@@ -1,17 +1,17 @@
 function(download_kaldi_native_fbank)
   include(FetchContent)
 
-  set(kaldi_native_fbank_URL  "https://github.com/csukuangfj/kaldi-native-fbank/archive/refs/tags/v1.8.tar.gz")
-  set(kaldi_native_fbank_HASH "SHA256=1aefda7e76456e2c5005e05fa10cdc7f91c3ffc0a7fad000a90b50e7ed18087b")
+  set(kaldi_native_fbank_URL  "https://github.com/csukuangfj/kaldi-native-fbank/archive/refs/tags/v1.11.tar.gz")
+  set(kaldi_native_fbank_HASH "SHA256=e69ae25ef6f30566ef31ca949dd1b0b8ec3a827caeba93a61d82bb848dac5d69")
 
   # If you don't have access to the Internet, please download it to your
   # local drive and modify the following line according to your needs.
-  if(EXISTS "/star-fj/fangjun/download/github/kaldi-native-fbank-1.8.tar.gz")
-    set(kaldi_native_fbank_URL  "file:///star-fj/fangjun/download/github/kaldi-native-fbank-1.8.tar.gz")
-  elseif(EXISTS "/Users/fangjun/Downloads/kaldi-native-fbank-1.8.tar.gz")
-    set(kaldi_native_fbank_URL  "file:///Users/fangjun/Downloads/kaldi-native-fbank-1.8.tar.gz")
-  elseif(EXISTS "/tmp/kaldi-native-fbank-1.8.tar.gz")
-    set(kaldi_native_fbank_URL  "file:///tmp/kaldi-native-fbank-1.8.tar.gz")
+  if(EXISTS "/star-fj/fangjun/download/github/kaldi-native-fbank-1.11.tar.gz")
+    set(kaldi_native_fbank_URL  "file:///star-fj/fangjun/download/github/kaldi-native-fbank-1.11.tar.gz")
+  elseif(EXISTS "/Users/fangjun/Downloads/kaldi-native-fbank-1.11.tar.gz")
+    set(kaldi_native_fbank_URL  "file:///Users/fangjun/Downloads/kaldi-native-fbank-1.11.tar.gz")
+  elseif(EXISTS "/tmp/kaldi-native-fbank-1.11.tar.gz")
+    set(kaldi_native_fbank_URL  "file:///tmp/kaldi-native-fbank-1.11.tar.gz")
   endif()
 
   set(KALDI_NATIVE_FBANK_BUILD_TESTS OFF CACHE BOOL "" FORCE)

+ 2 - 2
sherpa-ncnn/csrc/resample.cc

@@ -182,12 +182,12 @@ void LinearResample::Resample(const float *input, int32_t input_dim, bool flush,
         static_cast<int32_t>(first_samp_in - input_sample_offset_);
     float this_output;
     if (first_input_index >= 0 &&
-        first_input_index + weights.size() <= input_dim) {
+        first_input_index + static_cast<int32_t>(weights.size()) <= input_dim) {
       this_output =
           DotProduct(input + first_input_index, weights.data(), weights.size());
     } else {  // Handle edge cases.
       this_output = 0.0;
-      for (int32_t i = 0; i < weights.size(); i++) {
+      for (int32_t i = 0; i < static_cast<int32_t>(weights.size()); i++) {
         float weight = weights[i];
         int32_t input_index = first_input_index + i;
         if (input_index < 0 &&

+ 1 - 0
sherpa-ncnn/csrc/sherpa-ncnn-alsa.cc

@@ -20,6 +20,7 @@
 #include <stdlib.h>
 
 #include <algorithm>
+#include <cctype>  // std::tolower
 #include <cstdint>
 
 #include "sherpa-ncnn/csrc/alsa.h"

+ 2 - 0
sherpa-ncnn/csrc/sherpa-ncnn-microphone.cc

@@ -20,6 +20,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <cctype>  // std::tolower
+
 #include "portaudio.h"  // NOLINT
 #include "sherpa-ncnn/csrc/display.h"
 #include "sherpa-ncnn/csrc/microphone.h"