Skip to content

Commit 08f09df

Browse files
Harishmcwmattip
authored andcommitted
use if_bits and fix directory naming
1 parent 7dd7a74 commit 08f09df

File tree

1 file changed

+80
-27
lines changed

1 file changed

+80
-27
lines changed

tools/build_steps_win_arm64.bat

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
:: Build script for scipy_openblas wheel on Windows on ARM64
22

3-
:: Usage: build_steps_win_arm64.bat [build_bits]
4-
:: e.g build_steps_win_arm64.bat 64
3+
:: Usage: build_steps_win_arm64.bat [build_bits] [if_bits]
4+
:: e.g build_steps_win_arm64.bat 64 64
55

6-
:: BUILD_BITS (default binary architecture, 32 or 64, unspec -> 64).
6+
:: build_bits (default binary architecture, 32 or 64, unspec -> 64).
7+
:: if_bits (default interface size, 32 or 64, unspec -> 32)
8+
:: If INTERFACE64 environment variable is 1, then if_bits defaults to 64
79
:: Expects these binaries on the PATH:
810
:: clang-cl, flang-new, cmake, perl
911

@@ -16,19 +18,42 @@ set first_woa_buildable_commit="de2380e5a6149706a633322a16a0f66faa5591fc"
1618
setlocal enabledelayedexpansion
1719

1820
if "%1"=="" (
19-
set BUILD_BITS=64
21+
set build_bits=64
2022
) else (
21-
set BUILD_BITS=%1
23+
set build_bits=%1
2224
)
23-
echo Building for %BUILD_BITS%-bit configuration...
25+
if "%INTERFACE64%"=="1" (
26+
set "if_default=64"
27+
) else (
28+
set "if_default=32"
29+
)
30+
if "%2"=="" (
31+
set "if_bits=%if_default%"
32+
) else (
33+
set "if_bits=%2"
34+
)
35+
echo Building for %build_bits%-bit configuration...
2436

2537
:: Define destination directory
2638
pushd "%~dp0\.."
2739
set "ob_out_root=%CD%\local\scipy_openblas"
2840
set "ob_64=%ob_out_root%64"
2941
set "ob_32=%ob_out_root%32"
30-
if exist "%ob_64%" xcopy "%ob_64%" "%ob_32%" /I /Y
31-
set "DEST_DIR=%ob_32%"
42+
set "local_dir=%CD%\local"
43+
for /d %%D in ("%local_dir%\*") do (
44+
if /I not "%%~nxD"=="scipy_openblas64" (
45+
rmdir /S /Q "%%D"
46+
)
47+
)
48+
if "%if_bits%"=="64" (
49+
set "DEST_DIR=%ob_64%"
50+
) else (
51+
if exist "%ob_64%" (
52+
xcopy /Y /H "%ob_64%\*.py" "%CD%\ob64_backup\"
53+
move "%ob_64%" "%ob_32%"
54+
set "DEST_DIR=%ob_32%"
55+
)
56+
)
3257

3358
:: Clone OpenBLAS
3459
echo Cloning OpenBLAS repository with submodules...
@@ -43,6 +68,13 @@ if errorlevel 1 (
4368
git checkout %first_woa_buildable_commit%
4469
)
4570

