Skip to content

Commit e30cf53

Browse files
committed
Build Windows ARM64 binaries cross-compiled on x64
1 parent 3d208f3 commit e30cf53

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
@@ -17,8 +17,12 @@ FOR %%v IN (%DESIRED_PYTHON%) DO (
1717
)
1818
endlocal
1919

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

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
@@ -164,6 +164,12 @@ IF "%VC_YEAR%" == "2019" (
164164
set VC_VERSION_UPPER=17
165165
)
166166

167+
if "%CROSS_COMPILE_ARM64%" == "" (
168+
set VSDEVCMD_ARCH=x64
169+
) else (
170+
set VSDEVCMD_ARCH=x64_arm64
171+
)
172+
167173
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 (
168174
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
169175
set "VS15INSTALLDIR=%%i"
@@ -177,7 +183,7 @@ IF "%VS15VCVARSALL%"=="" (
177183
echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch test on Windows
178184
exit /b 1
179185
)
180-
call "%VS15VCVARSALL%" x64
186+
call "%VS15VCVARSALL%" %VSDEVCMD_ARCH%
181187

182188
set install_root=%CD%
183189
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)