Skip to content

Test Rust API on Windows - #3385

Merged
csukuangfj merged 10 commits into
k2-fsa:masterfrom
csukuangfj:test-rust-win
Mar 21, 2026
Merged

csukuangfj merged 10 commits into
k2-fsa:masterfrom
csukuangfj:test-rust-win

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Mar 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced Windows support in CI/CD pipelines and build configurations across all supported architectures.
  • Documentation

    • Expanded setup guides for Rust examples with platform-specific library path instructions (Linux, macOS, Windows).
    • Added comprehensive library discovery guidance for both source builds and prebuilt downloads.
  • Chores

    • Updated release version to v1.12.31.
    • Improved build configuration consistency across supported platforms.

Copilot AI review requested due to automatic review settings March 21, 2026 13:13
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 21, 2026
@coderabbitai

coderabbitai Bot commented Mar 21, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This pull request extends Windows CI/CD support by adding MSVC tooling setup and DLL handling to the Rust test workflow, refines CMake platform conditionals from NOT WIN32 to UNIX for clarity, updates Windows packaging to include onnxruntime.lib import libraries and remove artifacts, extends Rust documentation and build configuration for cross-platform library linking, updates the release script to version-bump lib.rs, and expands setup instructions in the Rust API examples README.

Changes

Cohort / File(s) Summary
Windows CI/Test Workflow Setup
.github/workflows/test-rust-package.yaml
Added Windows CI coverage with MSVC tooling installation (ilammy/msvc-dev-cmd@v1), linker configuration via CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER environment variable, Windows-specific prebuilt library archive selection, platform-specific path/linker setup, and DLL copying to target debug examples directory.
Windows Packaging & Artifact Management
.github/workflows/windows-arm64.yaml, .github/workflows/windows-x64.yaml, .github/workflows/windows-x86.yaml
Conditionally copy onnxruntime.lib when building shared libraries; remove pkgconfig metadata and cargs artifacts from packaged output. Version tag updated from v1.12.28 to v1.12.31 in x64 workflow.
CMake RPATH Platform Conditionals
CMakeLists.txt, sherpa-onnx/csrc/CMakeLists.txt, sherpa-onnx/python/csrc/CMakeLists.txt
Replaced if(NOT WIN32) conditions with if(UNIX) for RPATH configuration and runtime search path directives to improve cross-platform platform detection clarity.
ONNX Runtime Import Library Installation
cmake/onnxruntime-win-arm64.cmake, cmake/onnxruntime-win-x64.cmake, cmake/onnxruntime-win-x86.cmake
Added explicit CMake install steps to copy onnxruntime.lib import library into lib destination alongside existing DLL installations.
Rust Build & Package Configuration
sherpa-onnx/rust/sherpa-onnx-sys/build.rs, sherpa-onnx/rust/.gitignore
Made C API linking directive unconditional and updated associated comment; added Cargo.lock to .gitignore.
Rust Crate Root Documentation
sherpa-onnx/rust/sherpa-onnx/src/lib.rs
Extended crate-level Rustdoc with new Setup section covering link-time and runtime library configuration with per-OS guidance (RUSTFLAGS for Unix, PATH for Windows), including download URLs for v1.12.31 prebuilt archives.
Release Automation & Examples Documentation
new-release.sh, rust-api-examples/README.md
Updated release script to apply version substitution to lib.rs; expanded README with comprehensive setup workflows covering both build-from-source and prebuilt-download paths with OS-specific environment examples and troubleshooting guidance.
Minor Script Update
rust-api-examples/run-zipvoice-tts.sh
Removed verbose flag from tar extraction.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Begin to add Rust API #3203: Introduces Rust test workflow and Windows CI foundational changes that this PR extends with MSVC setup and DLL handling.
  • Refactor CI for Windows x64 #3119: Modifies the same Windows CI and CMake packaging files (windows-x64.yaml, onnxruntime win CMake files) for related artifact handling updates.
  • Add more doc for Rust API #3378: Updates crate-level Rust documentation in sherpa-onnx/rust/sherpa-onnx/src/lib.rs that overlaps with this PR's doc expansion.

