Skip to content

Swift bindings

Swift bindings #2

name: Swift bindings
on:
workflow_dispatch:
create:
permissions:
contents: write
jobs:
build-extensions:
name: Build Swift 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: Build Swift native extension
run: cargo build --release --no-default-features --features swift,ort-dynamic --lib
- name: Package Swift native extension
shell: pwsh
run: |
$nativeLibrary = "${{ matrix.native-library }}"
if (!(Test-Path $nativeLibrary)) {
throw "Native library was not produced: $nativeLibrary"
}
if (!(Test-Path "swift/generated")) {
throw "Generated Swift bindings were not produced"
}
New-Item -ItemType Directory -Force -Path package/native | Out-Null
New-Item -ItemType Directory -Force -Path package/swift | Out-Null
Copy-Item $nativeLibrary package/native/
Copy-Item swift/generated package/swift/generated -Recurse
Compress-Archive -Path package/* -DestinationPath "swift-${{ matrix.name }}.zip" -Force
- name: Upload Swift native extension
uses: actions/upload-artifact@v4
with:
name: swift-${{ matrix.name }}
path: swift-${{ matrix.name }}.zip
if-no-files-found: error
publish-release:
name: Upload Swift 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 Swift native extensions
uses: actions/download-artifact@v4
with:
pattern: swift-*
path: artifacts
merge-multiple: true
- name: Upload Swift 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/swift-*.zip
fail_on_unmatched_files: true