Skip to content

Refactor Windows on ARM build script #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/windows-arm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Windows-on-ARM

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
OPENBLAS_COMMIT: "v0.3.29"
OPENBLAS_ROOT: "c:\\opt"
# Preserve working directory for calls into bash
# Without this, invoking bash will cd to the home directory
CHERE_INVOKING: "yes"
BASH_PATH: "C:\\Program Files\\Git\\bin\\bash.exe"
PLAT: arm64
INTERFACE64: 0
BUILD_BITS: 32

jobs:
build:
runs-on: windows-11-arm
timeout-minutes: 90

steps:

- uses: actions/[email protected]

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
architecture: arm64

- name: Setup visual studio
uses: microsoft/setup-msbuild@v2

- name: Download, install 7zip.
run: |
Invoke-WebRequest https://www.7-zip.org/a/7z2409-arm64.exe -UseBasicParsing -OutFile 7z_arm.exe
Start-Process -FilePath ".\7z_arm.exe" -ArgumentList "/S" -Wait
echo "C:\Program Files\7-Zip" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- name: Download and install LLVM installer
run: |
Invoke-WebRequest https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.5/LLVM-19.1.5-woa64.exe -UseBasicParsing -OutFile LLVM-woa64.exe
Start-Process -FilePath ".\LLVM-woa64.exe" -ArgumentList "/S" -Wait
echo "C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- name: Update CMake for WoA
run: |
pip install cmake
get-command cmake

- name: Build
run: |
git submodule update --init --recursive
.\tools\build_steps_win_arm64.bat

- name: Pack
run: |
cd local
cp -r "scipy_openblas${env:BUILD_BITS}" $env:BUILD_BITS
7z a ../builds/openblas-${env:PLAT}-${env:INTERFACE64}.zip -tzip $env:BUILD_BITS

- name: Test 32-bit interface wheel
run: |
python -m pip install --no-index --find-links dist scipy_openblas32
python -m scipy_openblas32
python -c "import scipy_openblas32; print(scipy_openblas32.get_pkg_config())"

- uses: actions/[email protected]
with:
name: wheels-${{ env.PLAT }}-${{ env.INTERFACE64 }}
path: dist/scipy_openblas*.whl

- uses: actions/[email protected]
with:
name: openblas-${{ env.PLAT }}-${{ env.INTERFACE64 }}
path: builds/openblas*.zip

- name: Install Anaconda client
run: |
Invoke-WebRequest https://static.rust-lang.org/rustup/dist/aarch64-pc-windows-msvc/rustup-init.exe -UseBasicParsing -Outfile rustup-init.exe
.\rustup-init.exe -y
$env:PATH="$env:PATH;$env:USERPROFILE\.cargo\bin"
pip install anaconda-client

- name: Upload
# see https://github.com/marketplace/actions/setup-miniconda for why
# `-el {0}` is required.
shell: bash -el {0}
env:
ANACONDA_SCIENTIFIC_PYTHON_UPLOAD: ${{ secrets.ANACONDA_SCIENTIFIC_PYTHON_UPLOAD }}
run: |
source tools/upload_to_anaconda_staging.sh
upload_wheels
72 changes: 38 additions & 34 deletions tools/build_steps_win_arm64.bat
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,45 @@
:: Expects these binaries on the PATH:
:: clang-cl, flang-new, cmake, perl

:: First commit containing WoA build fixes.
:: Minimum OpenBLAS commit to build; we'll update to this if commit not
:: present.
set first_woa_buildable_commit="de2380e5a6149706a633322a16a0f66faa5591fc"

@echo off
setlocal enabledelayedexpansion

if "%1"=="" (
set BUILD_BIT=64
set BUILD_BITS=64
) else (
set BUILD_BIT=%1
set BUILD_BITS=%1
)
echo Building for %BUILD_BIT%-bit configuration...
echo Building for %BUILD_BITS%-bit configuration...

:: Define destination directory
move "..\local\scipy_openblas64" "..\local\scipy_openblas32"
set "DEST_DIR=%CD%\..\local\scipy_openblas32"
cd ..

:: Check if 'openblas' folder exists and is empty
if exist "openblas" (
dir /b "openblas" | findstr . >nul
if errorlevel 1 (
echo OpenBLAS folder exists but is empty. Deleting and recloning...
rmdir /s /q "openblas"
)
)
pushd "%~dp0\.."
set "ob_out_root=%CD%\local\scipy_openblas"
set "ob_64=%ob_out_root%64"
set "ob_32=%ob_out_root%32"
if exist "%ob_64%" xcopy "%ob_64%" "%ob_32%" /I /Y
set "DEST_DIR=%ob_32%"

:: Clone OpenBLAS
echo Cloning OpenBLAS repository with submodules...
git submodule update --init --recursive OpenBLAS
if errorlevel 1 exit /b 1

