Kotlin bindings #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Kotlin bindings | |
| on: | |
| workflow_dispatch: | |
| create: | |
| permissions: | |
| contents: write | |
| jobs: | |
| build-extensions: | |
| name: Build Kotlin native extension (${{ matrix.name }}) | |
| if: github.event_name != 'create' || github.event.ref_type == 'tag' | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - name: linux-x64-gnu | |
| os: ubuntu-22.04 | |
| native-library: target/release/libw2v_bert_uk.so | |
| - name: macos-arm64 | |
| os: macos-latest | |
| native-library: target/release/libw2v_bert_uk.dylib | |
| - name: windows-x64-msvc | |
| os: windows-latest | |
| native-library: target/release/w2v_bert_uk.dll | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Set up Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: "17" | |
| - name: Build Kotlin native extension | |
| env: | |
| CARGO_PROFILE_RELEASE_STRIP: "false" | |
| run: cargo build --release --no-default-features --features kotlin,ort-dynamic --lib | |
| - name: Install UniFFI bindgen | |
| run: cargo install uniffi --version 0.31.1 --locked --features cli --root uniffi-tools | |
| - name: Generate Kotlin bindings | |
| shell: pwsh | |
| run: | | |
| $bindgen = if ($IsWindows) { "uniffi-tools/bin/uniffi-bindgen.exe" } else { "uniffi-tools/bin/uniffi-bindgen" } | |
| & $bindgen generate "${{ matrix.native-library }}" --language kotlin --out-dir kotlin/generated --no-format | |
| - name: Package Kotlin native extension | |
| shell: pwsh | |
| run: | | |
| $nativeLibrary = "${{ matrix.native-library }}" | |
| if (!(Test-Path $nativeLibrary)) { | |
| throw "Native library was not produced: $nativeLibrary" | |
| } | |
| if (!(Test-Path "kotlin/generated/io/github/rustedbytes/w2vbertuk/w2v_bert_uk.kt")) { | |
| throw "Generated Kotlin bindings were not produced" | |
| } | |
| New-Item -ItemType Directory -Force -Path package/native | Out-Null | |
| New-Item -ItemType Directory -Force -Path package/kotlin | Out-Null | |
| New-Item -ItemType Directory -Force -Path package/examples | Out-Null | |
| Copy-Item $nativeLibrary package/native/ | |
| Copy-Item kotlin/generated package/kotlin/generated -Recurse | |
| Copy-Item uniffi.toml package/ | |
| Copy-Item examples/Transcribe.kt package/examples/ | |
| Compress-Archive -Path package/* -DestinationPath "kotlin-${{ matrix.name }}.zip" -Force | |
| - name: Upload Kotlin native extension | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: kotlin-${{ matrix.name }} | |
| path: kotlin-${{ matrix.name }}.zip | |
| if-no-files-found: error | |
| publish-release: | |
| name: Upload Kotlin native extensions to release | |
| needs: build-extensions | |
| if: >- | |
| always() && | |
| !cancelled() && | |
| !failure() && | |
| (startsWith(github.ref, 'refs/tags/') || (github.event_name == 'create' && github.event.ref_type == 'tag')) | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Download Kotlin native extensions | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: kotlin-* | |
| path: artifacts | |
| merge-multiple: true | |
| - name: Upload Kotlin native extensions to release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.event_name == 'create' && github.event.ref || github.ref_name }} | |
| files: artifacts/kotlin-*.zip | |
| fail_on_unmatched_files: true |