1
1
:: Build script for scipy_openblas wheel on Windows on ARM64
2
2
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
5
5
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
7
9
:: Expects these binaries on the PATH:
8
10
:: clang-cl, flang-new, cmake, perl
9
11
@@ -16,19 +18,42 @@ set first_woa_buildable_commit="de2380e5a6149706a633322a16a0f66faa5591fc"
16
18
setlocal enabledelayedexpansion
17
19
18
20
if " %1 " == " " (
19
- set BUILD_BITS = 64
21
+ set build_bits = 64
20
22
) else (
21
- set BUILD_BITS = %1
23
+ set build_bits = %1
22
24
)
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...
24
36
25
37
:: Define destination directory
26
38
pushd " %~dp0 \.."
27
39
set " ob_out_root = %CD% \local\scipy_openblas"
28
40
set " ob_64 = %ob_out_root% 64"
29
41
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
+ )
32
57
33
58
:: Clone OpenBLAS
34
59
echo Cloning OpenBLAS repository with submodules...
@@ -43,6 +68,13 @@ if errorlevel 1 (
43
68
git checkout %first_woa_buildable_commit%
44
69
)
45
70
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
+
46
78
:: Create build directory and navigate to it
47
79
if exist build (rmdir /S /Q build || exit /b 1)
48
80
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
54
86
55
87
:: Run CMake and Ninja build
56
88
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%
59
91
if errorlevel 1 exit /b 1
60
-
92
+
61
93
ninja
62
94
if errorlevel 1 exit /b 1
63
95
64
96
echo Build complete. Returning to Batch.
65
97
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
+ )
75
108
76
109
:: Prepare destination directory
77
110
cd OpenBLAS/build
@@ -84,7 +117,11 @@ echo Moving library files...
84
117
if exist lib\release (
85
118
move /Y lib\release\*.dll " %DEST_DIR% \lib\"
86
119
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 = %%o rig_name:.dll.a=%% "
123
+ move /Y " %%f " " %DEST_DIR% \lib\!base_name! .lib"
124
+ )
88
125
if errorlevel 1 exit /b 1
89
126
) else (
90
127
echo Error: lib/release directory not found!
@@ -114,15 +151,31 @@ cd ../..
114
151
:: Build the Wheel & Install It
115
152
echo Running 'python -m build' to build the wheel...
116
153
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
+ )
122
175
123
176
:: Locate the built wheel
124
177
for /f %%f in ('dir /b dist\scipy_openblas*.whl 2^ > nul ') do set WHEEL_FILE = dist\%%f
125
-
178
+
126
179
if not defined WHEEL_FILE (
127
180
echo Error: No wheel file found in dist folder.
128
181
exit /b 1
0 commit comments