ソースを参照

Fix building nuget packages (#195)

Fangjun Kuang 2 年 前
コミット
a2cb2327f1

+ 0 - 76
.github/workflows/dot-net-linux.yaml

@@ -1,76 +0,0 @@
-name: dot-net-linux
-
-on:
-  push:
-    branches:
-      - dot-net
-    tags:
-      - '*'
-
-concurrency:
-  group: dot-net-linux-${{ github.ref }}
-  cancel-in-progress: true
-
-permissions:
-  contents: read
-
-jobs:
-  dot-net-linux:
-    runs-on: ${{ matrix.os }}
-    strategy:
-      fail-fast: false
-      matrix:
-        os: [ubuntu-latest]
-
-    steps:
-      - uses: actions/checkout@v2
-        with:
-          fetch-depth: 0
-
-      - name: Setup .NET Core 3.1
-        uses: actions/setup-dotnet@v1
-        with:
-          dotnet-version: 3.1.x
-
-      - name: Setup .NET 6.0
-        uses: actions/setup-dotnet@v1
-        with:
-          dotnet-version: 6.0.x
-
-      - name: Check dotnet
-        run: dotnet --info
-
-      - name: Configure CMake
-        shell: bash
-        run: |
-          mkdir build
-          cd build
-          cmake -D CMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSHERPA_NCNN_ENABLE_DOT_NET_API=ON -DSHERPA_NCNN_ENABLE_C_API=ON -DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF ..
-
-      - name: Build sherpa-ncnn for ubuntu
-        run: |
-          cd build
-          make sherpa-ncnn-native-dot-net-package
-
-          ls -lh packages
-
-      - name: Display .Net packages
-        run: |
-          cd build
-          ls -lh packages
-
-      - name: Upload .Net packages sherpa-ncnn
-        uses: actions/upload-artifact@v2
-        with:
-          name: sherpa-ncnn-pre-built-dot-net-packages-os-${{ matrix.os }}
-          path: ./build/packages
-
-      - name: publish .Net packages to nuget.org
-        if: github.repository == 'csukuangfj/sherpa-ncnn' || github.repository == 'k2-fsa/sherpa-ncnn'
-        shell: bash
-        env:
-          API_KEY: ${{ secrets.NUGET_API_KEY }}
-        run: |
-          # API_KEY is valid until 2024.05.02
-          cd build/packages
-          dotnet nuget push ./org.k2fsa.sherpa.ncnn.runtime.*.nupkg --api-key $API_KEY --source https://api.nuget.org/v3/index.json

+ 0 - 77
.github/workflows/dot-net-macos.yaml

@@ -1,77 +0,0 @@
-name: dot-net-macos
-
-on:
-  push:
-    branches:
-      - dot-net
-    tags:
-      - '*'
-
-concurrency:
-  group: dot-net-macos-${{ github.ref }}
-  cancel-in-progress: true
-
-permissions:
-  contents: read
-
-jobs:
-  dot-net-macos:
-    runs-on: ${{ matrix.os }}
-    strategy:
-      fail-fast: false
-      matrix:
-        os: [macos-latest]
-
-    steps:
-      - uses: actions/checkout@v2
-        with:
-          fetch-depth: 0
-
-      - name: Setup .NET Core 3.1
-        uses: actions/setup-dotnet@v1
-        with:
-          dotnet-version: 3.1.x
-
-      - name: Setup .NET 6.0
-        uses: actions/setup-dotnet@v1
-        with:
-          dotnet-version: 6.0.x
-
-      - name: Check dotnet
-        run: dotnet --info
-
-      - name: Configure CMake
-        shell: bash
-        run: |
-          mkdir build
-          cd build
-          cmake -D CMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSHERPA_NCNN_ENABLE_DOT_NET_API=ON -DSHERPA_NCNN_ENABLE_C_API=ON -DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF ..
-
-      - name: Build sherpa-ncnn for macOS
-        shell: bash
-        run: |
-          cd build
-          make sherpa-ncnn-native-dot-net-package
-
-          ls -lh packages
-
-      - name: Display .Net packages
-        run: |
-          cd build
-          ls -lh packages
-
-      - name: Upload .Net packages sherpa-ncnn
-        uses: actions/upload-artifact@v2
-        with:
-          name: sherpa-ncnn-pre-built-dot-net-packages-os-${{ matrix.os }}
-          path: ./build/packages
-
-      - name: publish .Net packages to nuget.org
-        if: github.repository == 'csukuangfj/sherpa-ncnn' || github.repository == 'k2-fsa/sherpa-ncnn'
-        shell: bash
-        env:
-          API_KEY: ${{ secrets.NUGET_API_KEY }}
-        run: |
-          # API_KEY is valid until 2024.05.02
-          cd build/packages
-          dotnet nuget push ./org.k2fsa.sherpa.ncnn.runtime.*.nupkg --api-key $API_KEY --source https://api.nuget.org/v3/index.json

+ 0 - 82
.github/workflows/dot-net-windows-x64.yaml

@@ -1,82 +0,0 @@
-name: dot-net-windows-x64
-
-on:
-  push:
-    branches:
-      - dot-net
-    tags:
-      - '*'
-
-concurrency:
-  group: dot-net-windows-x64-${{ github.ref }}
-  cancel-in-progress: true
-
-permissions:
-  contents: read
-
-jobs:
-  dot-net-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
-
-    steps:
-      - uses: actions/checkout@v2
-        with:
-          fetch-depth: 0
-
-      - name: Setup .NET Core 3.1
-        uses: actions/setup-dotnet@v1
-        with:
-          dotnet-version: 3.1.x
-
-      - name: Setup .NET 6.0
-        uses: actions/setup-dotnet@v1
-        with:
-          dotnet-version: 6.0.x
-
-      - name: Check dotnet
-        run: dotnet --info
-
-      - name: Configure CMake
-        shell: bash
-        run: |
-          mkdir build
-          cd build
-          cmake -T ${{ matrix.toolset-version}},host=x64 -A x64 -D CMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSHERPA_NCNN_ENABLE_DOT_NET_API=ON -DSHERPA_NCNN_ENABLE_C_API=ON -DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF ..
-
-      - name: Build sherpa-ncnn for windows x64
-        shell: bash
-        run: |
-          cd build
-          cmake --build . --config Release --target sherpa-ncnn-native-dot-net-package
-
-          ls -lh packages
-
-      - name: Display .Net packages
-        shell: bash
-        run: |
-          cd build
-          ls -lh packages
-
-      - name: Upload .Net packages sherpa-ncnn
-        uses: actions/upload-artifact@v2
-        with:
-          name: sherpa-ncnn-pre-built-dot-net-packages-os-${{ matrix.os }}
-          path: ./build/packages
-
-      - name: publish .Net packages to nuget.org
-        if: github.repository == 'csukuangfj/sherpa-ncnn' || github.repository == 'k2-fsa/sherpa-ncnn'
-        shell: bash
-        env:
-          API_KEY: ${{ secrets.NUGET_API_KEY }}
-        run: |
-          # API_KEY is valid until 2024.05.02
-          cd build/packages
-          dotnet nuget push ./org.k2fsa.sherpa.ncnn.runtime.*.nupkg --api-key $API_KEY --source https://api.nuget.org/v3/index.json

+ 136 - 0
.github/workflows/dot-net.yaml

@@ -0,0 +1,136 @@
+name: dot-net
+
+on:
+  push:
+    branches:
+      - dot-net
+    tags:
+      - '*'
+
+concurrency:
+  group: dot-net-${{ github.ref }}
+  cancel-in-progress: true
+
+jobs:
+  build-libs:
+    name: dot-net for ${{ matrix.os }}
+    runs-on: ${{ matrix.os }}
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ubuntu-latest, windows-latest, macos-latest]
+
+    steps:
+      - uses: actions/checkout@v2
+      # see https://cibuildwheel.readthedocs.io/en/stable/changelog/
+      # for a list of versions
+      - name: Build wheels
+        uses: pypa/cibuildwheel@v2.11.4
+        env:
+          CIBW_BEFORE_BUILD: "pip install -U cmake numpy"
+          CIBW_BUILD: "cp38-*64"
+          CIBW_SKIP: "cp27-* cp35-* *-win32 pp* *-musllinux*"
+          CIBW_BUILD_VERBOSITY: 3
+
+      - name: Display wheels
+        shell: bash
+        run: |
+          ls -lh ./wheelhouse/*.whl
+          unzip -l ./wheelhouse/*.whl
+
+      - uses: actions/upload-artifact@v2
+        with:
+          name: ${{ matrix.os }}-wheels
+          path: ./wheelhouse/*.whl
+
+  build-nuget-packages:
+    name: build-nuget-packages
+    runs-on: ubuntu-latest
+    needs: build-libs
+
+    steps:
+      - uses: actions/checkout@v2
+
+      - name: Retrieve artifact from ubuntu-latest
+        uses: actions/download-artifact@v2
+        with:
+          name: ubuntu-latest-wheels
+          path: ./linux
+
+      - name: Retrieve artifact from macos-latest
+        uses: actions/download-artifact@v2
+        with:
+          name: macos-latest-wheels
+          path: ./macos
+
+      - name: Retrieve artifact from windows-latest
+        uses: actions/download-artifact@v2
+        with:
+          name: windows-latest-wheels
+          path: ./windows
+
+      - name: Display wheels
+        shell: bash
+        run: |
+          tree .
+
+      - name: Unzip Ubuntu wheels
+        shell: bash
+        run: |
+          cd linux
+          unzip ./*.whl
+          tree .
+
+          cp -v sherpa_ncnn.libs/libgomp-a34b3233.so.1.0.0 sherpa_ncnn/lib
+
+      - name: Unzip macOS wheels
+        shell: bash
+        run: |
+          cd macos
+          unzip ./*.whl
+          tree .
+
+      - name: Unzip Windows wheels
+        shell: bash
+        run: |
+          cd windows
+          unzip ./*.whl
+          cp -v ./ncnn.dll sherpa_ncnn/lib/
+          cp -v ./sherpa-ncnn-core.dll sherpa_ncnn/lib/
+          tree .
+
+      - name: Setup .NET Core 3.1
+        uses: actions/setup-dotnet@v1
+        with:
+          dotnet-version: 3.1.x
+
+      - name: Setup .NET 6.0
+        uses: actions/setup-dotnet@v1
+        with:
+          dotnet-version: 6.0.x
+
+      - name: Check dotnet
+        run: dotnet --info
+
+      - name: build nuget packages
+        shell: bash
+        run: |
+          cd scripts/dotnet
+          ./run.sh
+          ls -lh packages
+
+      - uses: actions/upload-artifact@v2
+        name: upload nuget packages
+        with:
+          name: nuget-packages
+          path: scripts/dotnet/packages/*.nupkg
+
+      - name: publish .Net packages to nuget.org
+        if: github.repository == 'csukuangfj/sherpa-ncnn' || github.repository == 'k2-fsa/sherpa-ncnn'
+        shell: bash
+        env:
+          API_KEY: ${{ secrets.NUGET_API_KEY }}
+        run: |
+          # API_KEY is valid until 2024.05.02
+          cd scripts/dotnet/packages
+          dotnet nuget push ./org.k2fsa.sherpa.ncnn.*.nupkg --skip-duplicate --api-key $API_KEY --source https://api.nuget.org/v3/index.json

+ 1 - 3
CMakeLists.txt

@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
 project(sherpa-ncnn)
 
-set(SHERPA_NCNN_VERSION "1.8.6")
+set(SHERPA_NCNN_VERSION "1.9.0")
 
 # Disable warning about
 #
@@ -40,7 +40,6 @@ option(SHERPA_NCNN_ENABLE_JNI "Whether to build JNI internface" OFF)
 option(SHERPA_NCNN_ENABLE_BINARY "Whether to build the binary sherpa-ncnn" ON)
 option(SHERPA_NCNN_ENABLE_TEST "Whether to build tests" OFF)
 option(SHERPA_NCNN_ENABLE_C_API "Whether to build C API" ON)
-option(SHERPA_NCNN_ENABLE_DOT_NET_API "Whether to build .Net API" OFF)
 option(SHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE "Whether to generate-int8-scale-table" ON)
 option(SHERPA_NCNN_ENABLE_FFMPEG_EXAMPLES "Whether to enable ffmpeg-examples" OFF)
 
@@ -62,7 +61,6 @@ message(STATUS "SHERPA_NCNN_ENABLE_JNI ${SHERPA_NCNN_ENABLE_JNI}")
 message(STATUS "SHERPA_NCNN_ENABLE_BINARY ${SHERPA_NCNN_ENABLE_BINARY}")
 message(STATUS "SHERPA_NCNN_ENABLE_TEST ${SHERPA_NCNN_ENABLE_TEST}")
 message(STATUS "SHERPA_NCNN_ENABLE_C_API ${SHERPA_NCNN_ENABLE_C_API}")
-message(STATUS "SHERPA_NCNN_ENABLE_DOT_NET_API ${SHERPA_NCNN_ENABLE_DOT_NET_API}")
 message(STATUS "SHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE ${SHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE}")
 message(STATUS "SHERPA_NCNN_ENABLE_FFMPEG_EXAMPLES ${SHERPA_NCNN_ENABLE_FFMPEG_EXAMPLES}")
 

+ 5 - 0
scripts/dotnet/.gitignore

@@ -0,0 +1,5 @@
+all
+linux
+macos
+windows
+packages

+ 0 - 0
sherpa-ncnn/csharp-api/README.md → scripts/dotnet/README.md


+ 119 - 0
scripts/dotnet/generate.py

@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# Copyright (c)  2023  Xiaomi Corporation
+
+import argparse
+import re
+from pathlib import Path
+
+import jinja2
+
+SHERPA_NCNN_DIR = Path(__file__).resolve().parent.parent.parent
+
+
+def get_version():
+    cmake_file = SHERPA_NCNN_DIR / "CMakeLists.txt"
+    with open(cmake_file) as f:
+        content = f.read()
+
+    version = re.search(r"set\(SHERPA_NCNN_VERSION (.*)\)", content).group(1)
+    return version.strip('"')
+
+
+def read_proj_file(filename):
+    with open(filename) as f:
+        return f.read()
+
+
+def get_dict():
+    version = get_version()
+    return {
+        "version": get_version(),
+    }
+
+
+def process_linux(s):
+    libs = [
+        "libkaldi-native-fbank-core.so",
+        "libncnn.so",
+        "libsherpa-ncnn-c-api.so",
+        "libsherpa-ncnn-core.so",
+        "libgomp-a34b3233.so.1.0.0",
+    ]
+    prefix = f"{SHERPA_NCNN_DIR}/linux/sherpa_ncnn/lib/"
+    libs = [prefix + lib for lib in libs]
+    libs = "\n      ;".join(libs)
+
+    d = get_dict()
+    d["dotnet_rid"] = "linux-x64"
+    d["libs"] = libs
+
+    environment = jinja2.Environment()
+    template = environment.from_string(s)
+    s = template.render(**d)
+    with open("./linux/sherpa-ncnn.runtime.csproj", "w") as f:
+        f.write(s)
+
+
+def process_macos(s):
+    libs = [
+        "libkaldi-native-fbank-core.dylib",
+        "libncnn.dylib",
+        "libsherpa-ncnn-c-api.dylib",
+        "libsherpa-ncnn-core.dylib",
+    ]
+    prefix = f"{SHERPA_NCNN_DIR}/macos/sherpa_ncnn/lib/"
+    libs = [prefix + lib for lib in libs]
+    libs = "\n      ;".join(libs)
+
+    d = get_dict()
+    d["dotnet_rid"] = "osx-x64"
+    d["libs"] = libs
+
+    environment = jinja2.Environment()
+    template = environment.from_string(s)
+    s = template.render(**d)
+    with open("./macos/sherpa-ncnn.runtime.csproj", "w") as f:
+        f.write(s)
+
+
+def process_windows(s):
+    libs = [
+        "kaldi-native-fbank-core.dll",
+        "ncnn.dll",
+        "sherpa-ncnn-c-api.dll",
+        "sherpa-ncnn-core.dll",
+    ]
+    prefix = f"{SHERPA_NCNN_DIR}/windows/sherpa_ncnn/lib/"
+    libs = [prefix + lib for lib in libs]
+    libs = "\n      ;".join(libs)
+
+    d = get_dict()
+    d["dotnet_rid"] = "win-x64"
+    d["libs"] = libs
+
+    environment = jinja2.Environment()
+    template = environment.from_string(s)
+    s = template.render(**d)
+    with open("./windows/sherpa-ncnn.runtime.csproj", "w") as f:
+        f.write(s)
+
+
+def main():
+    s = read_proj_file("./sherpa-ncnn.csproj.runtime.in")
+    process_linux(s)
+    process_macos(s)
+    process_windows(s)
+
+    s = read_proj_file("./sherpa-ncnn.csproj.in")
+    d = get_dict()
+    d["packages_dir"] = str(SHERPA_NCNN_DIR / "scripts/dotnet/packages")
+
+    environment = jinja2.Environment()
+    template = environment.from_string(s)
+    s = template.render(**d)
+    with open("./all/sherpa-ncnn.csproj", "w") as f:
+        f.write(s)
+
+
+if __name__ == "__main__":
+    main()

+ 4 - 35
sherpa-ncnn/csharp-api/notes.md → scripts/dotnet/notes.md

@@ -28,41 +28,8 @@ dotnet --info
 ./dotnet-install.sh --runtime dotnet --install-dir /star-fj/fangjun/software/dotnet/
 ```
 
-# Build Nuget packages
-```bash
-cd /tmp
-git clone http://github.com/k2-fsa/sherpa-ncnn
-cd sherpa-ncnn
-
-mkdir build
-cd build
-cmake -DBUILD_SHARED_LIBS=ON -DSHERPA_NCNN_ENABLE_DOT_NET_API=ON -DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF ..
-make -j 6 sherpa-ncnn-dot-net-package
-
-ls -lh packages
-
-dotnet nuget add source --name my-source $PWD/packages
-
-dotnet nuget list source
-```
+# Test sherpa-ncnn nuget packages
 
-If you are using Linux, you will see the following output:
-```bash
-$ ls -lh  packages/
-total 2.3M
--rw-r--r-- 1 kuangfangjun root  14K May  2 17:42 org.k2fsa.sherpa.ncnn.1.8.1.nupkg
--rw-r--r-- 1 kuangfangjun root 2.3M May  2 17:42 org.k2fsa.sherpa.ncnn.runtime.linux-x64.1.8.1.nupkg
-```
-
-If you are using macOS, you will see the following output:
-```bash
-$ ls -lh packages/
-total 5200
--rw-r--r--  1 fangjun  staff    13K May  2 17:17 org.k2fsa.sherpa.ncnn.1.8.1.nupkg
--rw-r--r--  1 fangjun  staff   2.5M May  2 17:17 org.k2fsa.sherpa.ncnn.runtime.osx-x64.1.8.1.nupkg
-```
-
-# Test the generated packages
 ```bash
 cd /tmp
 mkdir hello
@@ -74,7 +41,9 @@ dotnet new console -o test-sherpa-ncnn
 
 dotnet sln add ./test-sherpa-ncnn/test-sherpa-ncnn.csproj
 cd test-sherpa-ncnn
-dotnet add package org.k2fsa.sherpa.ncnn -v 1.8.1
+
+# please always use the latest version.
+dotnet add package org.k2fsa.sherpa.ncnn -v 1.9.0
 ```
 
 # Notes about dotnet

+ 1 - 0
scripts/dotnet/requirements.txt

@@ -0,0 +1 @@
+Jinja2

+ 32 - 0
scripts/dotnet/run.sh

@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+# Copyright (c)  2023  Xiaomi Corporation
+
+set -ex
+
+mkdir -p macos linux windows all
+
+cp ./sherpa-ncnn.cs all
+
+./generate.py
+
+pushd linux
+dotnet build -c Release
+dotnet pack -c Release -o ../packages
+popd
+
+pushd macos
+dotnet build -c Release
+dotnet pack -c Release -o ../packages
+popd
+
+pushd windows
+dotnet build -c Release
+dotnet pack -c Release -o ../packages
+popd
+
+pushd all
+dotnet build -c Release
+dotnet pack -c Release -o ../packages
+popd
+
+ls -lh packages

+ 0 - 8
sherpa-ncnn/csharp-api/sherpa-ncnn.cs → scripts/dotnet/sherpa-ncnn.cs

@@ -108,11 +108,7 @@ public class OnlineRecognizer : IDisposable {
 
   private HandleRef _handle;
 
-#if LINUX
-  private const string dllName = "libsherpa-ncnn-c-api.so";
-#else
   private const string dllName = "sherpa-ncnn-c-api";
-#endif
 
   [DllImport(dllName, EntryPoint="CreateRecognizer")]
   public static extern IntPtr CreateOnlineRecognizer(ref OnlineRecognizerConfig config);
@@ -170,11 +166,7 @@ public class OnlineStream : IDisposable {
   private HandleRef _handle;
   public IntPtr Handle => _handle.Handle;
 
-#if LINUX
-  private const string dllName = "libsherpa-ncnn-c-api.so";
-#else
   private const string dllName = "sherpa-ncnn-c-api";
-#endif
 
   [DllImport(dllName, EntryPoint="DestroyStream")]
   public static extern void DestroyOnlineStream(IntPtr handle);

+ 7 - 14
sherpa-ncnn/csharp-api/sherpa-ncnn.csproj.in → scripts/dotnet/sherpa-ncnn.csproj.in

@@ -8,7 +8,7 @@
     <RuntimeIdentifiers>linux-x64;osx-x64;win-x64</RuntimeIdentifiers>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <AssemblyName>sherpa-ncnn</AssemblyName>
-    <Version>@SHERPA_NCNN_VERSION@</Version>
+    <Version>{{ version }}</Version>
 
     <PackageProjectUrl>https://github.com/k2-fsa/sherpa-ncnn</PackageProjectUrl>
     <RepositoryUrl>https://github.com/k2-fsa/sherpa-ncnn</RepositoryUrl>
@@ -30,10 +30,8 @@
     </Description>
 
     <!-- Pack Option -->
-    <Title>sherpa-ncnn v@SHERPA_NCNN_VERSION@</Title>
+    <Title>sherpa-ncnn v{{ version }}</Title>
     <PackageId>org.k2fsa.sherpa.ncnn</PackageId>
-    <IncludeSymbols>true</IncludeSymbols>
-    <SymbolPackageFormat>snupkg</SymbolPackageFormat>
 
     <!-- Signing -->
     <SignAssembly>false</SignAssembly>
@@ -42,22 +40,17 @@
   </PropertyGroup>
 
   <PropertyGroup>
-    <IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
+    <RestoreSources>{{ packages_dir }};$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
   </PropertyGroup>
 
-  <PropertyGroup Condition="'$(IsLinux)'=='true'">
-   <DefineConstants>Linux</DefineConstants>
-  </PropertyGroup>
-
-
   <ItemGroup>
-    <None Include="./README.md" Pack="true" PackagePath="/"/>
+    <None Include="../README.md" Pack="true" PackagePath="/"/>
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="org.k2fsa.sherpa.ncnn.runtime.linux-x64" Version="@SHERPA_NCNN_VERSION@" />
-    <PackageReference Include="org.k2fsa.sherpa.ncnn.runtime.osx-x64"   Version="@SHERPA_NCNN_VERSION@" />
-    <PackageReference Include="org.k2fsa.sherpa.ncnn.runtime.win-x64"   Version="@SHERPA_NCNN_VERSION@" />
+    <PackageReference Include="org.k2fsa.sherpa.ncnn.runtime.linux-x64" Version="{{ version }}" />
+    <PackageReference Include="org.k2fsa.sherpa.ncnn.runtime.osx-x64"   Version="{{ version }}" />
+    <PackageReference Include="org.k2fsa.sherpa.ncnn.runtime.win-x64"   Version="{{ version }}" />
   </ItemGroup>
 
 </Project>

+ 13 - 11
sherpa-ncnn/csharp-api/sherpa-ncnn.csproj.runtime.in → scripts/dotnet/sherpa-ncnn.csproj.runtime.in

@@ -4,9 +4,9 @@
     <PackageReadmeFile>README.md</PackageReadmeFile>
     <OutputType>Library</OutputType>
     <TargetFrameworks>netstandard2.0;netcoreapp3.1;net6.0</TargetFrameworks>
-    <RuntimeIdentifier>@SHERPA_NCNN_DOTNET_RID@</RuntimeIdentifier>
+    <RuntimeIdentifier>{{ dotnet_rid }}</RuntimeIdentifier>
     <AssemblyName>sherpa-ncnn</AssemblyName>
-    <Version>@SHERPA_NCNN_VERSION@</Version>
+    <Version>{{ version }}</Version>
 
     <PackageProjectUrl>https://github.com/k2-fsa/sherpa-ncnn</PackageProjectUrl>
     <RepositoryUrl>https://github.com/k2-fsa/sherpa-ncnn</RepositoryUrl>
@@ -14,12 +14,17 @@
       privacy open-sourced next-gen-kaldi k2 kaldi2 sherpa-ncnn</PackageTags>
 
     <!-- Nuget Properties -->
-    <Description>.NET native wrapper for the sherpa-ncnn project</Description>
+    <Description>.NET native {{ dotnet_rid }} wrapper for the sherpa-ncnn project.
+
+    In general, you don't need to use this package directly.
+
+    Please use https://www.nuget.org/packages/org.k2fsa.sherpa.ncnn instead
+    </Description>
     <IncludeBuildOutput>false</IncludeBuildOutput>
 
     <!-- Pack Option -->
-    <Title>sherpa-ncnn @SHERPA_NCNN_DOTNET_RID@ v@SHERPA_NCNN_VERSION@</Title>
-    <PackageId>org.k2fsa.sherpa.ncnn.runtime.@SHERPA_NCNN_DOTNET_RID@</PackageId>
+    <Title>sherpa-ncnn {{ dotnet_rid }} v{{ version }}</Title>
+    <PackageId>org.k2fsa.sherpa.ncnn.runtime.{{ dotnet_rid }}</PackageId>
 
     <!-- Signing -->
     <SignAssembly>false</SignAssembly>
@@ -28,19 +33,16 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <None Include="./README.md" Pack="true" PackagePath="/"/>
+    <None Include="../README.md" Pack="true" PackagePath="/"/>
   </ItemGroup>
 
   <ItemGroup>
     <!-- Native library must be in native directory... -->
     <!-- If project is built as a STATIC_LIBRARY (e.g. Windows) then we don't have to include it -->
     <Content Include="
-      $<TARGET_FILE:ncnn>
-      ;$<TARGET_FILE:kaldi-native-fbank-core>
-      ;$<TARGET_FILE:sherpa-ncnn-c-api>
-      ;$<TARGET_FILE:sherpa-ncnn-core>
+      {{ libs }}
     ">
-      <PackagePath>runtimes/@SHERPA_NCNN_DOTNET_RID@/native/%(Filename)%(Extension)</PackagePath>
+      <PackagePath>runtimes/{{ dotnet_rid }}/native/%(Filename)%(Extension)</PackagePath>
       <Pack>true</Pack>
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>

+ 0 - 4
sherpa-ncnn/CMakeLists.txt

@@ -4,10 +4,6 @@ if(SHERPA_NCNN_ENABLE_C_API)
   add_subdirectory(c-api)
 endif()
 
-if(SHERPA_NCNN_ENABLE_DOT_NET_API)
-  add_subdirectory(csharp-api)
-endif()
-
 if(SHERPA_NCNN_ENABLE_JNI)
   add_subdirectory(jni)
 endif()

+ 0 - 120
sherpa-ncnn/csharp-api/CMakeLists.txt

@@ -1,120 +0,0 @@
-find_program(DOTNET_EXECUTABLE NAMES dotnet)
-if(NOT DOTNET_EXECUTABLE)
-  message(FATAL_ERROR "Cannot find the executable dotnet.")
-endif()
-
-message(STATUS "DOTNET_EXECUTABLE: ${DOTNET_EXECUTABLE}")
-
-# Runtime IDentifier
-# see: https://docs.microsoft.com/en-us/dotnet/core/rid-catalog
-if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)")
-  set(SHERPA_NCNN_DOTNET_PLATFORM arm64)
-else()
-  set(SHERPA_NCNN_DOTNET_PLATFORM x64)
-endif()
-
-if(APPLE)
-  set(SHERPA_NCNN_DOTNET_RID osx-${SHERPA_NCNN_DOTNET_PLATFORM})
-elseif(UNIX)
-  set(SHERPA_NCNN_DOTNET_RID linux-${SHERPA_NCNN_DOTNET_PLATFORM})
-elseif(WIN32)
-  set(SHERPA_NCNN_DOTNET_RID win-${SHERPA_NCNN_DOTNET_PLATFORM})
-else()
-  message(FATAL_ERROR "Unsupported system ${CMAKE_SYSTEM_NAME}!")
-endif()
-
-message(STATUS ".Net RID: ${SHERPA_NCNN_DOTNET_RID}")
-set(MY_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
-
-configure_file(
-  ${CMAKE_CURRENT_LIST_DIR}/sherpa-ncnn.csproj.runtime.in
-  ${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID}/sherpa-ncnn.csproj.in
-  @ONLY)
-
-file(GENERATE
-  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${SHERPA_NCNN_DOTNET_RID}/sherpa-ncnn.csproj
-  INPUT ${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID}/sherpa-ncnn.csproj.in)
-
-add_custom_command(
-  OUTPUT ${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID}/timestamp
-  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/README.md ${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID}/README.md
-  COMMAND ${CMAKE_COMMAND} -E env --unset=TARGETNAME ${DOTNET_EXECUTABLE} build -c Release /p:Platform=${SHERPA_NCNN_DOTNET_PLATFORM} sherpa-ncnn.csproj
-  COMMAND ${CMAKE_COMMAND} -E env --unset=TARGETNAME ${DOTNET_EXECUTABLE} pack -c Release sherpa-ncnn.csproj
-  COMMAND ${CMAKE_COMMAND} -E touch ${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID}/timestamp
-  DEPENDS
-    ${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID}/sherpa-ncnn.csproj
-    ${CMAKE_CURRENT_LIST_DIR}/README.md
-    sherpa-ncnn-c-api
-  BYPRODUCTS
-    ${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID}/bin
-    ${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID}/obj
-  VERBATIM
-  COMMENT "Generate .Net native package ${SHERPA_NCNN_DOTNET_RID} (${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID}/timestamp)"
-  WORKING_DIRECTORY ${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID})
-
-add_custom_target(_sherpa-ncnn-native-dot-net-package
-  DEPENDS
-    ${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID}/timestamp
-  )
-
-set(SHERPA_NCNN_DOTNET_PACKAGES_DIR "${PROJECT_BINARY_DIR}/packages")
-message(STATUS "SHERPA_NCNN_DOTNET_PACKAGES_DIR ${SHERPA_NCNN_DOTNET_PACKAGES_DIR}")
-file(MAKE_DIRECTORY ${SHERPA_NCNN_DOTNET_PACKAGES_DIR})
-
-add_custom_command(
-  OUTPUT ${SHERPA_NCNN_DOTNET_PACKAGES_DIR}/org.k2fsa.sherpa.ncnn.runtime.${SHERPA_NCNN_DOTNET_RID}.${SHERPA_NCNN_VERSION}.nupkg
-  COMMAND
-    ${CMAKE_COMMAND} -E copy bin/$<CONFIG>/org.k2fsa.sherpa.ncnn.runtime.${SHERPA_NCNN_DOTNET_RID}.${SHERPA_NCNN_VERSION}.nupkg ${SHERPA_NCNN_DOTNET_PACKAGES_DIR}/org.k2fsa.sherpa.ncnn.runtime.${SHERPA_NCNN_DOTNET_RID}.${SHERPA_NCNN_VERSION}.nupkg
-  DEPENDS
-    ${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID}/timestamp
-  WORKING_DIRECTORY ${MY_CURRENT_BINARY_DIR}/${SHERPA_NCNN_DOTNET_RID})
-
-add_custom_target(sherpa-ncnn-native-dot-net-package
-  DEPENDS
-    ${SHERPA_NCNN_DOTNET_PACKAGES_DIR}/org.k2fsa.sherpa.ncnn.runtime.${SHERPA_NCNN_DOTNET_RID}.${SHERPA_NCNN_VERSION}.nupkg)
-
-# Now for the wrapper
-
-file(MAKE_DIRECTORY ${MY_CURRENT_BINARY_DIR}/wrapper)
-
-configure_file(
-  ${CMAKE_CURRENT_LIST_DIR}/sherpa-ncnn.csproj.in
-  ${MY_CURRENT_BINARY_DIR}/wrapper/sherpa-ncnn.csproj
-  @ONLY)
-
-add_custom_command(
-  OUTPUT ${MY_CURRENT_BINARY_DIR}/wrapper/timestamp
-  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/README.md ${MY_CURRENT_BINARY_DIR}/wrapper/README.md
-  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/sherpa-ncnn.cs ${MY_CURRENT_BINARY_DIR}/wrapper/sherpa-ncnn.cs
-  COMMAND ${CMAKE_COMMAND} -E env --unset=TARGETNAME ${DOTNET_EXECUTABLE} build -c Release sherpa-ncnn.csproj
-  COMMAND ${CMAKE_COMMAND} -E env --unset=TARGETNAME ${DOTNET_EXECUTABLE} pack -c Release sherpa-ncnn.csproj
-  COMMAND ${CMAKE_COMMAND} -E touch ${MY_CURRENT_BINARY_DIR}/wrapper/timestamp
-  DEPENDS
-    ${CMAKE_CURRENT_LIST_DIR}/sherpa-ncnn.csproj.in
-    ${CMAKE_CURRENT_LIST_DIR}/README.md
-    ${CMAKE_CURRENT_LIST_DIR}/sherpa-ncnn.cs
-    _sherpa-ncnn-native-dot-net-package
-  BYPRODUCTS
-    ${MY_CURRENT_BINARY_DIR}/wrapper/bin
-    ${MY_CURRENT_BINARY_DIR}/wrapper/obj
-  VERBATIM
-  COMMENT "Generate .Net package (${MY_CURRENT_BINARY_DIR}/wrapper/timestamp)"
-  WORKING_DIRECTORY ${MY_CURRENT_BINARY_DIR}/wrapper)
-
-add_custom_target(_sherpa-ncnn-dot-net-package
-  DEPENDS
-    ${MY_CURRENT_BINARY_DIR}/wrapper/timestamp
-  )
-
-add_custom_command(
-  OUTPUT ${SHERPA_NCNN_DOTNET_PACKAGES_DIR}/org.k2fsa.sherpa.ncnn.${SHERPA_NCNN_VERSION}.nupkg
-  COMMAND
-    ${CMAKE_COMMAND} -E copy bin/$<CONFIG>/org.k2fsa.sherpa.ncnn.${SHERPA_NCNN_VERSION}.nupkg ${SHERPA_NCNN_DOTNET_PACKAGES_DIR}/org.k2fsa.sherpa.ncnn.${SHERPA_NCNN_VERSION}.nupkg
-  DEPENDS
-    ${MY_CURRENT_BINARY_DIR}/wrapper/timestamp
-    sherpa-ncnn-native-dot-net-package
-  WORKING_DIRECTORY ${MY_CURRENT_BINARY_DIR}/wrapper)
-
-add_custom_target(sherpa-ncnn-dot-net-package
-  DEPENDS
-    ${SHERPA_NCNN_DOTNET_PACKAGES_DIR}/org.k2fsa.sherpa.ncnn.${SHERPA_NCNN_VERSION}.nupkg)