Skip to content

Commit d9e101d

Browse files
authored
Merge pull request numpy#27330 from SlobodanMiletic/win_arm64_wheel_cross_workflow
Win-arm64 cross compile workflow
2 parents 482d81f + 51c2f1c commit d9e101d

File tree

1 file changed

+207
-0
lines changed

1 file changed

+207
-0
lines changed

.github/workflows/windows_arm64.yml

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
name: Windows Arm64
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
python_version: 3.12
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
11+
cancel-in-progress: true
12+
13+
permissions:
14+
contents: read # to fetch code (actions/checkout)
15+
16+
jobs:
17+
windows_arm:
18+
runs-on: windows-2019
19+
20+
# To enable this job on a fork, comment out:
21+
if: github.repository == 'numpy/numpy'
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
25+
with:
26+
submodules: recursive
27+
fetch-tags: true
28+
29+
- name: Setup Python
30+
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
31+
with:
32+
python-version: ${{env.python_version}}
33+
architecture: x64
34+
35+
- name: Install build dependencies from PyPI
36+
run: |
37+
python -m pip install -r requirements/build_requirements.txt
38+
39+
- name: Prepare python
40+
shell: powershell
41+
run: |
42+
$ErrorActionPreference = "Stop"
43+
44+
#Detecting python location and version
45+
$PythonDir = (Split-Path -Parent (get-command python).Path)
46+
$PythonVersionParts = ( -split (python -V))
47+
$PythonVersion = $PythonVersionParts[1]
48+
49+
#Downloading the package for appropriate python version from nuget
50+
$PythonARM64NugetLink = "https://www.nuget.org/api/v2/package/pythonarm64/$PythonVersion"
51+
$PythonARM64NugetZip = "nuget_python.zip"
52+
$PythonARM64NugetDir = "temp_nuget"
53+
Invoke-WebRequest $PythonARM64NugetLink -OutFile $PythonARM64NugetZip
54+
55+
#Changing the libs folder to enable python libraries to be linked for arm64
56+
Expand-Archive $PythonARM64NugetZip $PythonARM64NugetDir
57+
Copy-Item $PythonARM64NugetDir\tools\libs\* $PythonDir\libs
58+
Remove-Item -Force -Recurse $PythonARM64NugetDir
59+
Remove-Item -Force $PythonARM64NugetZip
60+
61+
if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE }
62+
63+
- name: Prepare Licence
64+
shell: powershell
65+
run: |
66+
$ErrorActionPreference = "Stop"
67+
68+
$CurrentDir = (get-location).Path
69+
$LicenseFile = "$CurrentDir\LICENSE.txt"
70+
Set-Content $LicenseFile ([Environment]::NewLine)
71+
Add-Content $LicenseFile "----"
72+
Add-Content $LicenseFile ([Environment]::NewLine)
73+
Add-Content $LicenseFile (Get-Content "$CurrentDir\LICENSES_bundled.txt")
74+
Add-Content $LicenseFile (Get-Content "$CurrentDir\tools\wheels\LICENSE_win32.txt")
75+
76+
if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE }
77+
78+
- name: Wheel build
79+
shell: powershell
80+
run: |
81+
$ErrorActionPreference = "Stop"
82+
83+
#Creating cross compile script for messon subsystem
84+
$CurrentDir = (get-location)
85+
$CrossScript = "$CurrentDir\arm64_w64.txt"
86+
$CrossScriptContent =
87+
{
88+
[host_machine]
89+
system = 'windows'
90+
subsystem = 'windows'
91+
kernel = 'nt'
92+
cpu_family = 'aarch64'
93+
cpu = 'aarch64'
94+
endian = 'little'
95+
96+
[binaries]
97+
c='cl.exe'
98+
cpp = 'cl.exe'
99+
100+
[properties]
101+
sizeof_short = 2
102+
sizeof_int = 4
103+
sizeof_long = 4
104+
sizeof_long_long = 8
105+
sizeof_float = 4
106+
sizeof_double = 8
107+
sizeof_long_double = 8
108+
sizeof_size_t = 8
109+
sizeof_wchar_t = 2
110+
sizeof_off_t = 4
111+
sizeof_Py_intptr_t = 8
112+
sizeof_PY_LONG_LONG = 8
113+
longdouble_format = 'IEEE_DOUBLE_LE'
114+
}
115+
Set-Content $CrossScript $CrossScriptContent.ToString()
116+
117+
#Setting up cross compilers from MSVC
118+
$Products = 'Community', 'Professional', 'Enterprise', 'BuildTools' | % { "Microsoft.VisualStudio.Product.$_" }
119+
$VsInstallPath = (vswhere -products $Products -latest -format json | ConvertFrom-Json).installationPath
120+
$VSVars = (Get-ChildItem -Path $VsInstallPath -Recurse -Filter "vcvarsamd64_arm64.bat").FullName
121+
$ScriptingObj = New-Object -ComObject Scripting.FileSystemObject
122+
$VSVarsShort = $ScriptingObj.GetFile($VSVars).ShortPath
123+
cmd /c "$VSVarsShort && set" |
124+
ForEach-Object {
125+
if ($_ -match "=") {
126+
$Var = $_.split("=")
127+
set-item -force -path "ENV:\$($Var[0])" -value "$($Var[1])"
128+
}
129+
}
130+
131+
#Building the wheel
132+
pip wheel . --config-settings=setup-args="--cross-file=$CrossScript"
133+
134+
if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE }
135+
136+
- name: Fix wheel
137+
shell: powershell
138+
run: |
139+
$ErrorActionPreference = "Stop"
140+
141+
#Finding whl file
142+
$CurrentDir = (get-location)
143+
$WhlName = ((Get-ChildItem -Filter "*.whl").FullName)
144+
$ZipWhlName = "$CurrentDir\ZipWhlName.zip"
145+
$UnzippedWhl = "$CurrentDir\unzipedWhl"
146+
147+
#Expanding whl file
148+
Rename-Item -Path $WhlName $ZipWhlName
149+
if (Test-Path $UnzippedWhl) {
150+
Remove-Item -Force -Recurse $UnzippedWhl
151+
}
152+
Expand-Archive -Force -Path $ZipWhlName $UnzippedWhl
153+
154+
#Renaming all files to show that their arch is arm64
155+
Get-ChildItem -Recurse -Path $UnzippedWhl *win_amd64* | Rename-Item -NewName { $_.Name -replace 'win_amd64', 'win_arm64' }
156+
$DIST_DIR = (Get-ChildItem -Recurse -Path $UnzippedWhl *dist-info).FullName
157+
158+
#Changing amd64 references from metafiles
159+
(GET-Content $DIST_DIR/RECORD) -replace 'win_amd64', 'win_arm64' | Set-Content $DIST_DIR/RECORD
160+
(GET-Content $DIST_DIR/WHEEL) -replace 'win_amd64', 'win_arm64' | Set-Content $DIST_DIR/WHEEL
161+
162+
#Packing whl file
163+
Compress-Archive -Path $UnzippedWhl\* -DestinationPath $ZipWhlName -Force
164+
$WhlName = $WhlName.Replace("win_amd64", "win_arm64")
165+
Rename-Item -Path $ZipWhlName $WhlName
166+
167+
if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE }
168+
169+
- name: Upload Artifacts
170+
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6
171+
with:
172+
name: ${{ env.python_version }}-win_arm64
173+
path: ./*.whl
174+
175+
- name: Setup Mamba
176+
uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822
177+
with:
178+
# for installation of anaconda-client, required for upload to
179+
# anaconda.org
180+
# Note that this step is *after* specific pythons have been used to
181+
# build and test the wheel
182+
# for installation of anaconda-client, for upload to anaconda.org
183+
# environment will be activated after creation, and in future bash steps
184+
init-shell: bash
185+
environment-name: upload-env
186+
create-args: >-
187+
anaconda-client
188+
189+
# - name: Upload wheels
190+
# if: success()
191+
# shell: bash -el {0}
192+
# # see https://github.com/marketplace/actions/setup-miniconda for why
193+
# # `-el {0}` is required.
194+
# env:
195+
# NUMPY_STAGING_UPLOAD_TOKEN: ${{ secrets.NUMPY_STAGING_UPLOAD_TOKEN }}
196+
# NUMPY_NIGHTLY_UPLOAD_TOKEN: ${{ secrets.NUMPY_NIGHTLY_UPLOAD_TOKEN }}
197+
# run: |
198+
# source tools/wheels/upload_wheels.sh
199+
# set_upload_vars
200+
# # trigger an upload to
201+
# # https://anaconda.org/scientific-python-nightly-wheels/numpy
202+
# # for cron jobs or "Run workflow" (restricted to main branch).
203+
# # Tags will upload to
204+
# # https://anaconda.org/multibuild-wheels-staging/numpy
205+
# # The tokens were originally generated at anaconda.org
206+
# upload_wheels
207+

0 commit comments

Comments
 (0)