|
| 1 | +name: Test rust package static |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - rust-static |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: test-rust-package-static-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + test-rust-package-static: |
| 15 | + name: Test static ${{ matrix.os }} |
| 16 | + runs-on: ${{ matrix.os }} |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + # os: [ubuntu-latest, macos-latest, macos-15-intel, ubuntu-22.04-arm, windows-latest] |
| 21 | + os: [macos-latest, macos-15-intel] |
| 22 | + |
| 23 | + env: |
| 24 | + SHERPA_ONNX_LIB_DIR: "" |
| 25 | + RUSTFLAGS: "" |
| 26 | + |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 31 | + with: |
| 32 | + toolchain: stable |
| 33 | + |
| 34 | + - name: Set up MSVC |
| 35 | + if: matrix.os == 'windows-latest' |
| 36 | + uses: ilammy/msvc-dev-cmd@v1 |
| 37 | + |
| 38 | + - name: Select MSVC linker |
| 39 | + if: matrix.os == 'windows-latest' |
| 40 | + shell: pwsh |
| 41 | + run: | |
| 42 | + $linker = Join-Path $env:VCToolsInstallDir 'bin\HostX64\x64\link.exe' |
| 43 | + if (-not (Test-Path $linker)) { |
| 44 | + throw "MSVC linker not found: $linker" |
| 45 | + } |
| 46 | + "CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER=$linker" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 47 | + Write-Host "Using linker: $linker" |
| 48 | + & where.exe link |
| 49 | +
|
| 50 | + - name: Download prebuilt Sherpa-ONNX static libraries |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) |
| 54 | +
|
| 55 | + if [[ "${{ matrix.os }}" == "macos-latest" ]]; then |
| 56 | + d=sherpa-onnx-v$SHERPA_ONNX_VERSION-osx-universal2-static |
| 57 | + elif [[ "${{ matrix.os }}" == "macos-15-intel" ]]; then |
| 58 | + d=sherpa-onnx-v$SHERPA_ONNX_VERSION-osx-universal2-static |
| 59 | + elif [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then |
| 60 | + d=sherpa-onnx-v$SHERPA_ONNX_VERSION-linux-x64-static |
| 61 | + elif [[ "${{ matrix.os }}" == "ubuntu-22.04-arm" ]]; then |
| 62 | + d=sherpa-onnx-v$SHERPA_ONNX_VERSION-linux-aarch64-static |
| 63 | + elif [[ "${{ matrix.os }}" == "windows-latest" ]]; then |
| 64 | + d=sherpa-onnx-v$SHERPA_ONNX_VERSION-win-x64-static-MT-Release |
| 65 | + else |
| 66 | + echo "Unknown ${{ matrix.os }}" |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | +
|
| 70 | + LIB_URL="https://github.com/k2-fsa/sherpa-onnx/releases/download/v$SHERPA_ONNX_VERSION/$d.tar.bz2" |
| 71 | +
|
| 72 | + curl -SsL -O "$LIB_URL" |
| 73 | + tar -xvf $d.tar.bz2 |
| 74 | +
|
| 75 | + ls -lh $d/lib |
| 76 | + echo "SHERPA_ONNX_LIB_DIR=$PWD/$d/lib" >> $GITHUB_ENV |
| 77 | + echo "RUSTFLAGS=" >> $GITHUB_ENV |
| 78 | +
|
| 79 | + - name: Show libs |
| 80 | + shell: bash |
| 81 | + run: | |
| 82 | + echo "SHERPA_ONNX_LIB_DIR: $SHERPA_ONNX_LIB_DIR" |
| 83 | + ls -lh $SHERPA_ONNX_LIB_DIR |
| 84 | + if [[ "${{ matrix.os }}" == "windows-latest" ]]; then |
| 85 | + echo "CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER: $CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER" |
| 86 | + fi |
| 87 | +
|
| 88 | + - name: Use local sherpa-onnx crate |
| 89 | + shell: bash |
| 90 | + run: | |
| 91 | + cd rust-api-examples |
| 92 | +
|
| 93 | + sed -i.bak 's|^sherpa-onnx *=.*|sherpa-onnx = { path = "../sherpa-onnx/rust/sherpa-onnx" }|' Cargo.toml |
| 94 | +
|
| 95 | + git diff . |
| 96 | +
|
| 97 | + - name: Run test |
| 98 | + shell: bash |
| 99 | + run: | |
| 100 | + ./.github/scripts/test-rust-static.sh |
0 commit comments