Suggested labels

size:L, area:ci, area:build, area:rust, platform:windows

🐰 Windows wheels now spinning bright,
With MSVC linking things just right!
Unix paths and DLL care,
Docs guide Rustaceans everywhere.
Cross-platform dreams take flight! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the primary focus of the changeset: enabling and testing the Rust API on Windows by adding CI coverage, Windows-specific build configurations, and comprehensive setup documentation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request aims to improve the cross-platform compatibility and user experience for the Rust API, particularly focusing on Windows. It refines the build system's platform-specific logic and provides extensive documentation to guide users through setting up the Rust development environment on various operating systems, thereby streamlining the process of integrating and utilizing the Rust API.

Highlights

  • CMake Configuration Updates: Modified CMake files to use if(UNIX) instead of if(NOT WIN32) for platform-specific RPATH and linking configurations, ensuring more precise handling of non-Windows systems.
  • Windows Rust API Support: Enhanced support for the Rust API on Windows by explicitly installing onnxruntime.lib in Windows-specific CMake modules and providing detailed setup instructions in the Rust API documentation.
  • Documentation Improvements: Significantly expanded the rust-api-examples/README.md and sherpa-onnx/rust/sherpa-onnx/src/lib.rs with comprehensive setup guides for the Rust API across Linux, macOS, and Windows, covering both building from source and using pre-built binaries.
  • Release Script Enhancement: Updated the new-release.sh script to include sherpa-onnx/rust/sherpa-onnx/src/lib.rs for version bumping, ensuring consistency across release updates.
  • Rust Build System Refinements: Added Cargo.lock to the .gitignore for the Rust directory and clarified a comment in sherpa-onnx-sys/build.rs regarding dynamic library linking.