71+
:: Set suffixed-ILP64 flags
72+
if "%if_bits%"=="64" (
73+
set "interface_flags=-DINTERFACE64=1 -DSYMBOLSUFFIX=64_"
74+
) else (
75+
set "interface_flags="
76+
)
77+
4678
:: Create build directory and navigate to it
4779
if exist build (rmdir /S /Q build || exit /b 1)
4880
mkdir build || exit /b 1 & cd build || exit /b 1
@@ -54,24 +86,25 @@ for /f "usebackq tokens=*" %%i in (`"C:\Program Files (x86)\Microsoft Visual Stu
5486

5587
:: Run CMake and Ninja build
5688
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DTARGET=ARMV8 -DBUILD_SHARED_LIBS=ON -DARCH=arm64 ^
57-
-DBINARY=%BUILD_BITS% -DCMAKE_SYSTEM_PROCESSOR=ARM64 -DCMAKE_C_COMPILER=clang-cl ^
58-
-DCMAKE_Fortran_COMPILER=flang-new -DSYMBOLPREFIX="scipy_" -DLIBNAMEPREFIX="scipy_"
89+
-DBINARY=%build_bits% -DCMAKE_SYSTEM_PROCESSOR=ARM64 -DCMAKE_C_COMPILER=clang-cl ^
90+
-DCMAKE_Fortran_COMPILER=flang-new -DSYMBOLPREFIX="scipy_" -DLIBNAMEPREFIX="scipy_" %interface_flags%
5991
if errorlevel 1 exit /b 1
60-
92+
6193
ninja
6294
if errorlevel 1 exit /b 1
6395

6496
echo Build complete. Returning to Batch.
6597

66-
:: Rewrite the name of the project to scipy-openblas32
67-
echo Rewrite to scipy_openblas32
68-
cd ../..
69-
set out_pyproject=pyproject_64_32.toml
70-
powershell -Command "(Get-Content 'pyproject.toml') -replace 'openblas64', 'openblas32' | Set-Content %out_pyproject%
71-
powershell -Command "(Get-Content 'local\scipy_openblas32\__main__.py') -replace 'openblas64', 'openblas32' | Out-File 'local\scipy_openblas32\__main__.py' -Encoding utf8"
72-
powershell -Command "(Get-Content 'local\scipy_openblas32\__init__.py') -replace 'openblas64', 'openblas32' | Out-File 'local\scipy_openblas32\__init__.py' -Encoding utf8"
73-
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"
74-
powershell -Command "(Get-Content 'local\scipy_openblas32\__init__.py') -replace 'cflags =.*', 'cflags = \"-DBLAS_SYMBOL_PREFIX=scipy_\"' | Out-File 'local\scipy_openblas32\__init__.py' -Encoding utf8"
98+
if "%if_bits%"=="32" (
99+
echo Rewrite to scipy_openblas32
100+
cd ../..
101+
set out_pyproject=pyproject_64_32.toml
102+
powershell -Command "(Get-Content 'pyproject.toml') -replace 'openblas64', 'openblas32' | Set-Content !out_pyproject!"
103+
powershell -Command "(Get-Content 'local\scipy_openblas32\__main__.py') -replace 'openblas64', 'openblas32' | Out-File 'local\scipy_openblas32\__main__.py' -Encoding utf8"
104+
powershell -Command "(Get-Content 'local\scipy_openblas32\__init__.py') -replace 'openblas64', 'openblas32' | Out-File 'local\scipy_openblas32\__init__.py' -Encoding utf8"
105+
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"
106+
powershell -Command "(Get-Content 'local\scipy_openblas32\__init__.py') -replace 'cflags =.*', 'cflags = \"-DBLAS_SYMBOL_PREFIX=scipy_\"' | Out-File 'local\scipy_openblas32\__init__.py' -Encoding utf8"
107+
)
75108

76109
:: Prepare destination directory
77110
cd OpenBLAS/build
@@ -84,7 +117,11 @@ echo Moving library files...
84117
if exist lib\release (
85118
move /Y lib\release\*.dll "%DEST_DIR%\lib\"
86119
if errorlevel 1 exit /b 1
87-
move /Y lib\release\*.dll.a "%DEST_DIR%\lib\scipy_openblas.lib"
120+
for %%f in (lib\release\*.dll.a) do (
121+
set "orig_name=%%~nxf"
122+
call set "base_name=%%orig_name:.dll.a=%%"
123+
move /Y "%%f" "%DEST_DIR%\lib\!base_name!.lib"
124+
)
88125
if errorlevel 1 exit /b 1
89126
) else (
90127
echo Error: lib/release directory not found!
@@ -114,15 +151,31 @@ cd ../..
114151
:: Build the Wheel & Install It
115152
echo Running 'python -m build' to build the wheel...
116153
python -c "import build" 2>NUL || pip install build
117-
move /Y pyproject.toml pyproject.toml.bak
118-
move /Y %out_pyproject% pyproject.toml
119-
python -m build
120-
if errorlevel 1 exit /b 1
121-
move /Y pyproject.toml.bak pyproject.toml
154+
if "%if_bits%"=="64" (
155+
python -m build
156+
if errorlevel 1 exit /b 1
157+
) else (
158+
move /Y pyproject.toml pyproject.toml.bak
159+
move /Y %out_pyproject% pyproject.toml
160+
python -m build
161+
if errorlevel 1 exit /b 1
162+
move /Y pyproject.toml.bak pyproject.toml
163+
)
164+
if "%if_bits%"=="32" (
165+
move /Y "%CD%\ob64_backup" "%ob_64%"
166+
)
167+
168+
:: Rename the wheel
169+
for %%f in (dist\*any.whl) do (
170+
set WHEEL_FILE=dist\%%f
171+
set "filename=%%~nxf"
172+
set "newname=!filename:any.whl=win_arm64.whl!"
173+
ren "dist\!filename!" "!newname!"
174+
)
122175

123176
:: Locate the built wheel
124177
for /f %%f in ('dir /b dist\scipy_openblas*.whl 2^>nul') do set WHEEL_FILE=dist\%%f
125-
178+
126179
if not defined WHEEL_FILE (
127180
echo Error: No wheel file found in dist folder.
128181
exit /b 1

0 commit comments

Comments
 (0)