Skip to content

Commit 9637c16

Browse files
committed
Build Windows ARM64 binaries cross-compiled on x64
1 parent 77b440b commit 9637c16

File tree

5 files changed

+48
-18
lines changed

5 files changed

+48
-18
lines changed

windows/condaenv.bat

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ FOR %%v IN (%DESIRED_PYTHON%) DO (
1818
)
1919
endlocal
2020

21-
22-
:: Install libuv
23-
conda install -y -q -c conda-forge libuv=1.39
24-
set libuv_ROOT=%CONDA_HOME%\Library
25-
echo libuv_ROOT=%libuv_ROOT%
21+
if "%CROSS_COMPILE_ARM64%" == "" (
22+
:: Install libuv
23+
conda install -y -q -c conda-forge libuv=1.39
24+
set libuv_ROOT=%CONDA_HOME%\Library
25+
echo libuv_ROOT=%libuv_ROOT%
26+
) else (
27+
:: Install protobuf
28+
conda install -y -q -c conda-forge protobuf=3.13 python=3.8
29+
)

windows/internal/copy_cpu.bat

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
copy "%CONDA_LIB_PATH%\libiomp*5md.dll" pytorch\torch\lib
2+
23
:: Should be set in build_pytorch.bat
3-
copy "%libuv_ROOT%\bin\uv.dll" pytorch\torch\lib
4+
if "%CROSS_COMPILE_ARM64%" == "" (
5+
copy "%libuv_ROOT%\bin\uv.dll" pytorch\torch\lib
6+
)

windows/internal/setup.bat

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,28 @@
33
echo The flags after configuring:
44
echo USE_CUDA=%USE_CUDA%
55
echo CMAKE_GENERATOR=%CMAKE_GENERATOR%
6+
echo CROSS_COMPILE_ARM64=%CROSS_COMPILE_ARM64%
7+
68
if "%USE_CUDA%"=="" echo CUDA_PATH=%CUDA_PATH%
79
if NOT "%CC%"=="" echo CC=%CC%
810
if NOT "%CXX%"=="" echo CXX=%CXX%
911
if NOT "%DISTUTILS_USE_SDK%"=="" echo DISTUTILS_USE_SDK=%DISTUTILS_USE_SDK%
1012

1113
set SRC_DIR=%~dp0\..
1214

15+
if "%CROSS_COMPILE_ARM64%" == "" (
16+
set VSDEVCMD_ARCH=x64
17+
) else (
18+
set VSDEVCMD_ARCH=x64_arm64
19+
set CMAKE_TOOLCHAIN_FILE=cmake\Toolchains\msvc2022-x64-arm64.cmake
20+
set USE_HOST_PROTOC=1
21+
set PROTOC=%CONDA_HOME%\Library\bin\protoc.exe
22+
)
23+
1324
IF "%VSDEVCMD_ARGS%" == "" (
14-
call "%VS15VCVARSALL%" x64
25+
call "%VS15VCVARSALL%" %VSDEVCMD_ARCH%
1526
) ELSE (
16-
call "%VS15VCVARSALL%" x64 %VSDEVCMD_ARGS%
27+
call "%VS15VCVARSALL%" %VSDEVCMD_ARCH% %VSDEVCMD_ARGS%
1728
)
1829

1930
pushd %SRC_DIR%

windows/internal/smoke_test.bat

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ IF "%VC_YEAR%" == "2019" (
161161
set VC_VERSION_UPPER=17
162162
)
163163

164+
if "%CROSS_COMPILE_ARM64%" == "" (
165+
set VSDEVCMD_ARCH=x64
166+
) else (
167+
set VSDEVCMD_ARCH=x64_arm64
168+
)
169+
164170
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [%VC_VERSION_LOWER%^,%VC_VERSION_UPPER%^) -property installationPath`) do (
165171
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
166172
set "VS15INSTALLDIR=%%i"
@@ -174,7 +180,7 @@ IF "%VS15VCVARSALL%"=="" (
174180
echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch test on Windows
175181
exit /b 1
176182
)
177-
call "%VS15VCVARSALL%" x64
183+
call "%VS15VCVARSALL%" %VSDEVCMD_ARCH%
178184

179185
set install_root=%CD%
180186
set INCLUDE=%INCLUDE%;%install_root%\include;%install_root%\include\torch\csrc\api\include

windows/internal/vs2022_install.ps1

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44
# 17.4.3 BuildTools
55
$VS_DOWNLOAD_LINK = "https://download.visualstudio.microsoft.com/download/pr/8f480125-28b8-4a2c-847c-c2b02a8cdd1b/64be21d4ada005d7d07896ed0b004c322409bd04d6e8eba4c03c9fa39c928e7a/vs_BuildTools.exe"
66
$COLLECT_DOWNLOAD_LINK = "https://aka.ms/vscollect.exe"
7-
$VS_INSTALL_ARGS = @("--nocache","--quiet","--wait", "--add Microsoft.VisualStudio.Workload.VCTools",
8-
"--add Microsoft.Component.MSBuild",
9-
"--add Microsoft.VisualStudio.Component.Roslyn.Compiler",
10-
"--add Microsoft.VisualStudio.Component.TextTemplating",
11-
"--add Microsoft.VisualStudio.Component.VC.CoreIde",
12-
"--add Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
13-
"--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
14-
"--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
15-
"--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81")
7+
$VS_INSTALL_ARGS = @(
8+
"--nocache",
9+
"--quiet",
10+
"--wait",
11+
"--add Microsoft.VisualStudio.Workload.VCTools",
12+
"--add Microsoft.Component.MSBuild",
13+
"--add Microsoft.VisualStudio.Component.Roslyn.Compiler",
14+
"--add Microsoft.VisualStudio.Component.TextTemplating",
15+
"--add Microsoft.VisualStudio.Component.VC.CoreIde",
16+
"--add Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
17+
"--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
18+
"--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
19+
"--add Microsoft.VisualStudio.Component.VC.Tools.ARM64",
20+
"--add Microsoft.VisualStudio.Component.Windows10SDK.20348"
21+
)
1622

1723
curl.exe --retry 3 -kL $VS_DOWNLOAD_LINK --output vs_installer.exe
1824
if ($LASTEXITCODE -ne 0) {

0 commit comments

Comments
 (0)