-
Notifications
You must be signed in to change notification settings - Fork 1
146 lines (136 loc) · 5.57 KB
/
rust.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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: Install Git for Windows (Bash)
if: matrix.os == 'windows-11-preview_aarch64'
shell: powershell
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://community.chocolatey.org/install.ps1'))
choco install git.install --params "'/GitAndUnixToolsOnPath /WindowsTerminal /NoAutoCrlf'" -y --no-progress
Get-Content C:\ProgramData\chocolatey\logs\chocolatey.log
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
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
refreshenv
where bash
- name: Download and install Visual Studio Installer
run: |
# Define the temporary folder path
$tempFolder = $env:RUNNER_TEMP
# Download the Visual Studio Installer for ARM64 to the temporary folder
Invoke-WebRequest -Uri "https://aka.ms/vs/17/release/vs_installer_arm64.exe" -OutFile "$tempFolder\vs_installer.exe"
# Run the installer with necessary components for C++ development
Start-Process -FilePath "$tempFolder\vs_installer.exe" -ArgumentList "--quiet --wait --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended --norestart" -NoNewWindow -Wait
Write-Host "Visual Studio installation complete."
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2
with:
msbuild-architecture: arm64
- name: Install Rust (nightly, 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" -y --default-toolchain nightly
- name: Install Rust 2 (nightly, aarch64)
if: matrix.os == 'windows-11-preview_aarch64'
run: |
where cargo
where rustc
where rustup
rustup toolchain install nightly
rustup target add aarch64-pc-windows-msvc --toolchain nightly
- 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: |
where git
where cargo
git --exec-path
dir "C:/Program Files/Git/usr/bin/"
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