Ignored Files
  • Ignored by pattern: .github/workflows/** (4)
    • .github/workflows/test-rust-package.yaml
    • .github/workflows/windows-arm64.yaml
    • .github/workflows/windows-x64.yaml
    • .github/workflows/windows-x86.yaml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request significantly improves the Rust API support on Windows by adjusting CMake configurations to correctly handle Windows-specific linking requirements. It also updates the setup documentation in rust-api-examples/README.md and sherpa-onnx/rust/sherpa-onnx/src/lib.rs to provide clear guidance for users on Linux, macOS, and Windows. A minor update to the release script ensures version consistency across files.

Comment on lines +31 to +40
//! Example download URLs for `v1.12.31`:
//!
//! - Linux x86_64:
//! [sherpa-onnx-v1.12.31-linux-x64-shared.tar.bz2](https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.12.31/sherpa-onnx-v1.12.31-linux-x64-shared.tar.bz2)
//! - Linux aarch64:
//! [sherpa-onnx-v1.12.31-linux-aarch64-shared-cpu.tar.bz2](https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.12.31/sherpa-onnx-v1.12.31-linux-aarch64-shared-cpu.tar.bz2)
//! - macOS:
//! [sherpa-onnx-v1.12.31-osx-universal2-shared.tar.bz2](https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.12.31/sherpa-onnx-v1.12.31-osx-universal2-shared.tar.bz2)
//! - Windows x64:
//! [sherpa-onnx-v1.12.31-win-x64-shared-MT-Release.tar.bz2](https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.12.31/sherpa-onnx-v1.12.31-win-x64-shared-MT-Release.tar.bz2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The example download URLs hardcode v1.12.31. While rust-api-examples/README.md mentions using the latest release, this lib.rs documentation does not. This could lead to outdated information and user confusion if not updated with each release. Consider adding a note here similar to the README.md or using a placeholder for the version.

@csukuangfj
csukuangfj merged commit 15e2648 into k2-fsa:master Mar 21, 2026
0 of 28 checks passed
@csukuangfj
csukuangfj deleted the test-rust-win branch March 21, 2026 13:18

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

Improve Windows support for the Rust API by updating docs, build/install scripts, and CI to ensure required shared/import libraries are discoverable and tests run on Windows.

Changes:

  • Add Windows-focused setup guidance for the Rust crate and examples (library discovery at build/run time).
  • Update CMake + packaging to include/import onnxruntime.lib on Windows and tighten rpath logic to UNIX platforms.
  • Extend Rust package CI to run on windows-latest with MSVC toolchain setup.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
sherpa-onnx/rust/sherpa-onnx/src/lib.rs Add crate-level setup documentation incl. Windows runtime DLL discovery guidance
sherpa-onnx/rust/sherpa-onnx-sys/build.rs Clarify linking intent for sherpa-onnx C API
sherpa-onnx/rust/.gitignore Ignore Cargo.lock under sherpa-onnx/rust/
sherpa-onnx/python/csrc/CMakeLists.txt Apply rpath only on UNIX platforms
sherpa-onnx/csrc/CMakeLists.txt Apply rpath/flags only on UNIX platforms; adjust Python rpath condition
rust-api-examples/run-zipvoice-tts.sh Use quieter tar xf extraction
rust-api-examples/README.md Expand setup instructions; add Windows-specific guidance for examples
new-release.sh Ensure version replacement also updates Rust crate docs
cmake/onnxruntime-win-x86.cmake Install onnxruntime.lib into lib/ for Windows x86
cmake/onnxruntime-win-x64.cmake Install onnxruntime.lib into lib/ for Windows x64
cmake/onnxruntime-win-arm64.cmake Install onnxruntime.lib into lib/ for Windows arm64
CMakeLists.txt Apply RPATH-related configuration only on UNIX platforms
.github/workflows/windows-x86.yaml Copy onnxruntime.lib into packaged artifacts when present
.github/workflows/windows-x64.yaml Copy onnxruntime.lib; update release tag value
.github/workflows/windows-arm64.yaml Copy onnxruntime.lib into packaged artifacts when present
.github/workflows/test-rust-package.yaml Add Windows to matrix; configure MSVC; adjust PATH/RUSTFLAGS and run-step DLL handling

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

if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
export PATH="$SHERPA_ONNX_LIB_DIR:$PATH"
mkdir -p rust-api-examples/target/debug/examples
cp -v "$SHERPA_ONNX_LIB_DIR"/*.dll rust-api-examples/target/debug/examples/

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

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

cp -v "$SHERPA_ONNX_LIB_DIR"/*.dll ... will fail the step when no DLLs exist in $SHERPA_ONNX_LIB_DIR (very common if DLLs live under bin/ in the archive). Guard the copy (e.g., check for matches / enable nullglob) and/or copy from the directory that actually contains the DLLs (often $PWD/$d/bin) to avoid spurious CI failures.

Suggested change
cp -v "$SHERPA_ONNX_LIB_DIR"/*.dll rust-api-examples/target/debug/examples/
if compgen -G "$SHERPA_ONNX_LIB_DIR"/*.dll > /dev/null; then
cp -v "$SHERPA_ONNX_LIB_DIR"/*.dll rust-api-examples/target/debug/examples/
else
echo "No DLLs found in $SHERPA_ONNX_LIB_DIR, skipping copy."
fi

Copilot uses AI. Check for mistakes.
```

If Windows still reports that it cannot find a DLL, or if it loads a wrong
`onnxruntime.dll`, copy the DLL files from `%SHERPA_ONNX_LIB_DIR%` to the same

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

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

This section mixes Windows cmd.exe syntax (%SHERPA_ONNX_LIB_DIR%) with surrounding Git-Bash/MSYS-style export ... commands. To prevent users from copying the wrong syntax, either (a) change %SHERPA_ONNX_LIB_DIR% to $SHERPA_ONNX_LIB_DIR to match the shown shell, or (b) explicitly provide distinct snippets for PowerShell / cmd.exe vs Git Bash.

Suggested change
`onnxruntime.dll`, copy the DLL files from `%SHERPA_ONNX_LIB_DIR%` to the same
`onnxruntime.dll`, copy the DLL files from `$SHERPA_ONNX_LIB_DIR` to the same

Copilot uses AI. Check for mistakes.
Comment on lines +57 to +62
//!
//! ```bash
//! export SHERPA_ONNX_LIB_DIR=/path/to/sherpa-onnx/lib
//! export PATH="$SHERPA_ONNX_LIB_DIR:$PATH"
//! ```
//!

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

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

The Windows setup snippet uses export, which only applies to bash-like shells (Git Bash/MSYS/WSL), not PowerShell or cmd.exe. Consider clarifying the intended shell (e.g., “Git Bash”) and/or adding PowerShell equivalents (e.g., $env:SHERPA_ONNX_LIB_DIR=..., $env:Path="...;$env:Path"). This avoids confusion for Windows users following crate-level docs.

Suggested change
//!
//! ```bash
//! export SHERPA_ONNX_LIB_DIR=/path/to/sherpa-onnx/lib
//! export PATH="$SHERPA_ONNX_LIB_DIR:$PATH"
//! ```
//!
//!
//! ### Git Bash / MSYS2 / WSL (bash)
//!
//! ```bash
//! export SHERPA_ONNX_LIB_DIR=/path/to/sherpa-onnx/lib
//! export PATH="$SHERPA_ONNX_LIB_DIR:$PATH"
//! ```
//!
//! ### PowerShell
//!
//! ```powershell
//! $env:SHERPA_ONNX_LIB_DIR = "C:\path\to\sherpa-onnx\lib"
//! $env:Path = "$env:SHERPA_ONNX_LIB_DIR;$env:Path"
//! ```
//!

Copilot uses AI. Check for mistakes.
}

// Link the dynamic libraries regardless (cargo will fail later if not found)
// Always link against the public sherpa-onnx C API import library.

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

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

“import library” is Windows-specific terminology; on Linux/macOS this is a shared library (.so/.dylib). Since this build script runs cross-platform, consider rewording to “shared library” (or “link library”) to stay accurate on all targets.

Suggested change
// Always link against the public sherpa-onnx C API import library.
// Always link against the public sherpa-onnx C API shared library.

Copilot uses AI. Check for mistakes.

install(FILES ${onnxruntime_lib_files} DESTINATION lib)
install(FILES ${onnxruntime_lib_files} DESTINATION bin)
install(FILES "${onnxruntime_SOURCE_DIR}/lib/onnxruntime.lib" DESTINATION lib)

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

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

This install(FILES ...) will hard-fail at install/package time if ${onnxruntime_SOURCE_DIR}/lib/onnxruntime.lib doesn’t exist for a given onnxruntime layout/version. To make packaging resilient, guard it with an if(EXISTS ...) (and optionally emit a clear message(FATAL_ERROR ...) only when the build truly requires it). The same issue applies to the analogous x86/arm64 CMake files.

Suggested change
install(FILES "${onnxruntime_SOURCE_DIR}/lib/onnxruntime.lib" DESTINATION lib)
if(EXISTS "${onnxruntime_SOURCE_DIR}/lib/onnxruntime.lib")
install(FILES "${onnxruntime_SOURCE_DIR}/lib/onnxruntime.lib" DESTINATION lib)
else()
message(WARNING "onnxruntime import library not found at '${onnxruntime_SOURCE_DIR}/lib/onnxruntime.lib'; it will not be installed.")
endif()

Copilot uses AI. Check for mistakes.
repo_name: k2-fsa/sherpa-onnx
repo_token: ${{ secrets.UPLOAD_GH_SHERPA_ONNX_TOKEN }}
tag: v1.12.28
tag: v1.12.31

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

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

Hardcoding the release tag increases the risk of uploading artifacts to the wrong GitHub Release when versions change. Prefer using the tag from the workflow context (e.g., ${{ github.ref_name }}) so the workflow automatically targets the pushed tag.

Suggested change
tag: v1.12.31
tag: ${{ github.ref_name }}

Copilot uses AI. Check for mistakes.
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