:: Clone OpenBLAS if not present
if not exist "openblas" (
echo Cloning OpenBLAS repository with submodules...
git clone --recursive https://github.com/OpenMathLib/OpenBLAS.git OpenBLAS
if errorlevel 1 exit /b 1
:: Enter OpenBLAS directory and checkout buildable commit
cd OpenBLAS
git merge-base --is-ancestor %first_woa_buildable_commit% HEAD 2>NUL
if errorlevel 1 (
echo Updating to WoA buildable commit for OpenBLAS
git checkout %first_woa_buildable_commit%
)

:: Enter OpenBLAS directory and checkout develop branch
cd openblas
git checkout develop

echo Checked out to the latest branch of OpenBLAS.

:: Create build directory and navigate to it
if not exist build mkdir build
cd build
if exist build (rmdir /S /Q build || exit /b 1)
mkdir build || exit /b 1 & cd build || exit /b 1

echo Setting up ARM64 Developer Command Prompt and running CMake...

Expand All @@ -55,7 +54,7 @@ for /f "usebackq tokens=*" %%i in (`"C:\Program Files (x86)\Microsoft Visual Stu

:: Run CMake and Ninja build
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DTARGET=ARMV8 -DBUILD_SHARED_LIBS=ON -DARCH=arm64 ^
-DBINARY=%BUILD_BIT% -DCMAKE_SYSTEM_PROCESSOR=ARM64 -DCMAKE_C_COMPILER=clang-cl ^
-DBINARY=%BUILD_BITS% -DCMAKE_SYSTEM_PROCESSOR=ARM64 -DCMAKE_C_COMPILER=clang-cl ^
-DCMAKE_Fortran_COMPILER=flang-new -DSYMBOLPREFIX="scipy_" -DLIBNAMEPREFIX="scipy_"
if errorlevel 1 exit /b 1

Expand All @@ -67,7 +66,8 @@ echo Build complete. Returning to Batch.
:: Rewrite the name of the project to scipy-openblas32
echo Rewrite to scipy_openblas32
cd ../..
powershell -Command "(Get-Content 'pyproject.toml') -replace 'openblas64', 'openblas32' | Set-Content 'pyproject.toml'"
set out_pyproject=pyproject_64_32.toml
powershell -Command "(Get-Content 'pyproject.toml') -replace 'openblas64', 'openblas32' | Set-Content %out_pyproject%
powershell -Command "(Get-Content 'local\scipy_openblas32\__main__.py') -replace 'openblas64', 'openblas32' | Out-File 'local\scipy_openblas32\__main__.py' -Encoding utf8"
powershell -Command "(Get-Content 'local\scipy_openblas32\__init__.py') -replace 'openblas64', 'openblas32' | Out-File 'local\scipy_openblas32\__init__.py' -Encoding utf8"
powershell -Command "(Get-Content 'local\scipy_openblas32\__init__.py') -replace 'openblas_get_config64_', 'openblas_get_config' | Out-File 'local\scipy_openblas32\__init__.py' -Encoding utf8"
Expand All @@ -76,7 +76,7 @@ powershell -Command "(Get-Content 'local\scipy_openblas32\__init__.py') -replace
:: Prepare destination directory
cd OpenBLAS/build
echo Preparing destination directory at %DEST_DIR%...
if not exist "%DEST_DIR%\lib\cmake\openblas" mkdir "%DEST_DIR%\lib\cmake\openblas"
if not exist "%DEST_DIR%\lib\cmake\OpenBLAS" mkdir "%DEST_DIR%\lib\cmake\OpenBLAS"
if not exist "%DEST_DIR%\include" mkdir "%DEST_DIR%\include"

:: Move library files
Expand All @@ -99,7 +99,7 @@ if exist openblasconfigversion.cmake copy /Y openblasconfigversion.cmake "%DEST_
:: Copy header files
echo Copying generated header files...
if exist generated xcopy /E /Y generated "%DEST_DIR%\include\"
if exist lapacke_mangling copy /Y lapacke_mangling "%DEST_DIR%\include\"
if exist lapacke_mangling.h copy /Y lapacke_mangling.h "%DEST_DIR%\include\"
if exist openblas_config.h copy /Y openblas_config.h "%DEST_DIR%\include\"


Expand All @@ -113,9 +113,13 @@ cd ../..

:: Build the Wheel & Install It
echo Running 'python -m build' to build the wheel...
python -c "import build" 2>NUL || pip install build
move /Y pyproject.toml pyproject.toml.bak
move /Y %out_pyproject% pyproject.toml
python -m build
if errorlevel 1 exit /b 1

move /Y pyproject.toml.bak pyproject.toml

:: Locate the built wheel
for /f %%f in ('dir /b dist\scipy_openblas*.whl 2^>nul') do set WHEEL_FILE=dist\%%f

Expand All @@ -129,4 +133,4 @@ pip install "%WHEEL_FILE%"
if errorlevel 1 exit /b 1

echo Done.
exit /b 0
exit /b 0
Loading