Skip to content

Go bindings

Go bindings #2

Workflow file for this run

name: Go bindings
on:
workflow_dispatch:
create:
permissions:
contents: write
jobs:
build-extensions:
name: Build Go 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
import-library: target/release/w2v_bert_uk.dll.lib
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Set up MSVC shell
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
- name: Build Go native extension
run: cargo build --release --no-default-features --features go,ort-dynamic --lib
- name: Prepare Go cgo smoke test
shell: pwsh
run: |
$nativeLibrary = "${{ matrix.native-library }}"
if (!(Test-Path $nativeLibrary)) {
throw "Native library was not produced: $nativeLibrary"
}
if (!(Test-Path "c/w2v_bert_uk.h")) {
throw "Generated C header was not produced"
}
New-Item -ItemType Directory -Force -Path native | Out-Null
Copy-Item $nativeLibrary native/
$importLibrary = "${{ matrix.import-library }}"
if ($importLibrary -and (Test-Path $importLibrary)) {
Copy-Item $importLibrary native/
}
- name: Compile Go bindings
if: runner.os != 'Windows'
run: go test ./go
- name: Package Go native extension
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path package/native | Out-Null
New-Item -ItemType Directory -Force -Path package/c | Out-Null
New-Item -ItemType Directory -Force -Path package/go | Out-Null
New-Item -ItemType Directory -Force -Path package/examples | Out-Null
Copy-Item native/* package/native/
Copy-Item c/w2v_bert_uk.h package/c/
Copy-Item go.mod package/
Copy-Item go/*.go package/go/
Copy-Item examples/transcribe.go package/examples/
Compress-Archive -Path package/* -DestinationPath "go-${{ matrix.name }}.zip" -Force
- name: Upload Go native extension
uses: actions/upload-artifact@v4
with:
name: go-${{ matrix.name }}
path: go-${{ matrix.name }}.zip
if-no-files-found: error
publish-release:
name: Upload Go 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 Go native extensions
uses: actions/download-artifact@v4
with:
pattern: go-*
path: artifacts
merge-multiple: true
- name: Upload Go 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/go-*.zip
fail_on_unmatched_files: true