Skip to content

Add API to get onnxruntime version. - #3810

Merged
csukuangfj merged 3 commits into
k2-fsa:masterfrom
csukuangfj:extend-version-str
Jul 28, 2026
Merged

csukuangfj merged 3 commits into
k2-fsa:masterfrom
csukuangfj:extend-version-str

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added access to the ONNX Runtime version used by Sherpa-ONNX across C, C++, Python, Java, Kotlin, Go, Rust, Dart, Flutter, .NET, Node.js, Swift, Pascal, and HarmonyOS APIs.
    • Version information now includes the ONNX Runtime version alongside Sherpa-ONNX and Git metadata.
    • Added version examples for C, C++, Dart, Go, and Pascal.
  • Tests

    • Expanded CI automation to build and run version checks for the supported language bindings.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 28, 2026
@csukuangfj csukuangfj changed the title Add API to get the onnxruntime version. Add API to get onnxruntime version. Jul 28, 2026
@csukuangfj
csukuangfj requested a review from Copilot July 28, 2026 04:19
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d7a91706-4f0b-48e7-92fb-50f8de6b5d65

📥 Commits

Reviewing files that changed from the base of the PR and between efae349 and 64a4a8d.

📒 Files selected for processing (2)
  • .github/workflows/pascal.yaml
  • .github/workflows/test-go.yaml

📝 Walkthrough

Walkthrough

The change adds a native ONNX Runtime version accessor, exposes it through multiple language APIs, updates version examples, and integrates C, C++, Dart, Go, Pascal, Python, and related checks into CI.

Changes

ONNX Runtime version exposure

