Skip to content

Commit 7f25941

Browse files
authored
Publish osx-arm64 nuget package for .Net (k2-fsa#1003)
1 parent 967faa3 commit 7f25941

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

scripts/dotnet/generate.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def process_linux(s):
6464
f.write(s)
6565

6666

67-
def process_macos(s):
67+
def process_macos(s, rid):
6868
libs = [
6969
"libespeak-ng.dylib",
7070
"libkaldi-decoder-core.dylib",
@@ -79,18 +79,18 @@ def process_macos(s):
7979
"libsherpa-onnx-kaldifst-core.dylib",
8080
"libucd.dylib",
8181
]
82-
prefix = f"{src_dir}/macos/"
82+
prefix = f"{src_dir}/macos-{rid}/"
8383
libs = [prefix + lib for lib in libs]
8484
libs = "\n ;".join(libs)
8585

8686
d = get_dict()
87-
d["dotnet_rid"] = "osx-x64"
87+
d["dotnet_rid"] = f"osx-{rid}"
8888
d["libs"] = libs
8989

9090
environment = jinja2.Environment()
9191
template = environment.from_string(s)
9292
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:
9494
f.write(s)
9595

9696

@@ -129,7 +129,8 @@ def process_windows(s, rid):
129129

130130
def main():
131131
s = read_proj_file("./sherpa-onnx.csproj.runtime.in")
132-
process_macos(s)
132+
process_macos(s, "x64")
133+
process_macos(s, "arm64")
133134
process_linux(s)
134135
process_windows(s, "x64")
135136
process_windows(s, "x86")

scripts/dotnet/run.sh

+42-13
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ export src_dir
2424
mkdir -p $src_dir
2525
pushd $src_dir
2626

27-
mkdir -p linux macos windows-x64 windows-x86
28-
27+
mkdir -p linux macos-x64 macos-arm64 windows-x64 windows-x86
2928

3029
linux_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
3130
linux_wheel=$src_dir/$linux_wheel_filename
3231

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
3537

3638
windows_x64_wheel_filename=sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-win_amd64.whl
3739
windows_x64_wheel=$src_dir/$windows_x64_wheel_filename
@@ -60,17 +62,17 @@ if [ ! -f $src_dir/linux/libsherpa-onnx-core.so ]; then
6062
cd ..
6163
fi
6264

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
6668
mkdir -p wheel
6769
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 .
7072
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
7274
fi
73-
unzip $macos_wheel_filename
75+
unzip $macos_x64_wheel_filename
7476
cp -v sherpa_onnx/lib/*.dylib ../
7577

7678
cd ..
@@ -83,6 +85,28 @@ if [ ! -f $src_dir/macos/libsherpa-onnx-core.dylib ]; then
8385
cd ..
8486
fi
8587

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
86110

87111
if [ ! -f $src_dir/windows-x64/sherpa-onnx-core.dll ]; then
88112
echo "---windows x64---"
@@ -124,7 +148,7 @@ fi
124148

125149
popd
126150

127-
mkdir -p macos linux windows-x64 windows-x86 all
151+
mkdir -p macos-x64 macos-arm64 linux windows-x64 windows-x86 all
128152

129153
cp ./*.cs all
130154

@@ -135,7 +159,12 @@ dotnet build -c Release
135159
dotnet pack -c Release -o ../packages
136160
popd
137161

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
139168
dotnet build -c Release
140169
dotnet pack -c Release -o ../packages
141170
popd

scripts/dotnet/sherpa-onnx.csproj.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<OutputType>Library</OutputType>
66
<LangVersion>10.0</LangVersion>
77
<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>
99
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1010
<AssemblyName>sherpa-onnx</AssemblyName>
1111
<Version>{{ version }}</Version>
@@ -50,6 +50,7 @@
5050
<ItemGroup>
5151
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.linux-x64" Version="{{ version }}" />
5252
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.osx-x64" Version="{{ version }}" />
53+
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.osx-arm64" Version="{{ version }}" />
5354
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x64" Version="{{ version }}" />
5455
<PackageReference Include="org.k2fsa.sherpa.onnx.runtime.win-x86" Version="{{ version }}" />
5556
</ItemGroup>

0 commit comments

Comments
 (0)