Fangjun Kuang
Committed by GitHub

Support linux-arm64 for .Net (#1092)

@@ -34,23 +34,23 @@ def get_dict(): @@ -34,23 +34,23 @@ def get_dict():
34 } 34 }
35 35
36 36
37 -def process_linux(s): 37 +def process_linux(s, rid):
38 libs = [ 38 libs = [
39 "libonnxruntime.so.1.17.1", 39 "libonnxruntime.so.1.17.1",
40 "libsherpa-onnx-c-api.so", 40 "libsherpa-onnx-c-api.so",
41 ] 41 ]
42 - prefix = f"{src_dir}/linux/" 42 + prefix = f"{src_dir}/linux-{rid}/"
43 libs = [prefix + lib for lib in libs] 43 libs = [prefix + lib for lib in libs]
44 libs = "\n ;".join(libs) 44 libs = "\n ;".join(libs)
45 45
46 d = get_dict() 46 d = get_dict()
47 - d["dotnet_rid"] = "linux-x64" 47 + d["dotnet_rid"] = f"linux-{rid}"
48 d["libs"] = libs 48 d["libs"] = libs
49 49
50 environment = jinja2.Environment() 50 environment = jinja2.Environment()
51 template = environment.from_string(s) 51 template = environment.from_string(s)
52 s = template.render(**d) 52 s = template.render(**d)
53 - with open("./linux/sherpa-onnx.runtime.csproj", "w") as f: 53 + with open(f"./linux-{rid}/sherpa-onnx.runtime.csproj", "w") as f:
54 f.write(s) 54 f.write(s)
55 55
56 56
@@ -101,7 +101,8 @@ def main(): @@ -101,7 +101,8 @@ def main():
101 s = read_proj_file("./sherpa-onnx.csproj.runtime.in") 101 s = read_proj_file("./sherpa-onnx.csproj.runtime.in")
102 process_macos(s, "x64") 102 process_macos(s, "x64")
103 process_macos(s, "arm64") 103 process_macos(s, "arm64")
104 - process_linux(s) 104 + process_linux(s, "x64")
  105 + process_linux(s, "arm64")
105 process_windows(s, "x64") 106 process_windows(s, "x64")
106 process_windows(s, "x86") 107 process_windows(s, "x86")
107 process_windows(s, "arm64") 108 process_windows(s, "arm64")
@@ -24,10 +24,13 @@ export src_dir @@ -24,10 +24,13 @@ export src_dir
24 mkdir -p $src_dir 24 mkdir -p $src_dir
25 pushd $src_dir 25 pushd $src_dir
26 26
27 -mkdir -p linux macos-x64 macos-arm64 windows-x64 windows-x86 windows-arm64 27 +mkdir -p linux-x64 linux-arm64 macos-x64 macos-arm64 windows-x64 windows-x86 windows-arm64
28 28
29 -linux_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl  
30 -linux_wheel=$src_dir/$linux_wheel_filename 29 +linux_x64_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  30 +linux_x64_wheel=$src_dir/$linux_x64_wheel_filename
  31 +
  32 +linux_arm64_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  33 +linux_arm64_wheel=$src_dir/$linux_arm64_wheel_filename