Layer / File(s) Summary
Native version API and executable integration
sherpa-onnx/csrc/*, sherpa-onnx/c-api/*
The native layer retrieves the ONNX Runtime version, exposes C and C++ accessors, updates symbol exports, and prints the value from the version executable.
Language binding propagation
flutter/..., sherpa-onnx/{java-api,jni,kotlin-api,python,rust}/*, scripts/{dotnet,go,nodejs}/*, harmony-os/*, sherpa-onnx/pascal-api/*, swift-api-examples/*
Language bindings expose the ONNX Runtime version through their native interop layers and public APIs.
Version examples and outputs
c-api-examples/*, cxx-api-examples/*, dart-api-examples/version/*, pascal-api-examples/version/*, python-api-examples/*, scripts/go/_internal/version/*, java-api-examples/*, kotlin-api-examples/*, rust-api-examples/*, swift-api-examples/*, go-api-examples/*, dotnet-examples/*
Version examples print the ONNX Runtime version alongside existing Sherpa-ONNX metadata.
CI version test wiring
.github/scripts/*, .github/workflows/*
CI builds or runs the added version examples before continuing with existing API and model tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NativeVersion as Native version API
  participant LanguageBinding as Language binding
  participant VersionExample as Version example
  participant CI as CI workflow
  NativeVersion->>LanguageBinding: Expose ONNX Runtime version accessor
  LanguageBinding->>VersionExample: Return ONNX Runtime version
  CI->>VersionExample: Build or run version test
  VersionExample-->>CI: Print version metadata
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.21% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding API support to retrieve the ONNX Runtime version across bindings and examples.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/pascal.yaml:
- Around line 135-143: Update the “Run Pascal version test” step in pascal.yaml
to make the native DLLs discoverable on Windows before invoking version/run.sh:
either copy the DLLs into pascal-api-examples/version or prepend their install
directory to PATH. Preserve the existing pushd/popd test flow and ensure the
Windows runner can locate the DLLs.

In @.github/workflows/test-go.yaml:
- Around line 158-168: Update the Windows setup and version-test flow in
test-go.yaml so the DLLs from scripts/go/_internal/lib/x86_64-pc-windows-gnu are
available when scripts/go/_internal/version/run.sh launches ./version. Either
copy the required DLLs into the version directory before the Test version step
or prepend their source directory to PATH before running the test.

In `@c-api-examples/version-c-api.c`:
- Line 9: Update the version-c-api.c entry point from int32_t main() to int
main(void), using the conforming return type and explicit no-argument
declaration.

In `@pascal-api-examples/version/run.sh`:
- Line 6: Quote the path variable expansions used by cd and fpc in run.sh,
including the SHERPA_ONNX_DIR assignment and the additionally affected commands,
so repository paths containing spaces or glob characters are passed as single
arguments.

In `@scripts/go/_internal/version/go.mod`:
- Line 5: Add a require entry for github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx
in the module configuration alongside the existing replace directive, using the
appropriate module version, so the import in main.go resolves and the version
example builds successfully.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 10a6ad94-551f-4c66-b5e7-a594b94ae83e

📥 Commits

Reviewing files that changed from the base of the PR and between 0a03d85 and efae349.

📒 Files selected for processing (57)
  • .github/scripts/test-c-api.sh
  • .github/scripts/test-dart.sh
  • .github/scripts/test-python.sh
  • .github/workflows/c-api.yaml
  • .github/workflows/cxx-api.yaml
  • .github/workflows/pascal.yaml
  • .github/workflows/test-dart.yaml
  • .github/workflows/test-go.yaml
  • c-api-examples/CMakeLists.txt
  • c-api-examples/version-c-api.c
  • cxx-api-examples/CMakeLists.txt
  • cxx-api-examples/version-cxx-api.cc
  • dart-api-examples/version/bin/main.dart
  • dart-api-examples/version/pubspec.yaml
  • dart-api-examples/version/run.sh
  • dotnet-examples/version-test/Program.cs
  • flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
  • flutter/sherpa_onnx/lib/src/version.dart
  • go-api-examples/streaming-decode-files/main.go
  • harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/version.cc
  • java-api-examples/VersionTest.java
  • java-api-examples/gradle-examples/src/main/java/com/k2fsa/sherpa/onnx/example/VersionTest.java
  • java-api-examples/gradle-kts-examples/src/main/java/com/k2fsa/sherpa/onnx/example/VersionTest.java
  • java-api-examples/maven-examples/src/main/java/com/k2fsa/sherpa/onnx/example/VersionTest.java
  • kotlin-api-examples/test_version.kt
  • pascal-api-examples/version/run.sh
  • pascal-api-examples/version/version.pas
  • python-api-examples/version-test.py
  • rust-api-examples/examples/version.rs
  • scripts/dart/version-pubspec.yaml
  • scripts/dotnet/VersionInfo.cs
  • scripts/go/_internal/version/go.mod
  • scripts/go/_internal/version/main.go
  • scripts/go/_internal/version/run.sh
  • scripts/go/sherpa_onnx.go
  • scripts/node-addon-api/lib/sherpa-onnx.js
  • scripts/nodejs/index.js
  • sherpa-onnx/c-api/c-api.cc
  • sherpa-onnx/c-api/c-api.h
  • sherpa-onnx/c-api/cxx-api.cc
  • sherpa-onnx/c-api/cxx-api.h
  • sherpa-onnx/c-api/sherpa-onnx-symbols-c.exp
  • sherpa-onnx/csrc/CMakeLists.txt
  • sherpa-onnx/csrc/sherpa-onnx-version.cc
  • sherpa-onnx/csrc/version.cc
  • sherpa-onnx/csrc/version.h
  • sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/VersionInfo.java
  • sherpa-onnx/jni/sherpa-onnx-symbols.exp
  • sherpa-onnx/jni/version.cc
  • sherpa-onnx/kotlin-api/VersionInfo.kt
  • sherpa-onnx/pascal-api/sherpa_onnx.pas
  • sherpa-onnx/python/csrc/version.cc
  • sherpa-onnx/python/sherpa_onnx/__init__.py
  • sherpa-onnx/rust/sherpa-onnx-sys/src/lib.rs
  • sherpa-onnx/rust/sherpa-onnx/src/utils.rs
  • swift-api-examples/SherpaOnnx.swift
  • swift-api-examples/test-version.swift

Comment thread .github/workflows/pascal.yaml
Comment thread .github/workflows/test-go.yaml

#include "sherpa-onnx/c-api/c-api.h"

int32_t main() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== file context =="
sed -n '1,40p' c-api-examples/version-c-api.c

echo
echo "== all version-c-api files =="
git ls-files | grep -E '(^|/)version-c-api\.c$' || true

echo
echo "== compiler availability and C semantics probe for int32_t main()/int main(void) =="
if command -v gcc >/dev/null 2>&1; then
  tmp="$(mktemp --suffix=.c)"
  cat > "$tmp" <<'EOF'
`#include` <stdint.h>
`#include` <stdio.h>

int32_t main() {
  printf("int32_t main()\n");
  return 0;
  // unreachable: int32_t has no default argument expressions, so
  // unspecified args would not make parameter count 0 for int.
}
EOF
  gcc -std=c11 -pedantic -Wall -Wextra -Werror "$tmp" 2>&1 || true
  rm -f "$tmp" a.out
fi

if command -v clang >/dev/null 2>&1; then
  tmp="$(mktemp --suffix=.c)"
  cat > "$tmp" <<'EOF'
`#include` <stdint.h>
`#include` <stdio.h>

int32_t main() {
  printf("int32_t main()\n");
  return 0;
}
EOF
  clang -std=c11 -pedantic -Wall -Wextra "$tmp" 2>&1 || true
  rm -f "$tmp" a.out
fi

echo
echo "== search for int32_t main declarations in repo =="
rg -n 'int32_t\s+main\s*\(' -g '*.c' -g '*.h' . || true

Repository: k2-fsa/sherpa-onnx

Length of output: 4774


Use a conforming C entry-point signature.

A hosted C program’s main should return int, and () declares unspecified arguments rather than no arguments. Use int main(void) so this entry point is portable and warning-clean with pedantic C compilers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@c-api-examples/version-c-api.c` at line 9, Update the version-c-api.c entry
point from int32_t main() to int main(void), using the conforming return type
and explicit no-argument declaration.

set -ex

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
SHERPA_ONNX_DIR=$(cd $SCRIPT_DIR/../.. && pwd)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Quote path variables before passing them to cd and fpc.

Unquoted expansions can break when the repository path contains spaces or glob characters.

Proposed fix
-SHERPA_ONNX_DIR=$(cd $SCRIPT_DIR/../.. && pwd)
+SHERPA_ONNX_DIR=$(cd "$SCRIPT_DIR/../.." && pwd)

-  -Fu$SHERPA_ONNX_DIR/sherpa-onnx/pascal-api \
-  -Fl$SHERPA_ONNX_DIR/build/install/lib \
+  -Fu"$SHERPA_ONNX_DIR/sherpa-onnx/pascal-api" \
+  -Fl"$SHERPA_ONNX_DIR/build/install/lib" \

Also applies to: 28-29

🧰 Tools
🪛 Shellcheck (0.11.0)

[info] 6-6: Double quote to prevent globbing and word splitting.

(SC2086)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pascal-api-examples/version/run.sh` at line 6, Quote the path variable
expansions used by cd and fpc in run.sh, including the SHERPA_ONNX_DIR
assignment and the additionally affected commands, so repository paths
containing spaces or glob characters are passed as single arguments.

Source: Linters/SAST tools


go 1.17

replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

cd scripts/go/_internal/version
go build

Repository: k2-fsa/sherpa-onnx

Length of output: 381


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'go.mod contents:\n'
cat -n scripts/go/_internal/version/go.mod

printf '\nImports in scripts/go/_internal/version/main.go:\n'
cat -n scripts/go/_internal/version/main.go | sed -n '1,40p'

Repository: k2-fsa/sherpa-onnx

Length of output: 805


Add the missing require for the replaced sherpa-onnx module.

scripts/go/_internal/version/main.go imports github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx, but the module only declares a replace directive. This makes go build fail with “replaced but not required”; add the corresponding require entry so the version example builds.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/go/_internal/version/go.mod` at line 5, Add a require entry for
github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx in the module configuration
alongside the existing replace directive, using the appropriate module version,
so the import in main.go resolves and the version example builds successfully.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds a new API surface to expose the ONNX Runtime version used by sherpa-onnx across multiple language bindings and example apps, with CI updates to validate the new version endpoints.

Changes:

  • Introduces a new C/C++ API function SherpaOnnxGetOnnxruntimeVersionStr() and corresponding C++ wrapper.
  • Wires the new API through bindings (Swift, Rust, Python, Java/Kotlin JNI, Go, Dart/Flutter, Node, Pascal, .NET) and updates/creates version example programs.
  • Extends GitHub Actions workflows/scripts to run new “version” checks in several language pipelines.

Reviewed changes

Copilot reviewed 56 out of 57 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
swift-api-examples/test-version.swift Prints ONNX Runtime version in Swift example output.
swift-api-examples/SherpaOnnx.swift Adds Swift wrapper for ONNX Runtime version C API call.
sherpa-onnx/rust/sherpa-onnx/src/utils.rs Exposes ONNX Runtime version helper in Rust API.
sherpa-onnx/rust/sherpa-onnx-sys/src/lib.rs Adds Rust FFI declaration for the new C symbol.
sherpa-onnx/python/sherpa_onnx/init.py Re-exports onnxruntime_version from Python module.
sherpa-onnx/python/csrc/version.cc Exposes onnxruntime_version attribute via pybind.
sherpa-onnx/pascal-api/sherpa_onnx.pas Adds Pascal binding for ONNX Runtime version C API.
sherpa-onnx/kotlin-api/VersionInfo.kt Adds Kotlin API property and JNI method hook.
sherpa-onnx/jni/version.cc Implements JNI methods returning ONNX Runtime version.
sherpa-onnx/jni/sherpa-onnx-symbols.exp Exports new JNI symbols for dynamic linking.
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/VersionInfo.java Adds Java API method to fetch ONNX Runtime version.
sherpa-onnx/csrc/version.h Declares GetOnnxruntimeVersionStr() in core C++ API.
sherpa-onnx/csrc/version.cc Implements ONNX Runtime version lookup via ORT C API.
sherpa-onnx/csrc/sherpa-onnx-version.cc Prints ONNX Runtime version in native CLI output.
sherpa-onnx/csrc/CMakeLists.txt Ensures sherpa-onnx-version is included in installed binaries list.
sherpa-onnx/c-api/sherpa-onnx-symbols-c.exp Exports new C API symbol for version retrieval.
sherpa-onnx/c-api/cxx-api.h Adds C++ wrapper declaration for ONNX Runtime version.
sherpa-onnx/c-api/cxx-api.cc Adds C++ wrapper implementation calling C API.
sherpa-onnx/c-api/c-api.h Documents and declares SherpaOnnxGetOnnxruntimeVersionStr().
sherpa-onnx/c-api/c-api.cc Implements C API bridge to core C++ function.
scripts/nodejs/index.js Adds WASM/Node accessor and export for ONNX Runtime version.
scripts/node-addon-api/lib/sherpa-onnx.js Exposes addon property as onnxruntimeVersion in JS wrapper.
scripts/go/sherpa_onnx.go Adds Go binding GetOnnxruntimeVersion().
scripts/go/_internal/version/run.sh Adds script to build/run Go version example.
scripts/go/_internal/version/main.go Adds Go example printing ONNX Runtime version.
scripts/go/_internal/version/go.mod Adds module file for Go version example wiring to local replace.
scripts/dotnet/VersionInfo.cs Adds .NET property to read ONNX Runtime version from native lib.
scripts/dart/version-pubspec.yaml Adds Dart pubspec template for version example.
rust-api-examples/examples/version.rs Prints ONNX Runtime version in Rust example.
python-api-examples/version-test.py Adds Python example printing ONNX Runtime version.
pascal-api-examples/version/version.pas Adds Pascal example printing ONNX Runtime version.
pascal-api-examples/version/run.sh Adds build/run script for Pascal version example.
kotlin-api-examples/test_version.kt Prints ONNX Runtime version in Kotlin example.
java-api-examples/maven-examples/src/main/java/com/k2fsa/sherpa/onnx/example/VersionTest.java Prints ONNX Runtime version in Maven Java example.
java-api-examples/gradle-kts-examples/src/main/java/com/k2fsa/sherpa/onnx/example/VersionTest.java Prints ONNX Runtime version in Gradle-KTS Java example.
java-api-examples/gradle-examples/src/main/java/com/k2fsa/sherpa/onnx/example/VersionTest.java Prints ONNX Runtime version in Gradle Java example.
java-api-examples/VersionTest.java Prints ONNX Runtime version in top-level Java example.
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/version.cc Adds ONNX Runtime version to HarmonyOS N-API exports.
go-api-examples/streaming-decode-files/main.go Logs ONNX Runtime version in Go example startup.
flutter/sherpa_onnx/lib/src/version.dart Adds Dart wrapper function to read ONNX Runtime version via FFI.
flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart Adds Dart FFI binding lookup for new native symbol.
dotnet-examples/version-test/Program.cs Prints ONNX Runtime version in .NET example.
dart-api-examples/version/run.sh Adds runner script for Dart version example.
dart-api-examples/version/pubspec.yaml Adds Dart example pubspec for version example app.
dart-api-examples/version/bin/main.dart Prints ONNX Runtime version in Dart example.
cxx-api-examples/version-cxx-api.cc Adds C++ (cxx-api) example printing ONNX Runtime version.
cxx-api-examples/CMakeLists.txt Builds the new C++ version example target.
c-api-examples/version-c-api.c Adds C API example printing ONNX Runtime version.
c-api-examples/CMakeLists.txt Builds the new C API version example target.
.github/workflows/test-go.yaml Runs Go version example in CI.
.github/workflows/test-dart.yaml Copies pubspec template for Dart version example in CI.
.github/workflows/pascal.yaml Runs Pascal version example in CI.
.github/workflows/cxx-api.yaml Compiles/runs C++ version example in CI.
.github/workflows/c-api.yaml Compiles/runs C version example in CI.
.github/scripts/test-python.sh Runs Python version example in CI script.
.github/scripts/test-dart.sh Runs Dart version example in CI script.
.github/scripts/test-c-api.sh Runs C version binary in CI script.
Comments suppressed due to low confidence (2)

scripts/go/_internal/version/go.mod:1

  • The replace target ../ resolves to scripts/go/_internal, but the Go bindings appear to live higher up (e.g., scripts/go). This will likely break go mod tidy/build for the example. Update the replace path to point at the actual module directory that provides github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx (commonly ../../ from this folder if the module root is scripts/go).
    scripts/dotnet/VersionInfo.cs:1
  • The UTF-8 pointer-to-string conversion is implemented manually (unsafe scan + buffer copy), which duplicates framework functionality and increases maintenance burden. If the target framework allows it, prefer Marshal.PtrToStringUTF8(p) (or an equivalent shared helper already used elsewhere in this repo) to reduce unsafe code and simplify this property.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +163 to +168
go mod tidy
cat go.mod
go build
ls -lh

./run.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants