Fangjun Kuang
Committed by GitHub

Publish osx-arm64 nuget package for .Net (#1003)

@@ -64,7 +64,7 @@ def process_linux(s): @@ -64,7 +64,7 @@ def process_linux(s):
64 f.write(s) 64 f.write(s)
65 65
66 66
67 -def process_macos(s): 67 +def process_macos(s, rid):
68 libs = [ 68 libs = [
69 "libespeak-ng.dylib", 69 "libespeak-ng.dylib",
70 "libkaldi-decoder-core.dylib", 70 "libkaldi-decoder-core.dylib",
@@ -79,18 +79,18 @@ def process_macos(s): @@ -79,18 +79,18 @@ def process_macos(s):
79 "libsherpa-onnx-kaldifst-core.dylib", 79 "libsherpa-onnx-kaldifst-core.dylib",
80 "libucd.dylib", 80 "libucd.dylib",
81 ] 81 ]
82 - prefix = f"{src_dir}/macos/" 82 + prefix = f"{src_dir}/macos-{rid}/"
83 libs = [prefix + lib for lib in libs] 83 libs = [prefix + lib for lib in libs]
84 libs = "\n ;".join(libs) 84 libs = "\n ;".join(libs)
85 85
86 d = get_dict() 86 d = get_dict()
87 - d["dotnet_rid"] = "osx-x64" 87 + d["dotnet_rid"] = f"osx-{rid}"
88 d["libs"] = libs 88 d["libs"] = libs
89 89
90 environment = jinja2.Environment() 90 environment = jinja2.Environment()
91 template = environment.from_string(s) 91 template = environment.from_string(s)
92 s = template.render(**d) 92 s = template.render(**d)
93 - with open("./macos/sherpa-onnx.runtime.csproj", "w") as f: 93 + with open(f"./macos-{rid}/sherpa-onnx.runtime.csproj", "w") as f:
94 f.write(s) 94 f.write(s)
95 95
96 96
@@ -129,7 +129,8 @@ def process_windows(s, rid): @@ -129,7 +129,8 @@ def process_windows(s, rid):
129 129
130 def main(): 130 def main():
131 s = read_proj_file("./sherpa-onnx.csproj.runtime.in") 131 s = read_proj_file("./sherpa-onnx.csproj.runtime.in")
132 - process_macos(s) 132 + process_macos(s, "x64")
  133 + process_macos(s, "arm64")
133 process_linux(s) 134 process_linux(s)
134 process_windows(s, "x64") 135 process_windows(s, "x64")
135 process_windows(s, "x86") 136 process_windows(s, "x86")
@@ -24,14 +24,16 @@ export src_dir @@ -24,14 +24,16 @@ 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 windows-x64 windows-x86  
28 - 27 +mkdir -p linux macos-x64 macos-arm64 windows-x64 windows-x86
29 28
30 linux_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl 29 linux_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
31 linux_wheel=$src_dir/$linux_wheel_filename 30 linux_wheel=$src_dir/$linux_wheel_filename
32 31
33 -macos_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp39-cp39-macosx_10_14_universal2.whl  
34 -macos_wheel=$src_dir/$macos_wheel_filename 32 +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
  34 +
  35 +macos_arm64_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp39-cp39-macosx_11_0_arm64.whl
  36 +macos_arm64_wheel=$src_dir/$macos_arm64_wheel_filename
35 37
36 windows_x64_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-win_amd64.whl 38 windows_x64_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-win_amd64.whl
37 windows_x64_wheel=$src_dir/$windows_x64_wheel_filename 39 windows_x64_wheel=$src_dir/$windows_x64_wheel_filename
@@ -60,17 +62,17 @@ if [ ! -f $src_dir/linux/libsherpa-onnx-core.so ]; then @@ -60,17 +62,17 @@ if [ ! -f $src_dir/linux/libsherpa-onnx-core.so ]; then
60 cd .. 62 cd ..
61 fi 63 fi
62 64
63 -if [ ! -f $src_dir/macos/libsherpa-onnx-core.dylib ]; then  
64 - echo "--- macOS x86_64/arm64 universal2---"  
65 - cd macos 65 +if [ ! -f $src_dir/macos-x64/libsherpa-onnx-core.dylib ]; then
  66 + echo "--- macOS x86_64---"
  67 + cd macos-x64
66 mkdir -p wheel 68 mkdir -p wheel
67 cd wheel 69 cd wheel
68 - if [ -f $macos_wheel ]; then  
69 - cp -v $macos_wheel . 70 + if [ -f $macos_x64_wheel ]; then
  71 + cp -v $macos_x64_wheel .
70 else 72 else
71 - curl -OL https://$HF_MIRROR/csukuangfj/sherpa-onnx-wheels/resolve/main/$macos_wheel_filename 73 + curl -OL https://$HF_MIRROR/csukuangfj/sherpa-onnx-wheels/resolve/main/$macos_x64_wheel_filename
72 fi 74 fi
73 - unzip $macos_wheel_filename 75 + unzip $macos_x64_wheel_filename
74 cp -v sherpa_onnx/lib/*.dylib ../ 76 cp -v sherpa_onnx/lib/*.dylib ../
75 77
76 cd .. 78 cd ..
@@ -83,6 +85,28 @@ if [ ! -f $src_dir/macos/libsherpa-onnx-core.dylib ]; then @@ -83,6 +85,28 @@ if [ ! -f $src_dir/macos/libsherpa-onnx-core.dylib ]; then
83 cd .. 85 cd ..
84 fi 86 fi
85 87
  88 +if [ ! -f $src_dir/macos-arm64/libsherpa-onnx-core.dylib ]; then
  89 + echo "--- macOS arm64---"
  90 + cd macos-arm64
  91 + mkdir -p wheel
  92 + cd wheel
  93 + if [ -f $macos_arm64_wheel ]; then
  94 + cp -v $macos_arm64_wheel .
  95 + else
  96 + curl -OL https://$HF_MIRROR/csukuangfj/sherpa-onnx-wheels/resolve/main/$macos_arm64_wheel_filename
  97 + fi
  98 + unzip $macos_arm64_wheel_filename
  99 + cp -v sherpa_onnx/lib/*.dylib ../
  100 +
  101 + cd ..
  102 +
  103 + rm -v libcargs.dylib
  104 + rm -v libonnxruntime.dylib
  105 + rm -v libpiper_phonemize.1.2.0.dylib libpiper_phonemize.dylib
  106 + rm -rf wheel
  107 + ls -lh
  108 + cd ..
  109 +fi
86 110
87 if [ ! -f $src_dir/windows-x64/sherpa-onnx-core.dll ]; then 111 if [ ! -f $src_dir/windows-x64/sherpa-onnx-core.dll ]; then
88 echo "---windows x64---" 112 echo "---windows x64---"
@@ -124,7 +148,7 @@ fi @@ -124,7 +148,7 @@ fi
124 148
125 popd 149 popd
126 150
127 -mkdir -p macos linux windows-x64 windows-x86 all 151 +mkdir -p macos-x64 macos-arm64 linux windows-x64 windows-x86 all
128 152
129 cp ./*.cs all 153 cp ./*.cs all
130 154
@@ -135,7 +159,12 @@ dotnet build -c Release @@ -135,7 +159,12 @@ dotnet build -c Release
135 dotnet pack -c Release -o ../packages 159 dotnet pack -c Release -o ../packages
136 popd 160 popd
137 161
138 -pushd macos 162 +pushd macos-x64
  163 +dotnet build -c Release
  164 +dotnet pack -c Release -o ../packages
  165 +popd
  166 +
  167 +pushd macos-arm64
139 dotnet build -c Release 168 dotnet build -c Release
140 dotnet pack -c Release -o ../packages 169 dotnet pack -c Release -o ../packages
141 popd 170 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>netstandard2.0</TargetFrameworks> 7 <TargetFrameworks>netstandard2.0</TargetFrameworks>
8 - <RuntimeIdentifiers>linux-x64;osx-x64;win-x64</RuntimeIdentifiers> 8 + <RuntimeIdentifiers>linux-x64;osx-x64;osx-arm64;win-x64;win-x86</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>
@@ -50,6 +50,7 @@ @@ -50,6 +50,7 @@
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.osx-x64" Version="{{ version }}" /> 52 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.osx-x64" Version="{{ version }}" />
  53 + <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.osx-arm64" Version="{{ version }}" />
53 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x64" Version="{{ version }}" /> 54 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x64" Version="{{ version }}" />
54 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x86" Version="{{ version }}" /> 55 <PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x86" Version="{{ version }}" />
55 </ItemGroup> 56 </ItemGroup>