Skip to content

Update rust.yml

Update rust.yml #331

Workflow file for this run

name: "cargo"
on:
workflow_dispatch:
push:
branches: ["master"]
pull_request:
branches: ["master"]
env:
CARGO_TERM_COLOR: always
jobs:
bindgen:
strategy:
matrix:
os: [windows-11-preview_aarch64, windows-2025]
target: [aarch64-pc-windows-msvc, x86_64-pc-windows-msvc, i686-pc-windows-msvc]
exclude:
- os: windows-11-preview_aarch64
target: x86_64-pc-windows-msvc
- os: windows-11-preview_aarch64
target: i686-pc-windows-msvc
- os: windows-2025
target: aarch64-pc-windows-msvc
runs-on: ${{ matrix.os }}
steps:
- name: Download LLVM
if: matrix.os == 'windows-11-preview_aarch64'
uses: robinraju/release-downloader@v1
with:
repository: 'llvm/llvm-project'
tag: 'llvmorg-19.1.5'
filename: 'LLVM-19.1.5-woa64.exe'
- name: Install LLVM
if: matrix.os == 'windows-11-preview_aarch64'
run: |
Start-Process -FilePath "LLVM-19.1.5-woa64.exe" -ArgumentList '/S' -NoNewWindow -Wait # The /S flag runs the installer silently
$llvmPath = "C:\Program Files\LLVM\bin\clang.exe"
if (Test-Path $llvmPath) {
Write-Host "LLVM is installed successfully."
} else {
Write-Host "LLVM installation failed."
exit 1
}
- name: Install Build Tools
if: matrix.os == 'windows-11-preview_aarch64'
run: |
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Add-Content -Path $env:GITHUB_PATH -Value "C:\ProgramData\chocolatey\bin" -Encoding utf8
choco install visualstudio2022buildtools -y --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.ARM64 --add Microsoft.VisualStudio.Component.Windows11SDK.22621"
- name: Install Nightly Rust (aarch64)
if: matrix.os == 'windows-11-preview_aarch64'
run: |
Add-Content -Path $env:GITHUB_PATH -Value "$env:USERPROFILE\.cargo\bin" -Encoding utf8
Invoke-WebRequest -Uri "https://win.rustup.rs/aarch64" -OutFile "$env:RUNNER_TEMP\rustup-init.exe"
& "$env:RUNNER_TEMP\rustup-init.exe" --default-host aarch64-pc-windows-msvc --default-toolchain nightly -y
- name: Download Git for Windows (aarch64)
if: matrix.os == 'windows-11-preview_aarch64'
uses: robinraju/release-downloader@v1
with:
repository: 'git-for-windows/git'
tag: 'v2.48.0-rc1.windows.1'
filename: 'Git-2.48.0-rc1-arm64.exe'
- name: Install Git for Windows (aarch64)
if: matrix.os == 'windows-11-preview_aarch64'
run: |
Start-Process -FilePath "Git-2.48.0-rc1-arm64.exe" -ArgumentList "/VERYSILENT" -NoNewWindow -Wait
Add-Content -Path $env:GITHUB_PATH -Value "C:\Program Files\Git\cmd" -Encoding utf8
Add-Content -Path $env:GITHUB_PATH -Value "C:\Program Files\Git\bin" -Encoding utf8
- uses: actions/checkout@v4
- name: Install Rust
if: matrix.os != 'windows-11-preview_aarch64'
uses: dtolnay/rust-toolchain@nightly
with:
targets: ${{ matrix.target }}
components: rustfmt
- name: Build
run: |
cargo build -vv -F regenerate --target ${{ matrix.target }}
- name: Extract architecture from target triple and move bindings
shell: bash
run: |
# Extract architecture (i686, x86_64 or aarch64) from target triple
ARCH=$(echo "${{ matrix.target }}" | cut -d'-' -f1)
echo "Extracted architecture: $ARCH"
# Map i686 to x86
if [ "$ARCH" == "i686" ]; then
ARCH="x86"
fi
# Set the architecture as an environment variable
echo "ARCH=$ARCH" >> $GITHUB_ENV
# Path to the generated binding
GENERATED_BINDING=$(find target/${{ matrix.target }}/debug/build -type f -name "${ARCH}_bindgen.rs")
if [ -z "$GENERATED_BINDING" ]; then
echo "Error: Generated binding file not found for $ARCH."
exit 1
fi
# Move the generated file to the repository directory
cp "$GENERATED_BINDING" "src/ffi/${ARCH}_bindgen.rs"
echo "Moved $GENERATED_BINDING to src/ffi/${ARCH}_bindgen.rs"
- name: Upload generated file as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCH }}_bindgen.rs
path: src/ffi/${{ env.ARCH }}_bindgen.rs
- name: Run tests
run: cargo test -vv -F regenerate --target ${{ matrix.target }}
commit-and-push:
runs-on: ubuntu-latest
needs: bindgen
if: success() # Run only if the generate-bindgen job succeeds
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download generated files
uses: actions/download-artifact@v4
with:
pattern: "*bindgen.rs"
path: src/ffi
merge-multiple: true
- name: Configure Git
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git add src/ffi
# Check if there are any changes to commit
if git diff --quiet --exit-code --cached; then
echo "No changes to commit."
else
git commit -m "chore: update vendored bindings"
git push --force
fi