31 34
32 macos_x64_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp39-cp39-macosx_11_0_x86_64.whl 35 macos_x64_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp39-cp39-macosx_11_0_x86_64.whl
33 macos_x64_wheel=$src_dir/$macos_x64_wheel_filename 36 macos_x64_wheel=$src_dir/$macos_x64_wheel_filename
@@ -44,17 +47,35 @@ windows_x86_wheel=$src_dir/$windows_x86_wheel_filename @@ -44,17 +47,35 @@ windows_x86_wheel=$src_dir/$windows_x86_wheel_filename
44 windows_arm64_wheel_filename=sherpa-onnx-${SHERPA_ONNX_VERSION}-win-arm64.tar.bz2 47 windows_arm64_wheel_filename=sherpa-onnx-${SHERPA_ONNX_VERSION}-win-arm64.tar.bz2
45 windows_arm64_wheel=$src_dir/$windows_arm64_wheel_filename 48 windows_arm64_wheel=$src_dir/$windows_arm64_wheel_filename
46 49
47 -if [ ! -f $src_dir/linux/libsherpa-onnx-c-api.so ]; then 50 +if [ ! -f $src_dir/linux-x64/libsherpa-onnx-c-api.so ]; then
48 echo "---linux x86_64---" 51 echo "---linux x86_64---"
49 - cd linux 52 + cd linux-x64
  53 + mkdir -p wheel
  54 + cd wheel
  55 + if [ -f $linux_x64_wheel ]; then
  56 + cp -v $linux_x64_wheel .
  57 + else
  58 + curl -OL https://$HF_MIRROR/csukuangfj/sherpa-onnx-wheels/resolve/main/$linux_x64_wheel_filename
  59 + fi
  60 + unzip $linux_x64_wheel_filename
  61 + cp -v sherpa_onnx/lib/*.so* ../
  62 + cd ..
  63 + rm -rf wheel
  64 + ls -lh
  65 + cd ..
  66 +fi
  67 +
  68 +if [ ! -f $src_dir/linux-arm64/libsherpa-onnx-c-api.so ]; then
  69 + echo "---linux arm64---"
  70 + cd linux-arm64
50 mkdir -p wheel 71 mkdir -p wheel
51 cd wheel 72 cd wheel
52 - if [ -f $linux_wheel ]; then  
53 - cp -v $linux_wheel . 73 + if [ -f $linux_arm64_wheel ]; then
  74 + cp -v $linux_arm64_wheel .
54 else 75 else
55 - curl -OL https://$HF_MIRROR/csukuangfj/sherpa-onnx-wheels/resolve/main/$linux_wheel_filename 76 + curl -OL https://$HF_MIRROR/csukuangfj/sherpa-onnx-wheels/resolve/main/$linux_arm64_wheel_filename
56 fi 77 fi
57 - unzip $linux_wheel_filename 78 + unzip $linux_arm64_wheel_filename
58 cp -v sherpa_onnx/lib/*.so* ../ 79 cp -v sherpa_onnx/lib/*.so* ../
59 cd .. 80 cd ..
60 rm -rf wheel 81 rm -rf wheel
@@ -161,13 +182,18 @@ fi @@ -161,13 +182,18 @@ fi
161 182
162 popd 183 popd
163 184
164 -mkdir -p macos-x64 macos-arm64 linux windows-x64 windows-x86 windows-arm64 all 185 +mkdir -p macos-x64 macos-arm64 linux-x64 linux-arm64 windows-x64 windows-x86 windows-arm64 all
165 186
166 cp ./*.cs all 187 cp ./*.cs all
167 188
168 ./generate.py 189 ./generate.py
169 190
170 -pushd linux 191 +pushd linux-x64
  192 +dotnet build -c Release
  193 +dotnet pack -c Release -o ../packages
  194 +popd
  195 +
  196 +pushd linux-arm64
171 dotnet build -c Release 197 dotnet build -c Release
172 dotnet pack -c Release -o ../packages 198 dotnet pack -c Release -o ../packages
173 popd 199 popd
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 <OutputType>Library</OutputType> 5 <OutputType>Library</OutputType>
6 <LangVersion>10.0</LangVersion> 6 <LangVersion>10.0</LangVersion>
7 <TargetFrameworks>net6.0;net45;net40;net35;net20;netstandard2.0</TargetFrameworks> 7 <TargetFrameworks>net6.0;net45;net40;net35;net20;netstandard2.0</TargetFrameworks>
8 - <RuntimeIdentifiers>linux-x64;osx-x64;osx-arm64;win-x64;win-x86;win-arm64</RuntimeIdentifiers> 8 + <RuntimeIdentifiers>linux-x64;linux-arm64;osx-x64;osx-arm64;win-x64;win-x86;win-arm64</RuntimeIdentifiers>
9 <AllowUnsafeBlocks>true</AllowUnsafeBlocks> 9 <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
10 <AssemblyName>sherpa-onnx</AssemblyName> 10 <AssemblyName>sherpa-onnx</AssemblyName>
11 <Version>{{ version }}</Version> 11 <Version>{{ version }}</Version>
@@ -49,6 +49,7 @@ @@ -49,6 +49,7 @@
49 49
50 <ItemGroup> 50 <ItemGroup>
51 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.linux-x64" Version="{{ version }}" /> 51 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.linux-x64" Version="{{ version }}" />
  52 + <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.linux-arm64" Version="{{ version }}" />
52 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.osx-x64" Version="{{ version }}" /> 53 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.osx-x64" Version="{{ version }}" />
53 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.osx-arm64" Version="{{ version }}" /> 54 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.osx-arm64" Version="{{ version }}" />
54 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x64" Version="{{ version }}" /> 55 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x64" Version="{{ version }}" />