Fangjun Kuang
Committed by GitHub

Support linux aarch64 for Dart and Flutter (#2342)

Adds support for building and packaging Linux AArch64 (arm64) artifacts alongside x64 for Dart/Flutter plugins.

- Detects host architecture in CMake and adjusts library paths
- Extends test workflows to run on an ARM runner and handle linux-aarch64 paths
- Splits release pipeline into separate x64 and aarch64 build/package jobs
@@ -14,12 +14,13 @@ concurrency: @@ -14,12 +14,13 @@ concurrency:
14 cancel-in-progress: true 14 cancel-in-progress: true
15 15
16 jobs: 16 jobs:
17 - sherpa_onnx_linux:  
18 - # if: false  
19 - permissions:  
20 - id-token: write # Required for authentication using OIDC  
21 - name: sherpa_onnx_linux  
22 - runs-on: ubuntu-latest 17 + build_linux_libs_x64:
  18 + name: ${{ matrix.os }}
  19 + runs-on: ${{ matrix.os }}
  20 + strategy:
  21 + fail-fast: false
  22 + matrix:
  23 + os: [ubuntu-latest]
23 24
24 steps: 25 steps:
25 - uses: actions/checkout@v4 26 - uses: actions/checkout@v4
@@ -30,37 +31,76 @@ jobs: @@ -30,37 +31,76 @@ jobs:
30 ./new-release.sh 31 ./new-release.sh
31 git diff . 32 git diff .
32 33
33 - - name: Fix version 34 + - name: Build sherpa-onnx
  35 + uses: addnab/docker-run-action@v3
  36 + with:
  37 + image: quay.io/pypa/manylinux2014_x86_64
  38 + options: |
  39 + --volume ${{ github.workspace }}/:/home/runner/work/sherpa-onnx/sherpa-onnx
34 shell: bash 40 shell: bash
35 run: | 41 run: |
36 - SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 42 + uname -a
  43 + gcc --version
  44 + cmake --version
  45 + cat /etc/*release
  46 + id
  47 + pwd
37 48
38 - src_dir=$PWD/flutter/sherpa_onnx_linux  
39 - pushd $src_dir  
40 - v="version: $SHERPA_ONNX_VERSION"  
41 - echo "v: $v"  
42 - sed -i.bak s"/^version: .*/$v/" ./pubspec.yaml  
43 - rm *.bak  
44 - git status  
45 - git diff 49 + cd /home/runner/work/sherpa-onnx/sherpa-onnx
46 50
47 - - name: Copy extra files 51 + mkdir build
  52 + cd build
  53 +
  54 + cmake \
  55 + -D SHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
  56 + -D SHERPA_ONNX_ENABLE_TTS=ON \
  57 + -D CMAKE_BUILD_TYPE=Release \
  58 + -D BUILD_SHARED_LIBS=ON \
  59 + -D CMAKE_INSTALL_PREFIX=./install \
  60 + -D SHERPA_ONNX_ENABLE_JNI=OFF \
  61 + -D SHERPA_ONNX_ENABLE_BINARY=OFF \
  62 + ..
  63 +
  64 + make -j2
  65 + make install
  66 +
  67 + ls -lh ./install/lib
  68 +
  69 + - name: Create tar file
48 shell: bash 70 shell: bash
49 run: | 71 run: |
50 - dst=flutter/sherpa_onnx_linux 72 + mkdir x64
  73 + dst=x64
  74 + cp -v build/install/lib/lib* $dst
  75 + tar cjvf $dst.tar.bz2 $dst
  76 + ls -lh *.tar.bz2
51 77
52 - mkdir $dst/example 78 + - uses: actions/upload-artifact@v4
  79 + with:
  80 + name: linux-x64
  81 + path: ./*.tar.bz2
53 82
54 - cp -v flutter/sherpa_onnx/example/* $dst/example  
55 - cp -v LICENSE $dst/  
56 - cp -v CHANGELOG.md $dst/ 83 + build_linux_libs_aarch64:
  84 + name: ${{ matrix.os }}
  85 + runs-on: ${{ matrix.os }}
  86 + strategy:
  87 + fail-fast: false
  88 + matrix:
  89 + os: [ubuntu-22.04-arm]
57 90
58 - git status 91 + steps:
  92 + - uses: actions/checkout@v4
  93 +
  94 + - name: Update version
  95 + shell: bash
  96 + run: |
  97 + ./new-release.sh
  98 + git diff .
59 99
60 - name: Build sherpa-onnx 100 - name: Build sherpa-onnx
61 uses: addnab/docker-run-action@v3 101 uses: addnab/docker-run-action@v3
62 with: 102 with:
63 - image: quay.io/pypa/manylinux2014_x86_64 103 + image: quay.io/pypa/manylinux2014_aarch64
64 options: | 104 options: |
65 --volume ${{ github.workspace }}/:/home/runner/work/sherpa-onnx/sherpa-onnx 105 --volume ${{ github.workspace }}/:/home/runner/work/sherpa-onnx/sherpa-onnx
66 shell: bash 106 shell: bash
@@ -92,10 +132,93 @@ jobs: @@ -92,10 +132,93 @@ jobs:
92 132
93 ls -lh ./install/lib 133 ls -lh ./install/lib
94 134
  135 + - name: Create tar file
  136 + shell: bash
  137 + run: |
  138 + mkdir aarch64
  139 + dst=aarch64
  140 + cp -v build/install/lib/lib* $dst
  141 + tar cjvf $dst.tar.bz2 $dst
  142 + ls -lh *.tar.bz2
  143 +
  144 + - uses: actions/upload-artifact@v4
  145 + with:
  146 + name: linux-aarch64
  147 + path: ./*.tar.bz2
  148 +
  149 + sherpa_onnx_linux:
  150 + needs: [build_linux_libs_x64, build_linux_libs_aarch64]
  151 + # if: false
  152 + permissions:
  153 + id-token: write # Required for authentication using OIDC
  154 + name: sherpa_onnx_linux
  155 + runs-on: ubuntu-latest
  156 +
  157 + steps:
  158 + - uses: actions/checkout@v4
  159 +
  160 + - name: Update version
  161 + shell: bash
  162 + run: |
  163 + ./new-release.sh
  164 + git diff .
  165 +
  166 + - name: Fix version
  167 + shell: bash
  168 + run: |
  169 + SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
  170 +
  171 + src_dir=$PWD/flutter/sherpa_onnx_linux
  172 + pushd $src_dir
  173 + v="version: $SHERPA_ONNX_VERSION"
  174 + echo "v: $v"
  175 + sed -i.bak s"/^version: .*/$v/" ./pubspec.yaml
  176 + rm *.bak
  177 + git status
  178 + git diff
  179 +
  180 + - name: Retrieve artifact from linux x64
  181 + uses: actions/download-artifact@v4
  182 + with:
  183 + name: linux-x64
  184 + path: /tmp
  185 +
  186 + - name: Retrieve artifact from linux aarch64
  187 + uses: actions/download-artifact@v4
  188 + with:
  189 + name: linux-aarch64
  190 + path: /tmp
  191 +
  192 + - name: Show files
  193 + shell: bash
  194 + run: |
  195 + cd /tmp
  196 + tar xvf x64.tar.bz2
  197 + tar xvf aarch64.tar.bz2
  198 +
  199 + echo "----x64---"
  200 + ls -lh /tmp/x64/
  201 + echo "----aarch64---"
  202 + ls -lh /tmp/aarch64/
  203 +
  204 + - name: Copy extra files
  205 + shell: bash
  206 + run: |
  207 + dst=flutter/sherpa_onnx_linux
  208 +
  209 + mkdir $dst/example
  210 +
  211 + cp -v flutter/sherpa_onnx/example/* $dst/example
  212 + cp -v LICENSE $dst/
  213 + cp -v CHANGELOG.md $dst/
  214 +
  215 + git status
  216 +
95 - name: Copy pre-built libs 217 - name: Copy pre-built libs
96 shell: bash 218 shell: bash
97 run: | 219 run: |
98 - cp -v build/install/lib/lib*.so* flutter/sherpa_onnx_linux/linux/ 220 + cp -v /tmp/x64/lib*.so* flutter/sherpa_onnx_linux/linux/x64
  221 + cp -v /tmp/aarch64/lib*.so* flutter/sherpa_onnx_linux/linux/aarch64
99 222
100 mv -v flutter/sherpa_onnx_linux /tmp/to_be_published 223 mv -v flutter/sherpa_onnx_linux /tmp/to_be_published
101 224
@@ -104,8 +227,8 @@ jobs: @@ -104,8 +227,8 @@ jobs:
104 - name: Setup Flutter SDK 227 - name: Setup Flutter SDK
105 uses: flutter-actions/setup-flutter@v3 228 uses: flutter-actions/setup-flutter@v3
106 with: 229 with:
107 - channel: stable  
108 - version: latest 230 + channel: master
  231 + version: 3.24.0
109 232
110 - uses: dart-lang/setup-dart@v1 233 - uses: dart-lang/setup-dart@v1
111 234
@@ -23,7 +23,7 @@ jobs: @@ -23,7 +23,7 @@ jobs:
23 strategy: 23 strategy:
24 fail-fast: false 24 fail-fast: false
25 matrix: 25 matrix:
26 - os: [macos-latest, ubuntu-latest] #, windows-latest] 26 + os: [ubuntu-latest, macos-latest, ubuntu-24.04-arm] #, windows-latest]
27 27
28 steps: 28 steps:
29 - uses: actions/checkout@v4 29 - uses: actions/checkout@v4
@@ -36,11 +36,12 @@ jobs: @@ -36,11 +36,12 @@ jobs:
36 ./new-release.sh 36 ./new-release.sh
37 git diff . 37 git diff .
38 38
39 - - name: Setup Flutter SDK  
40 - uses: flutter-actions/setup-flutter@v3 39 + # see https://github.com/subosito/flutter-action/issues/345
  40 + - name: Set up Flutter
  41 + uses: subosito/flutter-action@v2
41 with: 42 with:
42 - channel: stable  
43 - version: latest 43 + channel: master
  44 + flutter-version: 3.24.0
44 45
45 - name: Display flutter info 46 - name: Display flutter info
46 shell: bash 47 shell: bash
@@ -58,7 +59,7 @@ jobs: @@ -58,7 +59,7 @@ jobs:
58 cd dart-api-examples/vad 59 cd dart-api-examples/vad
59 flutter pub get 60 flutter pub get
60 61
61 - if [[ ${{ matrix.os }} == ubuntu-latest ]]; then 62 + if [[ ${{ matrix.os }} == ubuntu-latest || ${{ matrix.os }} == ubuntu-24.04-arm ]]; then
62 echo "-----" 63 echo "-----"
63 ls -lh /home/runner/work/_temp/pub-cache/hosted/pub.dev 64 ls -lh /home/runner/work/_temp/pub-cache/hosted/pub.dev
64 65
@@ -75,7 +76,7 @@ jobs: @@ -75,7 +76,7 @@ jobs:
75 # sudo touch /home/runner/work/_temp/pub-cache/hosted/pub.dev/sherpa_onnx_linux-1.10.7/lib/.gitkeep 76 # sudo touch /home/runner/work/_temp/pub-cache/hosted/pub.dev/sherpa_onnx_linux-1.10.7/lib/.gitkeep
76 77
77 echo "-----" 78 echo "-----"
78 - ls -lh /home/runner/work/_temp/pub-cache/hosted/pub.dev/sherpa_onnx_linux-*/linux 79 + ls -lh /home/runner/work/_temp/pub-cache/hosted/pub.dev/sherpa_onnx_linux-*/linux/*
79 elif [[ ${{ matrix.os }} == macos-latest ]]; then 80 elif [[ ${{ matrix.os }} == macos-latest ]]; then
80 echo "-----" 81 echo "-----"
81 ls -lh /Users/runner/work/_temp/pub-cache/hosted/pub.dev 82 ls -lh /Users/runner/work/_temp/pub-cache/hosted/pub.dev
@@ -32,7 +32,7 @@ jobs: @@ -32,7 +32,7 @@ jobs:
32 strategy: 32 strategy:
33 fail-fast: false 33 fail-fast: false
34 matrix: 34 matrix:
35 - os: [ubuntu-latest, macos-latest] #, windows-latest] 35 + os: [ubuntu-latest, macos-latest, ubuntu-24.04-arm] #, windows-latest]
36 36
37 steps: 37 steps:
38 - uses: actions/checkout@v4 38 - uses: actions/checkout@v4
@@ -50,11 +50,12 @@ jobs: @@ -50,11 +50,12 @@ jobs:
50 with: 50 with:
51 key: ${{ matrix.os }}-dart 51 key: ${{ matrix.os }}-dart
52 52
53 - - name: Setup Flutter SDK  
54 - uses: flutter-actions/setup-flutter@v3 53 + # see https://github.com/subosito/flutter-action/issues/345
  54 + - name: Set up Flutter
  55 + uses: subosito/flutter-action@v2
55 with: 56 with:
56 - channel: stable  
57 - version: latest 57 + channel: master
  58 + flutter-version: 3.24.0
58 59
59 - name: Display flutter info 60 - name: Display flutter info
60 shell: bash 61 shell: bash
@@ -91,22 +92,34 @@ jobs: @@ -91,22 +92,34 @@ jobs:
91 shell: bash 92 shell: bash
92 run: | 93 run: |
93 if [[ ${{ matrix.os }} == ubuntu-latest ]]; then 94 if [[ ${{ matrix.os }} == ubuntu-latest ]]; then
94 - os=linux 95 + os=linux-x64
  96 + elif [[ ${{ matrix.os }} == ubuntu-24.04-arm ]]; then
  97 + os=linux-aarch64
95 elif [[ ${{ matrix.os }} == macos-latest ]]; then 98 elif [[ ${{ matrix.os }} == macos-latest ]]; then
96 os=macos 99 os=macos
97 elif [[ ${{ matrix.os }} == windows-latest ]]; then 100 elif [[ ${{ matrix.os }} == windows-latest ]]; then
98 os=windows 101 os=windows
99 fi 102 fi
100 103
  104 + echo "os: $os"
  105 +
101 if [[ $os == windows ]]; then 106 if [[ $os == windows ]]; then
102 cp -fv build/install/lib/*.dll ./flutter/sherpa_onnx_$os/$os 107 cp -fv build/install/lib/*.dll ./flutter/sherpa_onnx_$os/$os
  108 + elif [[ $os == linux-x64 ]]; then
  109 + cp -fv build/install/lib/lib* ./flutter/sherpa_onnx_linux/linux/x64
  110 + elif [[ $os == linux-aarch64 ]]; then
  111 + cp -fv build/install/lib/lib* ./flutter/sherpa_onnx_linux/linux/aarch64
103 else 112 else
104 cp -fv build/install/lib/lib* ./flutter/sherpa_onnx_$os/$os 113 cp -fv build/install/lib/lib* ./flutter/sherpa_onnx_$os/$os
105 fi 114 fi
106 115
107 echo "--------------------" 116 echo "--------------------"
108 117
  118 + if [[ $os == linux-x64 || $os == linux-aarch64 ]]; then
  119 + ls -lh ./flutter/sherpa_onnx_linux/linux/*
  120 + else
109 ls -lh ./flutter/sherpa_onnx_$os/$os 121 ls -lh ./flutter/sherpa_onnx_$os/$os
  122 + fi
110 123
111 - name: Run tests 124 - name: Run tests
112 shell: bash 125 shell: bash
@@ -25,6 +25,14 @@ Future<void> initSherpaOnnx() async { @@ -25,6 +25,14 @@ Future<void> initSherpaOnnx() async {
25 exit(1); 25 exit(1);
26 } 26 }
27 27
28 - final libPath = p.join(p.dirname(p.fromUri(uri)), '..', platform); 28 + var libPath = p.join(p.dirname(p.fromUri(uri)), '..', platform);
  29 + if (platform == 'linux') {
  30 + final arch = Platform.version.contains('arm64') ||
  31 + Platform.version.contains('aarch64')
  32 + ? 'aarch64'
  33 + : 'x64';
  34 + libPath = p.join(p.dirname(p.fromUri(uri)), '..', platform, arch);
  35 + }
  36 +
29 sherpa_onnx.initBindings(libPath); 37 sherpa_onnx.initBindings(libPath);
30 } 38 }
@@ -7,11 +7,19 @@ cmake_minimum_required(VERSION 3.10) @@ -7,11 +7,19 @@ cmake_minimum_required(VERSION 3.10)
7 set(PROJECT_NAME "sherpa_onnx_linux") 7 set(PROJECT_NAME "sherpa_onnx_linux")
8 project(${PROJECT_NAME} LANGUAGES CXX) 8 project(${PROJECT_NAME} LANGUAGES CXX)
9 9
  10 +if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
  11 + set(LIB_ARCH_DIR "x64")
  12 +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
  13 + set(LIB_ARCH_DIR "aarch64")
  14 +else()
  15 + message(FATAL_ERROR "Unsupported arch: ${CMAKE_SYSTEM_PROCESSOR}")
  16 +endif()
  17 +
10 # List of absolute paths to libraries that should be bundled with the plugin. 18 # List of absolute paths to libraries that should be bundled with the plugin.
11 # This list could contain prebuilt libraries, or libraries created by an 19 # This list could contain prebuilt libraries, or libraries created by an
12 # external build triggered from this build file. 20 # external build triggered from this build file.
13 set(sherpa_onnx_linux_bundled_libraries 21 set(sherpa_onnx_linux_bundled_libraries
14 - "${CMAKE_CURRENT_SOURCE_DIR}/libsherpa-onnx-c-api.so"  
15 - "${CMAKE_CURRENT_SOURCE_DIR}/libonnxruntime.so" 22 + "${CMAKE_CURRENT_SOURCE_DIR}/${LIB_ARCH_DIR}/libsherpa-onnx-c-api.so"
  23 + "${CMAKE_CURRENT_SOURCE_DIR}/${LIB_ARCH_DIR}/libonnxruntime.so"
16 PARENT_SCOPE 24 PARENT_SCOPE
17 ) 25 )